diff --git a/lib/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs index 696c5f4..b8abcd0 100644 --- a/lib/src/lightwallet/data.rs +++ b/lib/src/lightwallet/data.rs @@ -440,7 +440,7 @@ pub struct WalletTx { impl WalletTx { pub fn serialized_version() -> u64 { - return 4; + return 5; } pub fn new(height: i32, datetime: u64, txid: &TxId) -> Self { @@ -460,10 +460,10 @@ impl WalletTx { pub fn read(mut reader: R) -> io::Result { let version = reader.read_u64::()?; + println!("wallet Version : {}", version); assert!(version <= WalletTx::serialized_version()); let block = reader.read_i32::()?; - let datetime = if version >= 4 { reader.read_u64::()? } else { @@ -472,23 +472,24 @@ impl WalletTx { let mut txid_bytes = [0u8; 32]; reader.read_exact(&mut txid_bytes)?; - let txid = TxId{0: txid_bytes}; let notes = Vector::read(&mut reader, |r| SaplingNoteData::read(r))?; let utxos = Vector::read(&mut reader, |r| Utxo::read(r))?; - let total_shielded_value_spent = reader.read_u64::()?; let total_transparent_value_spent = reader.read_u64::()?; - - // Outgoing metadata was only added in version 2 let outgoing_metadata = Vector::read(&mut reader, |r| OutgoingTxMetadata::read(r))?; - //let incoming_metadata = Vector::read(&mut reader, |r| IncomingTxMetadata::read(r))?; + // Read incoming_metadata only if version is 5 or higher + let incoming_metadata = if version >= 5 { + Vector::read(&mut reader, |r| IncomingTxMetadata::read(r))? + } else { + vec![] + }; let full_tx_scanned = reader.read_u8()? > 0; - - let mut wallet_tx = WalletTx { + + Ok(WalletTx { block, datetime, txid, @@ -497,17 +498,12 @@ impl WalletTx { total_shielded_value_spent, total_transparent_value_spent, outgoing_metadata, - incoming_metadata: vec![], + incoming_metadata, full_tx_scanned - }; - if version >= 5 { - wallet_tx.incoming_metadata = Vector::read(&mut reader, |r| IncomingTxMetadata::read(r))?; - } - - Ok(wallet_tx) - + }) } + pub fn write(&self, mut writer: W) -> io::Result<()> { writer.write_u64::(WalletTx::serialized_version())?;