From e2be12c87d7bc7e60ce4b9855ca2e07f98ef17df Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 11 Dec 2023 17:28:29 -0700 Subject: [PATCH] setting rest of data --- src/ffi.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index febb459..3b03bd8 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -331,12 +331,47 @@ mod tests { }) .collect::>(); let chunks = Value::Array(chunks); - let mut data = Value::Map(vec![(Value::String("chunks".into()), chunks.clone() )]); println!("Debug: chunks: {:?}", chunks[0][0]); + let hashes: Vec = data.iter().map(|c| c.1).collect(); + let hashes_slice: Vec = hashes.iter().map(|c| c.to_le_bytes_vec()).flatten().collect(); + + let path = [0, 1, 2, 3]; + let parent_hash_l = hash(&[hashes[0], hashes[1]]); + let parent_hash_r = hash(&[hashes[2], hashes[3]]); + + let sibling_hashes = &[ + hashes[1], + parent_hash_r, + hashes[0], + parent_hash_r, + hashes[3], + parent_hash_l, + hashes[2], + parent_hash_l, + ]; + + let siblings: Vec = sibling_hashes + .iter() + .map(|c| c.to_le_bytes_vec()) + .flatten() + .collect(); + + let root = treehash(hashes.as_slice()); + + let root_bytes: [u8; U256::BYTES] = root.to_le_bytes(); + // Serialize the value types to an array pointer - write_value(&mut buf, &data).unwrap(); + let mut mpk_data = Value::Map(vec![ + (Value::String("chunks".into()), chunks.clone() ), + (Value::String("siblings".into()), siblings_mpk.clone() ), + (Value::String("hashings".into()), hashings_mpk.clone() ), + (Value::String("path".into()), path_mpk.clone() ), + (Value::String("root".into()), root_mpk.clone() ), + (Value::String("salt".into()), salt_mpk.clone() ), + ]); + write_value(&mut buf, &mpk_data ).unwrap(); let mut rd: &[u8] = &buf[..]; let args_buff = Buffer {