Skip to content

Commit

Permalink
Merge pull request #981 from fluidvanadium/transparent_output
Browse files Browse the repository at this point in the history
Transparent output
  • Loading branch information
zancas authored Apr 23, 2024
2 parents 47eb63c + 098e1bd commit 6fa486c
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 75 deletions.
6 changes: 3 additions & 3 deletions zingolib/src/lightclient/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp;
use crate::wallet::transaction_record::TransactionRecord;

use super::*;
use crate::wallet::notes::NoteInterface;
use crate::wallet::notes::OutputInterface;
use crate::wallet::notes::ShieldedNoteInterface;
use zcash_note_encryption::Domain;

Expand Down Expand Up @@ -123,7 +123,7 @@ impl LightClient {
.flat_map(|(txid, wallet_transaction)| {
let mut consumer_notes_by_tx: Vec<JsonValue> = vec![];

let total_transparent_received = wallet_transaction.transparent_notes.iter().map(|u| u.value).sum::<u64>();
let total_transparent_received = wallet_transaction.transparent_outputs.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 @@ -139,7 +139,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.get_transparent_value_spent() as i64;
let address = wallet_transaction.transparent_notes.iter().map(|utxo| utxo.address.clone()).collect::<Vec<String>>().join(",");
let address = wallet_transaction.transparent_outputs.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
8 changes: 4 additions & 4 deletions zingolib/src/lightclient/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
TransactionRecord,
},
keys::address_from_pubkeyhash,
notes::NoteInterface,
notes::OutputInterface,
LightWallet, Pool,
},
};
Expand Down Expand Up @@ -149,7 +149,7 @@ impl LightClient {
}
});

tx.transparent_notes
tx.transparent_outputs
.iter()
.filter(|n| !n.is_spent() && n.unconfirmed_spent.is_none())
.for_each(|n| {
Expand Down Expand Up @@ -402,7 +402,7 @@ impl LightClient {
}
// No funds spent, this is a normal receipt
(false, true) => {
for received_transparent in transaction_md.transparent_notes.iter() {
for received_transparent in transaction_md.transparent_outputs.iter() {
summaries.push(ValueTransfer {
block_height,
datetime,
Expand Down Expand Up @@ -587,7 +587,7 @@ impl LightClient {

self.wallet.transaction_context.transaction_metadata_set.read().await.transaction_records_by_id.iter()
.flat_map( |(transaction_id, wtx)| {
wtx.transparent_notes.iter().filter_map(move |utxo|
wtx.transparent_outputs.iter().filter_map(move |utxo|
if !all_notes && utxo.is_spent() {
None
} else {
Expand Down
12 changes: 6 additions & 6 deletions zingolib/src/wallet/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use zcash_note_encryption::Domain;
use zcash_primitives::consensus::BlockHeight;

use crate::wallet::data::TransactionRecord;
use crate::wallet::notes::NoteInterface;
use crate::wallet::notes::OutputInterface;
use crate::wallet::notes::ShieldedNoteInterface;

use crate::wallet::traits::Diversifiable as _;

use super::keys::unified::{Capability, WalletCapability};
use super::notes::TransparentNote;
use super::notes::TransparentOutput;
use super::traits::DomainWalletExt;
use super::traits::Recipient;

Expand Down Expand Up @@ -70,7 +70,7 @@ impl LightWallet {
filtered_notes
.map(|notedata| {
if notedata.spent().is_none() && notedata.pending_spent().is_none() {
<D::WalletNote as NoteInterface>::value(notedata)
<D::WalletNote as OutputInterface>::value(notedata)
} else {
0
}
Expand Down Expand Up @@ -247,7 +247,7 @@ impl LightWallet {
}

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

/// TODO: Add Doc Comment Here!
Expand Down
12 changes: 6 additions & 6 deletions zingolib/src/wallet/notes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! All things needed to create, manaage, and use notes
pub mod interface;
pub use interface::NoteInterface;
pub use interface::OutputInterface;
pub use interface::ShieldedNoteInterface;
pub mod transparent;
pub use transparent::TransparentNote;
pub use transparent::TransparentOutput;
pub mod sapling;
pub use sapling::SaplingNote;
pub mod orchard;
Expand Down Expand Up @@ -132,7 +132,7 @@ pub mod tests {
test_framework::mocks::default_txid,
wallet::notes::{
query::OutputQuery, sapling::mocks::SaplingNoteBuilder,
transparent::mocks::TransparentNoteBuilder, NoteInterface,
transparent::mocks::TransparentOutputBuilder, OutputInterface,
},
};

Expand All @@ -142,11 +142,11 @@ pub mod tests {
fn note_queries() {
let spend = Some((default_txid(), 112358));

let transparent_unspent_note = TransparentNoteBuilder::default().build();
let transparent_pending_spent_note = TransparentNoteBuilder::default()
let transparent_unspent_note = TransparentOutputBuilder::default().build();
let transparent_pending_spent_note = TransparentOutputBuilder::default()
.unconfirmed_spent(spend)
.build();
let transparent_spent_note = TransparentNoteBuilder::default().spent(spend).build();
let transparent_spent_note = TransparentOutputBuilder::default().spent(spend).build();
let sapling_unspent_note = SaplingNoteBuilder::default().build();
let sapling_pending_spent_note = SaplingNoteBuilder::default()
.unconfirmed_spent(spend)
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/wallet/notes/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{
};

/// TODO: Add Doc Comment Here!
pub trait NoteInterface: Sized {
pub trait OutputInterface: Sized {
/// returns the zcash_client_backend PoolType enum (one of 3)
fn pool_type(&self) -> PoolType;

Expand Down Expand Up @@ -71,7 +71,7 @@ pub trait NoteInterface: Sized {
}

/// ShieldedNotes are either part of a Sapling or Orchard Pool
pub trait ShieldedNoteInterface: NoteInterface + Sized {
pub trait ShieldedNoteInterface: OutputInterface + Sized {
/// TODO: Add Doc Comment Here!
type Diversifier: Copy + FromBytes<11> + ToBytes<11>;
/// TODO: Add Doc Comment Here!
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/wallet/notes/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zcash_primitives::{memo::Memo, transaction::TxId};

use super::{
super::{data::TransactionRecord, Pool},
NoteInterface, ShieldedNoteInterface,
OutputInterface, ShieldedNoteInterface,
};

/// TODO: Add Doc Comment Here!
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct OrchardNote {
pub have_spending_key: bool,
}

impl NoteInterface for OrchardNote {
impl OutputInterface for OrchardNote {
fn pool_type(&self) -> PoolType {
PoolType::Shielded(ShieldedProtocol::Orchard)
}
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/wallet/notes/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zcash_primitives::{memo::Memo, transaction::TxId};

use super::{
super::{data::TransactionRecord, Pool},
NoteInterface, ShieldedNoteInterface,
OutputInterface, ShieldedNoteInterface,
};

/// TODO: Add Doc Comment Here!
Expand Down Expand Up @@ -62,7 +62,7 @@ impl std::fmt::Debug for SaplingNote {
}
}

impl NoteInterface for SaplingNote {
impl OutputInterface for SaplingNote {
fn pool_type(&self) -> PoolType {
PoolType::Shielded(ShieldedProtocol::Sapling)
}
Expand Down
24 changes: 12 additions & 12 deletions zingolib/src/wallet/notes/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use byteorder::{ReadBytesExt, WriteBytesExt};
use zcash_client_backend::PoolType;
use zcash_primitives::transaction::{components::OutPoint, TxId};

use super::NoteInterface;
use super::OutputInterface;

/// TODO: Add Doc Comment Here!
#[derive(Clone, Debug, PartialEq)]
pub struct TransparentNote {
pub struct TransparentOutput {
/// TODO: Add Doc Comment Here!
pub address: String,
/// TODO: Add Doc Comment Here!
Expand All @@ -29,7 +29,7 @@ pub struct TransparentNote {
pub unconfirmed_spent: Option<(TxId, u32)>,
}

impl NoteInterface for TransparentNote {
impl OutputInterface for TransparentOutput {
fn pool_type(&self) -> PoolType {
PoolType::Transparent
}
Expand All @@ -55,7 +55,7 @@ impl NoteInterface for TransparentNote {
}
}

impl TransparentNote {
impl TransparentOutput {
/// TODO: Add Doc Comment Here!
pub fn from_parts(
address: String,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl TransparentNote {
None
};

Ok(TransparentNote {
Ok(TransparentOutput {
address,
txid: transaction_id,
output_index,
Expand All @@ -196,10 +196,10 @@ pub mod mocks {
//! Mock version of the struct for testing
use zcash_primitives::transaction::TxId;

use crate::{test_framework::mocks::build_method, wallet::notes::TransparentNote};
use crate::{test_framework::mocks::build_method, wallet::notes::TransparentOutput};

/// to create a mock TransparentNote
pub struct TransparentNoteBuilder {
/// to create a mock TransparentOutput
pub struct TransparentOutputBuilder {
address: Option<String>,
txid: Option<TxId>,
output_index: Option<u64>,
Expand All @@ -209,7 +209,7 @@ pub mod mocks {
unconfirmed_spent: Option<Option<(TxId, u32)>>,
}
#[allow(dead_code)] //TODO: fix this gross hack that I tossed in to silence the language-analyzer false positive
impl TransparentNoteBuilder {
impl TransparentOutputBuilder {
/// blank builder
pub fn new() -> Self {
Self {
Expand All @@ -232,8 +232,8 @@ pub mod mocks {
build_method!(unconfirmed_spent, Option<(TxId, u32)>);

/// builds a mock TransparentNote after all pieces are supplied
pub fn build(self) -> TransparentNote {
TransparentNote::from_parts(
pub fn build(self) -> TransparentOutput {
TransparentOutput::from_parts(
self.address.unwrap(),
self.txid.unwrap(),
self.output_index.unwrap(),
Expand All @@ -245,7 +245,7 @@ pub mod mocks {
}
}

impl Default for TransparentNoteBuilder {
impl Default for TransparentOutputBuilder {
fn default() -> Self {
Self::new()
.address("default_address".to_string())
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/send.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This mod contains pieces of the impl LightWallet that are invoked during a send.
use crate::wallet::data::SpendableSaplingNote;
use crate::wallet::notes::NoteInterface;
use crate::wallet::notes::OutputInterface;
use crate::wallet::now;

use futures::Future;
Expand Down Expand Up @@ -613,7 +613,7 @@ impl LightWallet {
(
Vec<SpendableOrchardNote>,
Vec<SpendableSaplingNote>,
Vec<notes::TransparentNote>,
Vec<notes::TransparentOutput>,
u64,
),
u64,
Expand Down Expand Up @@ -750,7 +750,7 @@ impl LightWallet {
witness_trees: &WitnessTrees,
orchard_notes: &[SpendableOrchardNote],
sapling_notes: &[SpendableSaplingNote],
utxos: &[notes::TransparentNote],
utxos: &[notes::TransparentOutput],
) -> Result<TxBuilder<'_>, String> {
// Add all tinputs
// Create a map from address -> sk for all taddrs, so we can spend from the
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
notes::{OrchardNote, SaplingNote},
transactions::TxMapAndMaybeTrees,
};
use crate::wallet::notes::NoteInterface;
use crate::wallet::notes::OutputInterface;
use crate::wallet::notes::ShieldedNoteInterface;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use incrementalmerkletree::{witness::IncrementalWitness, Hashable, Level, Position};
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub mod decrypt_transaction {
{
// One of the tx outputs is a match
if let Some(spent_utxo) = wtx
.transparent_notes
.transparent_outputs
.iter()
.find(|u| u.txid == prev_transaction_id && u.output_index == prev_n)
{
Expand Down
Loading

0 comments on commit 6fa486c

Please sign in to comment.