Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless field #790

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zingo-testutils/test_binaries/bins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repo exists to stash test binaries in.
6 changes: 4 additions & 2 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use crate::{
keys::{address_from_pubkeyhash, unified::ReceiverSelection},
message::Message,
notes::ShieldedNoteInterface,
now, LightWallet, Pool, SendProgress, WalletBase,
now,
utils::get_price,
LightWallet, Pool, SendProgress, WalletBase,
},
};
use futures::future::join_all;
Expand Down Expand Up @@ -1308,7 +1310,7 @@ impl LightClient {
transaction,
status,
now() as u32,
TransactionRecord::get_price(now(), &price),
get_price(now(), &price),
)
.await;
}
Expand Down
8 changes: 2 additions & 6 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use self::data::{SpendableOrchardNote, WitnessTrees, COMMITMENT_TREE_LEVELS, MAX
use self::keys::unified::{Capability, WalletCapability};
use self::traits::Recipient;
use self::traits::{DomainWalletExt, SpendableNote};
use self::utils::get_price;
use self::{
data::{BlockData, WalletZecPriceInfo},
message::Message,
Expand Down Expand Up @@ -1432,12 +1433,7 @@ impl LightWallet {

let status = ConfirmationStatus::Broadcast(submission_height);
self.transaction_context
.scan_full_tx(
transaction,
status,
now() as u32,
TransactionRecord::get_price(now(), &price),
)
.scan_full_tx(transaction, status, now() as u32, get_price(now(), &price))
.await;
}

Expand Down
24 changes: 2 additions & 22 deletions zingolib/src/wallet/transaction_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ pub struct TransactionRecord {
// All outgoing sends
pub outgoing_tx_data: Vec<OutgoingTxData>,

// Whether this TxID was downloaded from the server and scanned for Memos
pub full_tx_scanned: bool,

// Price of Zec when this Tx was created
pub price: Option<f64>,
}
Expand All @@ -72,7 +69,6 @@ impl TransactionRecord {
total_sapling_value_spent: 0,
total_orchard_value_spent: 0,
outgoing_tx_data: vec![],
full_tx_scanned: false,
price: None,
}
}
Expand Down Expand Up @@ -175,21 +171,6 @@ impl TransactionRecord {
self.total_orchard_value_spent,
]
}
pub fn get_price(datetime: u64, price: &WalletZecPriceInfo) -> Option<f64> {
match price.zec_price {
None => None,
Some((t, p)) => {
// If the price was fetched within 24 hours of this Tx, we use the "current" price
// else, we mark it as None, for the historical price fetcher to get
// TODO: Investigate the state of "the historical price fetcher".
if (t as i64 - datetime as i64).abs() < 24 * 60 * 60 {
Some(p)
} else {
None
}
}
}
}
}
// read/write
impl TransactionRecord {
Expand Down Expand Up @@ -254,7 +235,7 @@ impl TransactionRecord {
// Outgoing metadata was only added in version 2
let outgoing_metadata = Vector::read(&mut reader, |r| OutgoingTxData::read(r))?;

let full_tx_scanned = reader.read_u8()? > 0;
let _full_tx_scanned = reader.read_u8()? > 0;

let zec_price = if version <= 4 {
None
Expand Down Expand Up @@ -295,7 +276,6 @@ impl TransactionRecord {
total_transparent_value_spent,
total_orchard_value_spent,
outgoing_tx_data: outgoing_metadata,
full_tx_scanned,
price: zec_price,
})
}
Expand Down Expand Up @@ -327,7 +307,7 @@ impl TransactionRecord {
// Write the outgoing metadata
Vector::write(&mut writer, &self.outgoing_tx_data, |w, om| om.write(w))?;

writer.write_u8(if self.full_tx_scanned { 1 } else { 0 })?;
writer.write_u8(0)?;

Optional::write(&mut writer, self.price, |w, p| {
w.write_f64::<LittleEndian>(p)
Expand Down
17 changes: 17 additions & 0 deletions zingolib/src/wallet/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::io::{self, Read, Write};
use zcash_primitives::{memo::MemoBytes, transaction::TxId};

use super::data::WalletZecPriceInfo;

pub fn read_string<R: Read>(mut reader: R) -> io::Result<String> {
// Strings are written as <littleendian> len + bytes
let str_len = reader.read_u64::<LittleEndian>()?;
Expand Down Expand Up @@ -41,3 +43,18 @@ pub fn txid_from_slice(txid: &[u8]) -> TxId {
txid_bytes.copy_from_slice(txid);
TxId::from_bytes(txid_bytes)
}
pub fn get_price(datetime: u64, price: &WalletZecPriceInfo) -> Option<f64> {
match price.zec_price {
None => None,
Some((t, p)) => {
// If the price was fetched within 24 hours of this Tx, we use the "current" price
// else, we mark it as None, for the historical price fetcher to get
// TODO: Investigate the state of "the historical price fetcher".
if (t as i64 - datetime as i64).abs() < 24 * 60 * 60 {
Some(p)
} else {
None
}
}
}
}
Loading