From 81b6b52ba0e0a4af34e836837a6fcdab6045039f Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Fri, 6 Sep 2019 09:57:13 -0700 Subject: [PATCH] Serialization --- rust-lightclient/Cargo.toml | 2 +- rust-lightclient/src/lightwallet.rs | 32 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/rust-lightclient/Cargo.toml b/rust-lightclient/Cargo.toml index 4dd302e..71d1d3f 100644 --- a/rust-lightclient/Cargo.toml +++ b/rust-lightclient/Cargo.toml @@ -20,7 +20,7 @@ tower-util = "0.1" hex = "0.3" protobuf = "2" rustyline = "5.0.2" - +byteorder = "1" [dependencies.bellman] git = "https://github.com/adityapk00/librustzcash.git" diff --git a/rust-lightclient/src/lightwallet.rs b/rust-lightclient/src/lightwallet.rs index 3638b17..b1ef0fb 100644 --- a/rust-lightclient/src/lightwallet.rs +++ b/rust-lightclient/src/lightwallet.rs @@ -1,4 +1,7 @@ use std::time::SystemTime; +use std::io::{self, Read, Write}; + +use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use pairing::bls12_381::Bls12; use zcash_primitives::primitives::{Diversifier, Note, PaymentAddress}; @@ -53,6 +56,29 @@ struct BlockData { tree: CommitmentTree, } +impl BlockData { + pub fn read(mut reader: R) -> io::Result { + let height = reader.read_i32::()?; + + let mut hash_bytes = [0; 32]; + reader.read_exact(&mut hash_bytes)?; + + let tree = CommitmentTree::::read(&mut reader)?; + + Ok(BlockData{ + height, + hash: BlockHash{ 0: hash_bytes }, + tree + }) + } + + pub fn write(&self, mut writer: W) -> io::Result<()> { + writer.write_i32::(self.height)?; + writer.write_all(&self.hash.0)?; + self.tree.write(writer) + } +} + pub struct SaplingNoteData { account: usize, diversifier: Diversifier, @@ -79,6 +105,7 @@ impl SaplingNoteData { nf }; + SaplingNoteData { account: output.account, diversifier: output.to.diversifier, @@ -89,7 +116,10 @@ impl SaplingNoteData { memo: None } } -} + + fn print_note(&self) { + + } pub struct WalletTx { block: i32,