Skip to content

Commit

Permalink
Merge pull request zingolabs#647 from zancas/rename_for_clarity
Browse files Browse the repository at this point in the history
simplify names now that we understand note receipt better
  • Loading branch information
zancas authored Nov 1, 2023
2 parents d6efd1e + 19466de commit 4747e8b
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 123 deletions.
14 changes: 6 additions & 8 deletions zingolib/src/blaze/block_management_reorg_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
grpc_connector::GrpcConnector,
wallet::{
data::{BlockData, PoolNullifier},
traits::{DomainWalletExt, FromCommitment, ReceivedNoteAndMetadata},
traits::{DomainWalletExt, FromCommitment, NoteInterface},
transactions::TransactionMetadataSet,
},
};
Expand Down Expand Up @@ -33,7 +33,7 @@ use zcash_primitives::{

use super::sync_status::BatchSyncStatus;

type Node<D> = <<D as DomainWalletExt>::WalletNote as ReceivedNoteAndMetadata>::Node;
type Node<D> = <<D as DomainWalletExt>::WalletNote as NoteInterface>::Node;

const ORCHARD_START: &str = "000000";
/// The data relating to the blocks in the current batch
Expand Down Expand Up @@ -501,7 +501,7 @@ impl BlockManagementData {
transaction_num: usize,
output_num: usize,
activation_height: u64,
) -> Result<IncrementalWitness<<D::WalletNote as ReceivedNoteAndMetadata>::Node, 32>, String>
) -> Result<IncrementalWitness<<D::WalletNote as NoteInterface>::Node, 32>, String>
where
D: DomainWalletExt,
D::Note: PartialEq + Clone,
Expand All @@ -515,7 +515,7 @@ impl BlockManagementData {
let (cb, mut tree) = {
// In the edge case of a transition to a new network epoch, there is no previous tree.
let tree = if prev_height < activation_height {
CommitmentTree::<<D::WalletNote as ReceivedNoteAndMetadata>::Node, 32>::empty()
CommitmentTree::<<D::WalletNote as NoteInterface>::Node, 32>::empty()
} else {
let tree_state = GrpcConnector::get_trees(uri, prev_height).await?;
let tree = hex::decode(D::get_tree(&tree_state)).unwrap();
Expand Down Expand Up @@ -552,10 +552,8 @@ impl BlockManagementData {
.enumerate()
{
if let Some(node) =
<D::WalletNote as ReceivedNoteAndMetadata>::Node::from_commitment(
compactoutput.cmstar(),
)
.into()
<D::WalletNote as NoteInterface>::Node::from_commitment(compactoutput.cmstar())
.into()
{
tree.append(node).unwrap();
if t_num == transaction_num && o_num == output_num {
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/blaze/fetch_full_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::wallet::{
data::OutgoingTxData,
keys::{address_from_pubkeyhash, unified::WalletCapability},
traits::{
self as zingo_traits, Bundle as _, DomainWalletExt, ReceivedNoteAndMetadata as _,
Recipient as _, ShieldedOutputExt as _, Spend as _, ToBytes as _,
self as zingo_traits, Bundle as _, DomainWalletExt, NoteInterface as _, Recipient as _,
ShieldedOutputExt as _, Spend as _, ToBytes as _,
},
transactions::TransactionMetadataSet,
};
Expand Down Expand Up @@ -287,7 +287,7 @@ impl TransactionContext {
if let Some(wtx) = current.get(&prev_transaction_id) {
// One of the tx outputs is a match
if let Some(spent_utxo) = wtx
.received_utxos
.transparent_notes
.iter()
.find(|u| u.txid == prev_transaction_id && u.output_index == prev_n)
{
Expand Down
15 changes: 6 additions & 9 deletions zingolib/src/blaze/trial_decryptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::{
wallet::{
data::{PoolNullifier, TransactionMetadata},
keys::unified::WalletCapability,
traits::{
CompactOutput as _, DomainWalletExt, FromCommitment, ReceivedNoteAndMetadata, Recipient,
},
traits::{CompactOutput as _, DomainWalletExt, FromCommitment, NoteInterface, Recipient},
transactions::TransactionMetadataSet,
MemoDownloadOption,
},
Expand Down Expand Up @@ -286,15 +284,15 @@ impl TrialDecryptions {
notes_to_mark_position: &mut [(
u32,
TxId,
<D::WalletNote as ReceivedNoteAndMetadata>::Node,
<D::WalletNote as NoteInterface>::Node,
Retention<BlockHeight>,
)],
) where
D: DomainWalletExt,
<D as Domain>::Recipient: crate::wallet::traits::Recipient + Send + 'static,
<D as Domain>::Note: PartialEq + Send + 'static + Clone,
<D as Domain>::ExtractedCommitmentBytes: Into<[u8; 32]>,
<<D as DomainWalletExt>::WalletNote as ReceivedNoteAndMetadata>::Node: PartialEq,
<<D as DomainWalletExt>::WalletNote as NoteInterface>::Node: PartialEq,
{
let transaction_id = TransactionMetadata::new_txid(&compact_transaction.hash);
let outputs = D::CompactOutput::from_compact_transaction(compact_transaction)
Expand Down Expand Up @@ -383,7 +381,7 @@ fn zip_outputs_with_retention_txids_indexes<D: DomainWalletExt>(
) -> Vec<(
u32,
TxId,
<D::WalletNote as ReceivedNoteAndMetadata>::Node,
<D::WalletNote as NoteInterface>::Node,
Retention<BlockHeight>,
)>
where
Expand All @@ -399,8 +397,7 @@ where
(
i as u32,
TxId::from_bytes(<[u8; 32]>::try_from(&compact_transaction.hash[..]).unwrap()),
<D::WalletNote as ReceivedNoteAndMetadata>::Node::from_commitment(output.cmstar())
.unwrap(),
<D::WalletNote as NoteInterface>::Node::from_commitment(output.cmstar()).unwrap(),
Retention::Ephemeral,
)
})
Expand All @@ -413,7 +410,7 @@ fn update_witnesses<D>(
Vec<(
u32,
TxId,
<D::WalletNote as ReceivedNoteAndMetadata>::Node,
<D::WalletNote as NoteInterface>::Node,
Retention<BlockHeight>,
)>,
BlockHeight,
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
keys::{address_from_pubkeyhash, unified::ReceiverSelection},
message::Message,
now,
traits::ReceivedNoteAndMetadata,
traits::NoteInterface,
LightWallet, Pool, SendProgress, WalletBase,
},
};
Expand Down Expand Up @@ -1571,7 +1571,7 @@ impl LightClient {
}
// No funds spent, this is a normal receipt
(false, true) => {
for received_transparent in transaction_md.received_utxos.iter() {
for received_transparent in transaction_md.transparent_notes.iter() {
summaries.push(ValueTransfer {
block_height,
datetime,
Expand Down Expand Up @@ -1953,7 +1953,7 @@ impl LightClient {

self.wallet.transaction_context.transaction_metadata_set.read().await.current.iter()
.flat_map( |(transaction_id, wtx)| {
wtx.received_utxos.iter().filter_map(move |utxo|
wtx.transparent_notes.iter().filter_map(move |utxo|
if !all_notes && utxo.spent.is_some() {
None
} else {
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/lightclient/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl LightClient {
.flat_map(|(txid, wallet_transaction)| {
let mut consumer_notes_by_tx: Vec<JsonValue> = vec![];

let total_transparent_received = wallet_transaction.received_utxos.iter().map(|u| u.value).sum::<u64>();
let total_transparent_received = wallet_transaction.transparent_notes.iter().map(|u| u.value).sum::<u64>();
if wallet_transaction.is_outgoing_transaction() {
// If money was spent, create a consumer_ui_note. For this, we'll subtract
// all the change notes + Utxos
Expand All @@ -131,7 +131,7 @@ impl LightClient {
// Get the total transparent value received in this transaction
// Again we see the assumption that utxos are incoming.
let net_transparent_value = total_transparent_received as i64 - wallet_transaction.total_transparent_value_spent as i64;
let address = wallet_transaction.received_utxos.iter().map(|utxo| utxo.address.clone()).collect::<Vec<String>>().join(",");
let address = wallet_transaction.transparent_notes.iter().map(|utxo| utxo.address.clone()).collect::<Vec<String>>().join(",");
if net_transparent_value > 0 {
if let Some(transaction) = consumer_notes_by_tx.iter_mut().find(|transaction| transaction["txid"] == txid.to_string()) {
// If this transaction is outgoing:
Expand Down
32 changes: 15 additions & 17 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ use zingo_memo::create_wallet_internal_memo_version_0;
use self::data::{SpendableOrchardNote, WitnessTrees, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL};
use self::keys::unified::{Capability, WalletCapability};
use self::traits::Recipient;
use self::traits::{DomainWalletExt, ReceivedNoteAndMetadata, SpendableNote};
use self::traits::{DomainWalletExt, NoteInterface, SpendableNote};
use self::{
data::{BlockData, ReceivedTransparentOutput, WalletZecPriceInfo},
data::{BlockData, TransparentNote, WalletZecPriceInfo},
message::Message,
transactions::TransactionMetadataSet,
};
Expand Down Expand Up @@ -254,16 +254,14 @@ impl LightWallet {
fn get_legacy_frontier<D: DomainWalletExt>(
trees: &crate::compact_formats::TreeState,
) -> Option<
incrementalmerkletree::frontier::NonEmptyFrontier<
<D::WalletNote as ReceivedNoteAndMetadata>::Node,
>,
incrementalmerkletree::frontier::NonEmptyFrontier<<D::WalletNote as NoteInterface>::Node>,
>
where
<D as Domain>::Note: PartialEq + Clone,
<D as Domain>::Recipient: traits::Recipient,
{
zcash_primitives::merkle_tree::read_commitment_tree::<
<D::WalletNote as ReceivedNoteAndMetadata>::Node,
<D::WalletNote as NoteInterface>::Node,
&[u8],
COMMITMENT_TREE_LEVELS,
>(&hex::decode(D::get_tree(trees)).unwrap()[..])
Expand Down Expand Up @@ -385,7 +383,7 @@ impl LightWallet {
.current
.values_mut()
.for_each(|wtx| {
wtx.received_utxos
wtx.transparent_notes
.iter_mut()
.filter(|utxo| utxo.spent.is_some() && utxo.spent_at_height.is_none())
.for_each(|utxo| {
Expand Down Expand Up @@ -519,7 +517,7 @@ impl LightWallet {
}

// Get all (unspent) utxos. Unconfirmed spent utxos are included
pub async fn get_utxos(&self) -> Vec<ReceivedTransparentOutput> {
pub async fn get_utxos(&self) -> Vec<TransparentNote> {
self.transaction_context
.transaction_metadata_set
.read()
Expand All @@ -528,12 +526,12 @@ impl LightWallet {
.values()
.flat_map(|transaction| {
transaction
.received_utxos
.transparent_notes
.iter()
.filter(|utxo| utxo.spent.is_none())
})
.cloned()
.collect::<Vec<ReceivedTransparentOutput>>()
.collect::<Vec<TransparentNote>>()
}

pub async fn last_synced_hash(&self) -> String {
Expand Down Expand Up @@ -875,7 +873,7 @@ impl LightWallet {
(
Vec<SpendableOrchardNote>,
Vec<SpendableSaplingNote>,
Vec<ReceivedTransparentOutput>,
Vec<TransparentNote>,
u64,
),
u64,
Expand Down Expand Up @@ -1050,7 +1048,7 @@ impl LightWallet {
witness_trees: &WitnessTrees,
orchard_notes: &[SpendableOrchardNote],
sapling_notes: &[SpendableSaplingNote],
utxos: &[ReceivedTransparentOutput],
utxos: &[TransparentNote],
) -> Result<TxBuilder<'_>, String> {
// Add all tinputs
// Create a map from address -> sk for all taddrs, so we can spend from the
Expand Down Expand Up @@ -1255,7 +1253,7 @@ impl LightWallet {
u32,
Vec<SpendableOrchardNote>,
Vec<SpendableSaplingNote>,
Vec<ReceivedTransparentOutput>,
Vec<TransparentNote>,
),
String,
> {
Expand Down Expand Up @@ -1408,7 +1406,7 @@ impl LightWallet {
Transaction,
Vec<SpendableOrchardNote>,
Vec<SpendableSaplingNote>,
Vec<ReceivedTransparentOutput>,
Vec<TransparentNote>,
),
String,
> {
Expand Down Expand Up @@ -1498,7 +1496,7 @@ impl LightWallet {
transaction: Transaction,
orchard_notes: &[SpendableOrchardNote],
sapling_notes: &[SpendableSaplingNote],
utxos: &[ReceivedTransparentOutput],
utxos: &[TransparentNote],
submission_height: BlockHeight,
broadcast_fn: F,
) -> Result<(String, Vec<u8>), String>
Expand Down Expand Up @@ -1558,7 +1556,7 @@ impl LightWallet {
.current
.get_mut(&utxo.txid)
.unwrap()
.received_utxos
.transparent_notes
.iter_mut()
.find(|u| utxo.txid == u.txid && utxo.output_index == u.output_index)
.unwrap();
Expand Down Expand Up @@ -1680,7 +1678,7 @@ impl LightWallet {
filtered_notes
.map(|notedata| {
if notedata.spent().is_none() && notedata.pending_spent().is_none() {
<D::WalletNote as traits::ReceivedNoteAndMetadata>::value(notedata)
<D::WalletNote as traits::NoteInterface>::value(notedata)
} else {
0
}
Expand Down
Loading

0 comments on commit 4747e8b

Please sign in to comment.