Skip to content

Commit

Permalink
Merge pull request #141 from permaweb/VinceJuliano/su-save-data
Browse files Browse the repository at this point in the history
feat(su) save and return data of a data item
  • Loading branch information
VinceJuliano authored Nov 8, 2023
2 parents 31fb8e6 + d7913ca commit 42f77a7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions servers/mu/src/domain/lib/monitor/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions servers/su/src/domain/core/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,15 @@ impl DataItem {
pub fn tags(&self) -> Vec<Tag> {
self.tags.clone()
}

pub fn data(&self) -> Option<String> {
match &self.data {
Data::Bytes(d) => {
let data_base64 = base64_url::encode(&d);
Some(data_base64)
},
Data::None => None
}
}

}
5 changes: 4 additions & 1 deletion servers/su/src/domain/core/json.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@



use serde::{Serialize, Deserialize}; // Import Serde traits
use serde::{Serialize, Deserialize};

use super::bytes::{DataBundle};
use super::sequencer::hash;
Expand Down Expand Up @@ -59,6 +59,7 @@ pub struct Message {
pub owner: Owner,
pub sort_key: String,
pub process_id: String,
pub data: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -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,
Expand All @@ -166,6 +168,7 @@ impl Message {
owner,
sort_key: sort_key_clone,
process_id,
data: data
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions servers/su/src/domain/pipeline/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl MessagePipeline {
pub async fn commit(&mut self) -> Result<String, String> {
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()),
};


Expand Down
2 changes: 1 addition & 1 deletion servers/testscripts/src/local/su.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 42f77a7

Please sign in to comment.