Browse Source

check for version 5

pull/27/head
lucretius 3 months ago
parent
commit
e4658582cb
  1. 30
      lib/src/lightwallet/data.rs

30
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<R: Read>(mut reader: R) -> io::Result<Self> {
let version = reader.read_u64::<LittleEndian>()?;
println!("wallet Version : {}", version);
assert!(version <= WalletTx::serialized_version());
let block = reader.read_i32::<LittleEndian>()?;
let datetime = if version >= 4 {
reader.read_u64::<LittleEndian>()?
} 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::<LittleEndian>()?;
let total_transparent_value_spent = reader.read_u64::<LittleEndian>()?;
// 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<W: Write>(&self, mut writer: W) -> io::Result<()> {
writer.write_u64::<LittleEndian>(WalletTx::serialized_version())?;

Loading…
Cancel
Save