From d7913cac5ce48f889b31ee58d069c9601bc90a70 Mon Sep 17 00:00:00 2001 From: Vince Juliano Date: Wed, 8 Nov 2023 15:35:38 -0500 Subject: [PATCH] feat(su) save and return data of a data item) --- servers/mu/src/domain/lib/monitor/worker.js | 4 ++-- servers/su/src/domain/core/bytes.rs | 10 ++++++++++ servers/su/src/domain/core/json.rs | 5 ++++- servers/su/src/domain/pipeline/message.rs | 4 ++-- servers/testscripts/src/local/su.js | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/servers/mu/src/domain/lib/monitor/worker.js b/servers/mu/src/domain/lib/monitor/worker.js index b054135ef..70fea1e5c 100644 --- a/servers/mu/src/domain/lib/monitor/worker.js +++ b/servers/mu/src/domain/lib/monitor/worker.js @@ -33,7 +33,7 @@ const updateMonitor = dataStoreClient.updateMonitorWith({dbInstance, logger}) parentPort.on('message', (message) => { if(message.label === 'start') { - setInterval(() => processMonitors(), 1000) + // setInterval(() => processMonitors(), 1000) parentPort.postMessage(`Monitor worker started`) } else { parentPort.postMessage(`Invalid message`) @@ -133,7 +133,7 @@ async function processMonitor(monitor) { return {status: 'ok'} } catch(e) { - console.error('Error in processMonitor:', error); + console.error('Error in processMonitor:', e); throw error; } diff --git a/servers/su/src/domain/core/bytes.rs b/servers/su/src/domain/core/bytes.rs index 2443bda96..ebc721749 100644 --- a/servers/su/src/domain/core/bytes.rs +++ b/servers/su/src/domain/core/bytes.rs @@ -305,5 +305,15 @@ impl DataItem { pub fn tags(&self) -> Vec { self.tags.clone() } + + pub fn data(&self) -> Option { + match &self.data { + Data::Bytes(d) => { + let data_base64 = base64_url::encode(&d); + Some(data_base64) + }, + Data::None => None + } + } } \ No newline at end of file diff --git a/servers/su/src/domain/core/json.rs b/servers/su/src/domain/core/json.rs index a409ab7d3..82fadfbed 100644 --- a/servers/su/src/domain/core/json.rs +++ b/servers/su/src/domain/core/json.rs @@ -1,7 +1,7 @@ -use serde::{Serialize, Deserialize}; // Import Serde traits +use serde::{Serialize, Deserialize}; use super::bytes::{DataBundle}; use super::sequencer::hash; @@ -59,6 +59,7 @@ pub struct Message { pub owner: Owner, pub sort_key: String, pub process_id: String, + pub data: Option, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -140,6 +141,7 @@ impl Message { let tags = data_bundle.items[0].tags(); let owner = data_bundle.items[0].owner().clone(); let target = data_bundle.items[0].target().clone(); + let data = data_bundle.items[0].data().clone(); let message_inner = MessageInner { id: id, @@ -166,6 +168,7 @@ impl Message { owner, sort_key: sort_key_clone, process_id, + data: data }) } } diff --git a/servers/su/src/domain/pipeline/message.rs b/servers/su/src/domain/pipeline/message.rs index e4a8217ab..3e151d0c6 100644 --- a/servers/su/src/domain/pipeline/message.rs +++ b/servers/su/src/domain/pipeline/message.rs @@ -77,12 +77,12 @@ impl MessagePipeline { pub async fn commit(&mut self) -> Result { let build_data = match &self.build_data { Some(data) => data, - None => return Err("Upload error occurred.".to_string()), + None => return Err("Build error occurred.".to_string()), }; let build_bundle = match &self.build_bundle { Some(data) => data, - None => return Err("Upload error occurred.".to_string()), + None => return Err("Build error occurred.".to_string()), }; diff --git a/servers/testscripts/src/local/su.js b/servers/testscripts/src/local/su.js index b2ef71667..f54c590b5 100644 --- a/servers/testscripts/src/local/su.js +++ b/servers/testscripts/src/local/su.js @@ -11,7 +11,7 @@ const { createData, ArweaveSigner } = WarpArBundles; const tags = [] const signer = new ArweaveSigner(wallet) - const dataItem = createData(data, signer, { tags, target: 'feOEvFn5N8KxXjmHTGWQ26l_39Cm1_uEo4SiSil7cZU' }) + const dataItem = createData(data, signer, { tags, target: 'UO6S6DLXzn3Jlz7E2XCiG3hZcRYTmzpOZpvZwBrCuqQ' }) await dataItem.sign(signer) const response = await fetch(