check for version 5
This commit is contained in:
@@ -440,7 +440,7 @@ pub struct WalletTx {
|
|||||||
|
|
||||||
impl WalletTx {
|
impl WalletTx {
|
||||||
pub fn serialized_version() -> u64 {
|
pub fn serialized_version() -> u64 {
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(height: i32, datetime: u64, txid: &TxId) -> Self {
|
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> {
|
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
|
||||||
let version = reader.read_u64::<LittleEndian>()?;
|
let version = reader.read_u64::<LittleEndian>()?;
|
||||||
|
println!("wallet Version : {}", version);
|
||||||
assert!(version <= WalletTx::serialized_version());
|
assert!(version <= WalletTx::serialized_version());
|
||||||
|
|
||||||
let block = reader.read_i32::<LittleEndian>()?;
|
let block = reader.read_i32::<LittleEndian>()?;
|
||||||
|
|
||||||
let datetime = if version >= 4 {
|
let datetime = if version >= 4 {
|
||||||
reader.read_u64::<LittleEndian>()?
|
reader.read_u64::<LittleEndian>()?
|
||||||
} else {
|
} else {
|
||||||
@@ -472,23 +472,24 @@ impl WalletTx {
|
|||||||
|
|
||||||
let mut txid_bytes = [0u8; 32];
|
let mut txid_bytes = [0u8; 32];
|
||||||
reader.read_exact(&mut txid_bytes)?;
|
reader.read_exact(&mut txid_bytes)?;
|
||||||
|
|
||||||
let txid = TxId{0: txid_bytes};
|
let txid = TxId{0: txid_bytes};
|
||||||
|
|
||||||
let notes = Vector::read(&mut reader, |r| SaplingNoteData::read(r))?;
|
let notes = Vector::read(&mut reader, |r| SaplingNoteData::read(r))?;
|
||||||
let utxos = Vector::read(&mut reader, |r| Utxo::read(r))?;
|
let utxos = Vector::read(&mut reader, |r| Utxo::read(r))?;
|
||||||
|
|
||||||
let total_shielded_value_spent = reader.read_u64::<LittleEndian>()?;
|
let total_shielded_value_spent = reader.read_u64::<LittleEndian>()?;
|
||||||
let total_transparent_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 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 full_tx_scanned = reader.read_u8()? > 0;
|
||||||
|
|
||||||
let mut wallet_tx = WalletTx {
|
Ok(WalletTx {
|
||||||
block,
|
block,
|
||||||
datetime,
|
datetime,
|
||||||
txid,
|
txid,
|
||||||
@@ -497,17 +498,12 @@ impl WalletTx {
|
|||||||
total_shielded_value_spent,
|
total_shielded_value_spent,
|
||||||
total_transparent_value_spent,
|
total_transparent_value_spent,
|
||||||
outgoing_metadata,
|
outgoing_metadata,
|
||||||
incoming_metadata: vec![],
|
incoming_metadata,
|
||||||
full_tx_scanned
|
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<()> {
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
writer.write_u64::<LittleEndian>(WalletTx::serialized_version())?;
|
writer.write_u64::<LittleEndian>(WalletTx::serialized_version())?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user