From 8076ee1426aa5f0f95100a85404ad6f507a764fd Mon Sep 17 00:00:00 2001 From: lucretius Date: Sat, 20 Jan 2024 15:43:43 +0100 Subject: [PATCH 1/4] add check for wallet version --- lib/src/lightwallet/data.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs index eb57b13..696c5f4 100644 --- a/lib/src/lightwallet/data.rs +++ b/lib/src/lightwallet/data.rs @@ -484,11 +484,11 @@ impl WalletTx { // 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))?; + //let incoming_metadata = Vector::read(&mut reader, |r| IncomingTxMetadata::read(r))?; let full_tx_scanned = reader.read_u8()? > 0; - Ok(WalletTx{ + let mut wallet_tx = WalletTx { block, datetime, txid, @@ -497,9 +497,15 @@ impl WalletTx { total_shielded_value_spent, total_transparent_value_spent, outgoing_metadata, - incoming_metadata, + incoming_metadata: vec![], 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<()> { From e4658582cbe610cb6f7f5d62d2ea9444bd38f4ca Mon Sep 17 00:00:00 2001 From: lucretius Date: Sat, 20 Jan 2024 15:59:30 +0100 Subject: [PATCH 2/4] check for version 5 --- lib/src/lightwallet/data.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) 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())?; From b3e4162f8a1b5161d02e56199dab95fc1cf93e20 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sat, 20 Jan 2024 16:05:35 +0100 Subject: [PATCH 3/4] add error warning --- lib/src/lightwallet/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs index b8abcd0..dcc0007 100644 --- a/lib/src/lightwallet/data.rs +++ b/lib/src/lightwallet/data.rs @@ -461,7 +461,7 @@ impl WalletTx { pub fn read(mut reader: R) -> io::Result { let version = reader.read_u64::()?; println!("wallet Version : {}", version); - assert!(version <= WalletTx::serialized_version()); + assert!(version <= WalletTx::serialized_version(), "Version mismatch. Please restore your Seed"); let block = reader.read_i32::()?; let datetime = if version >= 4 { From d8994eec8e285c70f0f26045a377eccc8265c2c4 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sat, 20 Jan 2024 19:47:40 +0100 Subject: [PATCH 4/4] less debug --- lib/src/lightwallet/data.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs index dcc0007..657f342 100644 --- a/lib/src/lightwallet/data.rs +++ b/lib/src/lightwallet/data.rs @@ -460,8 +460,7 @@ impl WalletTx { pub fn read(mut reader: R) -> io::Result { let version = reader.read_u64::()?; - println!("wallet Version : {}", version); - assert!(version <= WalletTx::serialized_version(), "Version mismatch. Please restore your Seed"); + assert!(version <= WalletTx::serialized_version(), "Version mismatch. Please restore with your Seed"); let block = reader.read_i32::()?; let datetime = if version >= 4 {