diff --git a/zingolib/src/blaze/block_management_reorg_detection.rs b/zingolib/src/blaze/block_management_reorg_detection.rs index eb01f38c3..e9dfa9e25 100644 --- a/zingolib/src/blaze/block_management_reorg_detection.rs +++ b/zingolib/src/blaze/block_management_reorg_detection.rs @@ -3,7 +3,7 @@ use crate::{ grpc_connector::GrpcConnector, wallet::{ data::{BlockData, PoolNullifier}, - traits::{DomainWalletExt, FromCommitment, ReceivedNoteAndMetadata}, + traits::{DomainWalletExt, FromCommitment, NoteInterface}, transactions::TransactionMetadataSet, }, }; @@ -33,7 +33,7 @@ use zcash_primitives::{ use super::sync_status::BatchSyncStatus; -type Node = <::WalletNote as ReceivedNoteAndMetadata>::Node; +type Node = <::WalletNote as NoteInterface>::Node; const ORCHARD_START: &str = "000000"; /// The data relating to the blocks in the current batch @@ -501,7 +501,7 @@ impl BlockManagementData { transaction_num: usize, output_num: usize, activation_height: u64, - ) -> Result::Node, 32>, String> + ) -> Result::Node, 32>, String> where D: DomainWalletExt, D::Note: PartialEq + Clone, @@ -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::<::Node, 32>::empty() + CommitmentTree::<::Node, 32>::empty() } else { let tree_state = GrpcConnector::get_trees(uri, prev_height).await?; let tree = hex::decode(D::get_tree(&tree_state)).unwrap(); @@ -552,10 +552,8 @@ impl BlockManagementData { .enumerate() { if let Some(node) = - ::Node::from_commitment( - compactoutput.cmstar(), - ) - .into() + ::Node::from_commitment(compactoutput.cmstar()) + .into() { tree.append(node).unwrap(); if t_num == transaction_num && o_num == output_num { diff --git a/zingolib/src/blaze/fetch_full_transaction.rs b/zingolib/src/blaze/fetch_full_transaction.rs index db087d3ea..5322783bb 100644 --- a/zingolib/src/blaze/fetch_full_transaction.rs +++ b/zingolib/src/blaze/fetch_full_transaction.rs @@ -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, }; @@ -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) { diff --git a/zingolib/src/blaze/trial_decryptions.rs b/zingolib/src/blaze/trial_decryptions.rs index 131d20d19..54760db85 100644 --- a/zingolib/src/blaze/trial_decryptions.rs +++ b/zingolib/src/blaze/trial_decryptions.rs @@ -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, }, @@ -286,7 +284,7 @@ impl TrialDecryptions { notes_to_mark_position: &mut [( u32, TxId, - ::Node, + ::Node, Retention, )], ) where @@ -294,7 +292,7 @@ impl TrialDecryptions { ::Recipient: crate::wallet::traits::Recipient + Send + 'static, ::Note: PartialEq + Send + 'static + Clone, ::ExtractedCommitmentBytes: Into<[u8; 32]>, - <::WalletNote as ReceivedNoteAndMetadata>::Node: PartialEq, + <::WalletNote as NoteInterface>::Node: PartialEq, { let transaction_id = TransactionMetadata::new_txid(&compact_transaction.hash); let outputs = D::CompactOutput::from_compact_transaction(compact_transaction) @@ -383,7 +381,7 @@ fn zip_outputs_with_retention_txids_indexes( ) -> Vec<( u32, TxId, - ::Node, + ::Node, Retention, )> where @@ -399,8 +397,7 @@ where ( i as u32, TxId::from_bytes(<[u8; 32]>::try_from(&compact_transaction.hash[..]).unwrap()), - ::Node::from_commitment(output.cmstar()) - .unwrap(), + ::Node::from_commitment(output.cmstar()).unwrap(), Retention::Ephemeral, ) }) @@ -413,7 +410,7 @@ fn update_witnesses( Vec<( u32, TxId, - ::Node, + ::Node, Retention, )>, BlockHeight, diff --git a/zingolib/src/lightclient.rs b/zingolib/src/lightclient.rs index bd3025139..da9af3616 100644 --- a/zingolib/src/lightclient.rs +++ b/zingolib/src/lightclient.rs @@ -16,7 +16,7 @@ use crate::{ keys::{address_from_pubkeyhash, unified::ReceiverSelection}, message::Message, now, - traits::ReceivedNoteAndMetadata, + traits::NoteInterface, LightWallet, Pool, SendProgress, WalletBase, }, }; @@ -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, @@ -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 { diff --git a/zingolib/src/lightclient/deprecated.rs b/zingolib/src/lightclient/deprecated.rs index 7d5b3ba56..ebe9daa4b 100644 --- a/zingolib/src/lightclient/deprecated.rs +++ b/zingolib/src/lightclient/deprecated.rs @@ -115,7 +115,7 @@ impl LightClient { .flat_map(|(txid, wallet_transaction)| { let mut consumer_notes_by_tx: Vec = vec![]; - let total_transparent_received = wallet_transaction.received_utxos.iter().map(|u| u.value).sum::(); + let total_transparent_received = wallet_transaction.transparent_notes.iter().map(|u| u.value).sum::(); 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 @@ -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::>().join(","); + let address = wallet_transaction.transparent_notes.iter().map(|utxo| utxo.address.clone()).collect::>().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: diff --git a/zingolib/src/wallet.rs b/zingolib/src/wallet.rs index 10bec7c58..f496c5cf6 100644 --- a/zingolib/src/wallet.rs +++ b/zingolib/src/wallet.rs @@ -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, }; @@ -254,16 +254,14 @@ impl LightWallet { fn get_legacy_frontier( trees: &crate::compact_formats::TreeState, ) -> Option< - incrementalmerkletree::frontier::NonEmptyFrontier< - ::Node, - >, + incrementalmerkletree::frontier::NonEmptyFrontier<::Node>, > where ::Note: PartialEq + Clone, ::Recipient: traits::Recipient, { zcash_primitives::merkle_tree::read_commitment_tree::< - ::Node, + ::Node, &[u8], COMMITMENT_TREE_LEVELS, >(&hex::decode(D::get_tree(trees)).unwrap()[..]) @@ -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| { @@ -519,7 +517,7 @@ impl LightWallet { } // Get all (unspent) utxos. Unconfirmed spent utxos are included - pub async fn get_utxos(&self) -> Vec { + pub async fn get_utxos(&self) -> Vec { self.transaction_context .transaction_metadata_set .read() @@ -528,12 +526,12 @@ impl LightWallet { .values() .flat_map(|transaction| { transaction - .received_utxos + .transparent_notes .iter() .filter(|utxo| utxo.spent.is_none()) }) .cloned() - .collect::>() + .collect::>() } pub async fn last_synced_hash(&self) -> String { @@ -875,7 +873,7 @@ impl LightWallet { ( Vec, Vec, - Vec, + Vec, u64, ), u64, @@ -1050,7 +1048,7 @@ impl LightWallet { witness_trees: &WitnessTrees, orchard_notes: &[SpendableOrchardNote], sapling_notes: &[SpendableSaplingNote], - utxos: &[ReceivedTransparentOutput], + utxos: &[TransparentNote], ) -> Result, String> { // Add all tinputs // Create a map from address -> sk for all taddrs, so we can spend from the @@ -1255,7 +1253,7 @@ impl LightWallet { u32, Vec, Vec, - Vec, + Vec, ), String, > { @@ -1408,7 +1406,7 @@ impl LightWallet { Transaction, Vec, Vec, - Vec, + Vec, ), String, > { @@ -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), String> @@ -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(); @@ -1680,7 +1678,7 @@ impl LightWallet { filtered_notes .map(|notedata| { if notedata.spent().is_none() && notedata.pending_spent().is_none() { - ::value(notedata) + ::value(notedata) } else { 0 } diff --git a/zingolib/src/wallet/data.rs b/zingolib/src/wallet/data.rs index be8106f29..894331762 100644 --- a/zingolib/src/wallet/data.rs +++ b/zingolib/src/wallet/data.rs @@ -1,6 +1,6 @@ use crate::compact_formats::CompactBlock; use crate::error::ZingoLibError; -use crate::wallet::traits::ReceivedNoteAndMetadata; +use crate::wallet::traits::NoteInterface; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use incrementalmerkletree::frontier::{CommitmentTree, NonEmptyFrontier}; use incrementalmerkletree::witness::IncrementalWitness; @@ -183,9 +183,7 @@ impl WitnessTrees { } fn insert_domain_frontier_notes( &mut self, - non_empty_frontier: Option< - NonEmptyFrontier<::Node>, - >, + non_empty_frontier: Option::Node>>, ) where ::Note: PartialEq + Clone, ::Recipient: traits::Recipient, @@ -439,7 +437,7 @@ impl WitnessCache { // return hex::encode(buf); // } } -pub struct ReceivedSaplingNoteAndMetadata { +pub struct SaplingNote { pub diversifier: zcash_primitives::sapling::Diversifier, pub note: zcash_primitives::sapling::Note, @@ -464,7 +462,7 @@ pub struct ReceivedSaplingNoteAndMetadata { } #[derive(Debug)] -pub struct ReceivedOrchardNoteAndMetadata { +pub struct OrchardNote { pub diversifier: orchard::keys::Diversifier, pub note: orchard::note::Note, @@ -488,7 +486,7 @@ pub struct ReceivedOrchardNoteAndMetadata { pub have_spending_key: bool, } -impl std::fmt::Debug for ReceivedSaplingNoteAndMetadata { +impl std::fmt::Debug for SaplingNote { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SaplingNoteData") .field("diversifier", &self.diversifier) @@ -545,7 +543,7 @@ pub(crate) fn write_sapling_rseed( } #[derive(Clone, Debug, PartialEq)] -pub struct ReceivedTransparentOutput { +pub struct TransparentNote { pub address: String, pub txid: TxId, pub output_index: u64, @@ -561,7 +559,7 @@ pub struct ReceivedTransparentOutput { pub unconfirmed_spent: Option<(TxId, u32)>, } -impl ReceivedTransparentOutput { +impl TransparentNote { pub fn serialized_version() -> u64 { 3 } @@ -617,7 +615,7 @@ impl ReceivedTransparentOutput { })? }; - Ok(ReceivedTransparentOutput { + Ok(TransparentNote { address, txid: transaction_id, output_index, @@ -916,13 +914,13 @@ pub struct TransactionMetadata { pub spent_orchard_nullifiers: Vec, // List of all sapling notes received in this tx. Some of these might be change notes. - pub sapling_notes: Vec, + pub sapling_notes: Vec, // List of all sapling notes received in this tx. Some of these might be change notes. - pub orchard_notes: Vec, + pub orchard_notes: Vec, // List of all Utxos received in this Tx. Some of these might be change notes - pub received_utxos: Vec, + pub transparent_notes: Vec, // Total value of all the sapling nullifiers that were spent in this Tx pub total_sapling_value_spent: u64, @@ -990,7 +988,7 @@ impl TransactionMetadata { pub fn is_incoming_transaction(&self) -> bool { self.sapling_notes.iter().any(|note| !note.is_change()) || self.orchard_notes.iter().any(|note| !note.is_change()) - || !self.received_utxos.is_empty() + || !self.transparent_notes.is_empty() } pub fn net_spent(&self) -> u64 { assert!(self.is_outgoing_transaction()); @@ -1011,7 +1009,7 @@ impl TransactionMetadata { spent_orchard_nullifiers: vec![], sapling_notes: vec![], orchard_notes: vec![], - received_utxos: vec![], + transparent_notes: vec![], total_transparent_value_spent: 0, total_sapling_value_spent: 0, total_orchard_value_spent: 0, @@ -1083,22 +1081,16 @@ impl TransactionMetadata { let transaction_id = TxId::from_bytes(transaction_id_bytes); let sapling_notes = Vector::read_collected_mut(&mut reader, |r| { - ReceivedSaplingNoteAndMetadata::read( - r, - (wallet_capability, trees.as_mut().map(|t| &mut t.0)), - ) + SaplingNote::read(r, (wallet_capability, trees.as_mut().map(|t| &mut t.0))) })?; let orchard_notes = if version > 22 { Vector::read_collected_mut(&mut reader, |r| { - ReceivedOrchardNoteAndMetadata::read( - r, - (wallet_capability, trees.as_mut().map(|t| &mut t.1)), - ) + OrchardNote::read(r, (wallet_capability, trees.as_mut().map(|t| &mut t.1))) })? } else { vec![] }; - let utxos = Vector::read(&mut reader, |r| ReceivedTransparentOutput::read(r))?; + let utxos = Vector::read(&mut reader, |r| TransparentNote::read(r))?; let total_sapling_value_spent = reader.read_u64::()?; let total_transparent_value_spent = reader.read_u64::()?; @@ -1145,7 +1137,7 @@ impl TransactionMetadata { txid: transaction_id, sapling_notes, orchard_notes, - received_utxos: utxos, + transparent_notes: utxos, spent_sapling_nullifiers, spent_orchard_nullifiers, total_sapling_value_spent, @@ -1169,7 +1161,7 @@ impl TransactionMetadata { self.pool_value_received::() + self.pool_value_received::>() + self - .received_utxos + .transparent_notes .iter() .map(|utxo| utxo.value) .sum::() @@ -1205,7 +1197,7 @@ impl TransactionMetadata { Vector::write(&mut writer, &self.sapling_notes, |w, nd| nd.write(w))?; Vector::write(&mut writer, &self.orchard_notes, |w, nd| nd.write(w))?; - Vector::write(&mut writer, &self.received_utxos, |w, u| u.write(w))?; + Vector::write(&mut writer, &self.transparent_notes, |w, u| u.write(w))?; for pool in self.value_spent_by_pool() { writer.write_u64::(pool)?; diff --git a/zingolib/src/wallet/traits.rs b/zingolib/src/wallet/traits.rs index 93527a7f7..1445a081f 100644 --- a/zingolib/src/wallet/traits.rs +++ b/zingolib/src/wallet/traits.rs @@ -3,9 +3,8 @@ use std::io::{self, Read, Write}; use super::{ data::{ - PoolNullifier, ReceivedOrchardNoteAndMetadata, ReceivedSaplingNoteAndMetadata, - SpendableOrchardNote, SpendableSaplingNote, TransactionMetadata, WitnessCache, - WitnessTrees, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, + OrchardNote, PoolNullifier, SaplingNote, SpendableOrchardNote, SpendableSaplingNote, + TransactionMetadata, WitnessCache, WitnessTrees, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, }, keys::unified::WalletCapability, transactions::TransactionMetadataSet, @@ -389,10 +388,9 @@ impl Nullifier for orchard::note::Nullifier { } } -/// "Received" because this data is eventually chain-retrievable -/// "Note" because this contains the Note itself -/// "AndMetaData" everything that the client will eventually know about the note -pub trait ReceivedNoteAndMetadata: Sized { +/// All zingolib::wallet::traits::Notes are NoteInterface +/// NoteInterface provides... +pub trait NoteInterface: Sized { type Diversifier: Copy + FromBytes<11> + ToBytes<11>; type Note: PartialEq @@ -450,7 +448,7 @@ pub trait ReceivedNoteAndMetadata: Sized { fn witnessed_position_mut(&mut self) -> &mut Option; } -impl ReceivedNoteAndMetadata for ReceivedSaplingNoteAndMetadata { +impl NoteInterface for SaplingNote { type Diversifier = zcash_primitives::sapling::Diversifier; type Note = zcash_primitives::sapling::Note; type Node = zcash_primitives::sapling::Node; @@ -573,7 +571,7 @@ impl ReceivedNoteAndMetadata for ReceivedSaplingNoteAndMetadata { } } -impl ReceivedNoteAndMetadata for ReceivedOrchardNoteAndMetadata { +impl NoteInterface for OrchardNote { type Diversifier = orchard::keys::Diversifier; type Note = orchard::note::Note; type Node = MerkleHashOrchard; @@ -707,7 +705,7 @@ where type SpendingKey: for<'a> TryFrom<&'a WalletCapability> + Clone; type CompactOutput: CompactOutput; - type WalletNote: ReceivedNoteAndMetadata< + type WalletNote: NoteInterface< Note = ::Note, Diversifier = <::Recipient as Recipient>::Diversifier, Nullifier = <<::Bundle as Bundle>::Spend as Spend>::Nullifier, @@ -725,7 +723,7 @@ where } fn transaction_metadata_set_to_shardtree( txmds: &TransactionMetadataSet, - ) -> Option<&MemoryStoreShardTree<::Node>> { + ) -> Option<&MemoryStoreShardTree<::Node>> { txmds .witness_trees .as_ref() @@ -733,8 +731,7 @@ where } fn transaction_metadata_set_to_shardtree_mut( txmds: &mut TransactionMetadataSet, - ) -> Option<&mut MemoryStoreShardTree<::Node>> - { + ) -> Option<&mut MemoryStoreShardTree<::Node>> { txmds .witness_trees .as_mut() @@ -742,15 +739,15 @@ where } fn get_shardtree( trees: &WitnessTrees, - ) -> &MemoryStoreShardTree<::Node>; + ) -> &MemoryStoreShardTree<::Node>; fn get_shardtree_mut( trees: &mut WitnessTrees, - ) -> &mut MemoryStoreShardTree<::Node>; + ) -> &mut MemoryStoreShardTree<::Node>; fn get_nullifier_from_note_fvk_and_witness_position( note: &Self::Note, fvk: &Self::Fvk, position: u64, - ) -> ::Nullifier; + ) -> ::Nullifier; fn get_tree(tree_state: &TreeState) -> &String; fn to_notes_vec(_: &TransactionMetadata) -> &Vec; fn to_notes_vec_mut(_: &mut TransactionMetadata) -> &mut Vec; @@ -773,7 +770,7 @@ impl DomainWalletExt for SaplingDomain { type CompactOutput = CompactSaplingOutput; - type WalletNote = ReceivedSaplingNoteAndMetadata; + type WalletNote = SaplingNote; type SpendableNoteAT = SpendableSaplingNote; @@ -782,7 +779,7 @@ impl DomainWalletExt for SaplingDomain { fn get_shardtree( trees: &WitnessTrees, ) -> &ShardTree< - MemoryShardStore<::Node, BlockHeight>, + MemoryShardStore<::Node, BlockHeight>, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, > { @@ -791,7 +788,7 @@ impl DomainWalletExt for SaplingDomain { fn get_shardtree_mut( trees: &mut WitnessTrees, ) -> &mut ShardTree< - MemoryShardStore<::Node, BlockHeight>, + MemoryShardStore<::Node, BlockHeight>, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, > { @@ -801,7 +798,7 @@ impl DomainWalletExt for SaplingDomain { note: &Self::Note, fvk: &Self::Fvk, position: u64, - ) -> <::WalletNote as ReceivedNoteAndMetadata>::Nullifier { + ) -> <::WalletNote as NoteInterface>::Nullifier { note.nf(&fvk.fvk().vk.nk, position) } @@ -849,7 +846,7 @@ impl DomainWalletExt for OrchardDomain { type CompactOutput = CompactOrchardAction; - type WalletNote = ReceivedOrchardNoteAndMetadata; + type WalletNote = OrchardNote; type SpendableNoteAT = SpendableOrchardNote; @@ -858,7 +855,7 @@ impl DomainWalletExt for OrchardDomain { fn get_shardtree( trees: &WitnessTrees, ) -> &ShardTree< - MemoryShardStore<::Node, BlockHeight>, + MemoryShardStore<::Node, BlockHeight>, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, > { @@ -867,7 +864,7 @@ impl DomainWalletExt for OrchardDomain { fn get_shardtree_mut( trees: &mut WitnessTrees, ) -> &mut ShardTree< - MemoryShardStore<::Node, BlockHeight>, + MemoryShardStore<::Node, BlockHeight>, COMMITMENT_TREE_LEVELS, MAX_SHARD_LEVEL, > { @@ -877,7 +874,7 @@ impl DomainWalletExt for OrchardDomain { note: &Self::Note, fvk: &Self::Fvk, _position: u64, - ) -> <::WalletNote as ReceivedNoteAndMetadata>::Nullifier { + ) -> <::WalletNote as NoteInterface>::Nullifier { note.nullifier(fvk) } @@ -917,34 +914,34 @@ impl DomainWalletExt for OrchardDomain { } pub trait Diversifiable { - type Note: ReceivedNoteAndMetadata; + type Note: NoteInterface; type Address: Recipient; fn diversified_address( &self, - div: ::Diversifier, + div: ::Diversifier, ) -> Option; } impl Diversifiable for zip32::sapling::DiversifiableFullViewingKey { - type Note = ReceivedSaplingNoteAndMetadata; + type Note = SaplingNote; type Address = zcash_primitives::sapling::PaymentAddress; fn diversified_address( &self, - div: <::Note as ReceivedNoteAndMetadata>::Diversifier, + div: <::Note as NoteInterface>::Diversifier, ) -> Option { self.fvk().vk.to_payment_address(div) } } impl Diversifiable for orchard::keys::FullViewingKey { - type Note = ReceivedOrchardNoteAndMetadata; + type Note = OrchardNote; type Address = orchard::Address; fn diversified_address( &self, - div: <::Note as ReceivedNoteAndMetadata>::Diversifier, + div: <::Note as NoteInterface>::Diversifier, ) -> Option { Some(self.address(div, orchard::keys::Scope::External)) } @@ -999,15 +996,15 @@ where /// default impl of `from`. This function's only caller should be `Self::from` fn from_parts_unchecked( transaction_id: TxId, - nullifier: ::Nullifier, - diversifier: ::Diversifier, + nullifier: ::Nullifier, + diversifier: ::Diversifier, note: D::Note, witnessed_position: Position, sk: Option<&D::SpendingKey>, ) -> Self; fn transaction_id(&self) -> TxId; - fn nullifier(&self) -> ::Nullifier; - fn diversifier(&self) -> ::Diversifier; + fn nullifier(&self) -> ::Nullifier; + fn diversifier(&self) -> ::Diversifier; fn note(&self) -> &D::Note; fn witnessed_position(&self) -> &Position; fn spend_key(&self) -> Option<&D::SpendingKey>; @@ -1275,7 +1272,7 @@ impl >, )> for T where - T: ReceivedNoteAndMetadata, + T: NoteInterface, { const VERSION: u8 = 4; @@ -1294,7 +1291,7 @@ where let external_version = Self::get_version(&mut reader)?; if external_version < 2 { - let mut x = ::get_deprecated_serialized_view_key_buffer(); + let mut x = ::get_deprecated_serialized_view_key_buffer(); reader.read_exact(&mut x).expect("To not used this data."); } diff --git a/zingolib/src/wallet/transactions.rs b/zingolib/src/wallet/transactions.rs index d6a8a4a88..0f47d3a4a 100644 --- a/zingolib/src/wallet/transactions.rs +++ b/zingolib/src/wallet/transactions.rs @@ -20,11 +20,9 @@ use zcash_primitives::{ use zingoconfig::{ChainType, MAX_REORG}; use super::{ - data::{ - OutgoingTxData, PoolNullifier, ReceivedTransparentOutput, TransactionMetadata, WitnessTrees, - }, + data::{OutgoingTxData, PoolNullifier, TransactionMetadata, TransparentNote, WitnessTrees}, keys::unified::WalletCapability, - traits::{self, DomainWalletExt, Nullifier, ReceivedNoteAndMetadata, Recipient}, + traits::{self, DomainWalletExt, NoteInterface, Nullifier, Recipient}, }; /// HashMap of all transactions in a wallet, keyed by txid. @@ -217,7 +215,7 @@ impl TransactionMetadataSet { self.current.values_mut().for_each(|transaction_metadata| { // Update UTXOs to rollback any spent utxos transaction_metadata - .received_utxos + .transparent_notes .iter_mut() .for_each(|utxo| { if utxo.spent.is_some() && txids_to_remove.contains(&utxo.spent.unwrap()) { @@ -355,7 +353,7 @@ impl TransactionMetadataSet { pub fn get_nullifier_value_txid_outputindex_of_unspent_notes( &self, ) -> Vec<( - <::WalletNote as ReceivedNoteAndMetadata>::Nullifier, + <::WalletNote as NoteInterface>::Nullifier, u64, TxId, u32, @@ -471,7 +469,7 @@ impl TransactionMetadataSet { } } } - fn mark_notes_as_change_for_pool(notes: &mut [Note]) { + fn mark_notes_as_change_for_pool(notes: &mut [Note]) { notes.iter_mut().for_each(|n| { *n.is_change_mut() = match n.memo() { Some(Memo::Text(_)) => false, @@ -560,7 +558,7 @@ impl TransactionMetadataSet { height: BlockHeight, unconfirmed: bool, timestamp: u32, - spent_nullifier: ::Nullifier, + spent_nullifier: ::Nullifier, value: u64, source_txid: TxId, output_index: u32, @@ -574,9 +572,11 @@ impl TransactionMetadataSet { // Mark the height correctly, in case this was previously a mempool or unconfirmed tx. transaction_metadata.block_height = height; - if !::Nullifier::get_nullifiers_spent_in_transaction(transaction_metadata) - .iter() - .any(|nf| *nf == spent_nullifier) + if !::Nullifier::get_nullifiers_spent_in_transaction( + transaction_metadata, + ) + .iter() + .any(|nf| *nf == spent_nullifier) { transaction_metadata.add_spent_nullifier(spent_nullifier.into(), value) } @@ -651,7 +651,7 @@ impl TransactionMetadataSet { // Find the UTXO let value = if let Some(utxo_transacion_metadata) = self.current.get_mut(&spent_txid) { if let Some(spent_utxo) = utxo_transacion_metadata - .received_utxos + .transparent_notes .iter_mut() .find(|u| u.txid == spent_txid && u.output_index == output_num as u64) { @@ -695,7 +695,7 @@ impl TransactionMetadataSet { // Add this UTXO if it doesn't already exist if let Some(utxo) = transaction_metadata - .received_utxos + .transparent_notes .iter_mut() .find(|utxo| utxo.txid == txid && utxo.output_index == output_num as u64) { @@ -703,8 +703,8 @@ impl TransactionMetadataSet { utxo.height = height as i32 } else { transaction_metadata - .received_utxos - .push(ReceivedTransparentOutput { + .transparent_notes + .push(TransparentNote { address: taddr, txid, output_index: output_num as u64, @@ -768,10 +768,10 @@ impl TransactionMetadataSet { height: BlockHeight, unconfirmed: bool, timestamp: u64, - note: ::Note, + note: ::Note, to: D::Recipient, have_spending_key: bool, - nullifier: Option<::Nullifier>, + nullifier: Option<::Nullifier>, output_index: u32, position: Position, ) where @@ -843,7 +843,7 @@ impl TransactionMetadataSet { } // Update the memo for a note if it already exists. If the note doesn't exist, then nothing happens. - pub(crate) fn add_memo_to_note_metadata( + pub(crate) fn add_memo_to_note_metadata( &mut self, txid: &TxId, note: Nd::Note,