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

Dev #13

Closed
wants to merge 5 commits into from
Closed

Dev #13

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
8 changes: 7 additions & 1 deletion zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Zingo]
- replace create_proposed_transaction with `calculate_proposed_transaction`
- dont try to write the calculated transaction to wallet, that will be handled later
- ignore collecting any transaction metadata
- handle usk differently
- modify change algorithm
- added display for NoteId

## [0.12.1] - 2024-03-27

Expand Down
20 changes: 15 additions & 5 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use nonempty::NonEmpty;
use rand_core::OsRng;
use sapling::{
note_encryption::{try_sapling_note_decryption, PreparedIncomingViewingKey},

Check failure on line 39 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused imports: `PreparedIncomingViewingKey`, `try_sapling_note_decryption`

error: unused imports: `PreparedIncomingViewingKey`, `try_sapling_note_decryption` --> zcash_client_backend/src/data_api/wallet.rs:39:23 | 39 | note_encryption::{try_sapling_note_decryption, PreparedIncomingViewingKey}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

Check failure on line 39 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused imports: `PreparedIncomingViewingKey`, `try_sapling_note_decryption`

error: unused imports: `PreparedIncomingViewingKey`, `try_sapling_note_decryption` --> zcash_client_backend/src/data_api/wallet.rs:39:23 | 39 | note_encryption::{try_sapling_note_decryption, PreparedIncomingViewingKey}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings`
prover::{OutputProver, SpendProver},
};
use std::num::NonZeroU32;
Expand All @@ -45,20 +45,20 @@
use crate::{
address::Address,
data_api::{
error::Error, Account, SentTransaction, SentTransactionOutput, WalletCommitmentTrees,

Check failure on line 48 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused imports: `Recipient`, `SentTransactionOutput`, `SentTransaction`

error: unused imports: `Recipient`, `SentTransactionOutput`, `SentTransaction` --> zcash_client_backend/src/data_api/wallet.rs:48:32 | 48 | error::Error, Account, SentTransaction, SentTransactionOutput, WalletCommitmentTrees, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ... 55 | wallet::{Note, OvkPolicy, Recipient, TransparentAddressMetadata}, | ^^^^^^^^^

Check failure on line 48 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused imports: `Recipient`, `SentTransactionOutput`, `SentTransaction`

error: unused imports: `Recipient`, `SentTransactionOutput`, `SentTransaction` --> zcash_client_backend/src/data_api/wallet.rs:48:32 | 48 | error::Error, Account, SentTransaction, SentTransactionOutput, WalletCommitmentTrees, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ... 55 | wallet::{Note, OvkPolicy, Recipient, TransparentAddressMetadata}, | ^^^^^^^^^
WalletRead, WalletWrite,
},
decrypt_transaction,
fees::{self, DustOutputPolicy},
keys::UnifiedSpendingKey,
proposal::{self, Proposal, ProposalError},
wallet::{Note, OvkPolicy, Recipient},
wallet::{Note, OvkPolicy, Recipient, TransparentAddressMetadata},
zip321::{self, Payment},
PoolType, ShieldedProtocol,
};
use zcash_primitives::transaction::{
builder::{BuildConfig, BuildResult, Builder},
components::{amount::NonNegativeAmount, sapling::zip212_enforcement},

Check failure on line 61 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `sapling::zip212_enforcement`

error: unused import: `sapling::zip212_enforcement` --> zcash_client_backend/src/data_api/wallet.rs:61:45 | 61 | components::{amount::NonNegativeAmount, sapling::zip212_enforcement}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check failure on line 61 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `sapling::zip212_enforcement`

error: unused import: `sapling::zip212_enforcement` --> zcash_client_backend/src/data_api/wallet.rs:61:45 | 61 | components::{amount::NonNegativeAmount, sapling::zip212_enforcement}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
fees::{zip317::FeeError as Zip317FeeError, FeeRule, StandardFeeRule},
Transaction, TxId,
};
Expand Down Expand Up @@ -584,13 +584,13 @@
#[allow(clippy::too_many_arguments)]
#[allow(clippy::type_complexity)]
pub fn create_proposed_transactions<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
wallet_db: &mut DbT,

Check failure on line 587 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `wallet_db`

error: unused variable: `wallet_db` --> zcash_client_backend/src/data_api/wallet.rs:587:5 | 587 | wallet_db: &mut DbT, | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_wallet_db` | = note: `-D unused-variables` implied by `-D warnings`

Check failure on line 587 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `wallet_db`

error: unused variable: `wallet_db` --> zcash_client_backend/src/data_api/wallet.rs:587:5 | 587 | wallet_db: &mut DbT, | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_wallet_db` | = note: `-D unused-variables` implied by `-D warnings`
params: &ParamsT,

Check failure on line 588 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `params`

error: unused variable: `params` --> zcash_client_backend/src/data_api/wallet.rs:588:5 | 588 | params: &ParamsT, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_params`

Check failure on line 588 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `params`

error: unused variable: `params` --> zcash_client_backend/src/data_api/wallet.rs:588:5 | 588 | params: &ParamsT, | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_params`
spend_prover: &impl SpendProver,

Check failure on line 589 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `spend_prover`

error: unused variable: `spend_prover` --> zcash_client_backend/src/data_api/wallet.rs:589:5 | 589 | spend_prover: &impl SpendProver, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_spend_prover`

Check failure on line 589 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `spend_prover`

error: unused variable: `spend_prover` --> zcash_client_backend/src/data_api/wallet.rs:589:5 | 589 | spend_prover: &impl SpendProver, | ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_spend_prover`
output_prover: &impl OutputProver,

Check failure on line 590 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `output_prover`

error: unused variable: `output_prover` --> zcash_client_backend/src/data_api/wallet.rs:590:5 | 590 | output_prover: &impl OutputProver, | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_output_prover`

Check failure on line 590 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `output_prover`

error: unused variable: `output_prover` --> zcash_client_backend/src/data_api/wallet.rs:590:5 | 590 | output_prover: &impl OutputProver, | ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_output_prover`
usk: &UnifiedSpendingKey,

Check failure on line 591 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `usk`

error: unused variable: `usk` --> zcash_client_backend/src/data_api/wallet.rs:591:5 | 591 | usk: &UnifiedSpendingKey, | ^^^ help: if this is intentional, prefix it with an underscore: `_usk`

Check failure on line 591 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `usk`

error: unused variable: `usk` --> zcash_client_backend/src/data_api/wallet.rs:591:5 | 591 | usk: &UnifiedSpendingKey, | ^^^ help: if this is intentional, prefix it with an underscore: `_usk`
ovk_policy: OvkPolicy,

Check failure on line 592 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `ovk_policy`

error: unused variable: `ovk_policy` --> zcash_client_backend/src/data_api/wallet.rs:592:5 | 592 | ovk_policy: OvkPolicy, | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_ovk_policy`

Check failure on line 592 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `ovk_policy`

error: unused variable: `ovk_policy` --> zcash_client_backend/src/data_api/wallet.rs:592:5 | 592 | ovk_policy: OvkPolicy, | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_ovk_policy`
proposal: &Proposal<FeeRuleT, N>,

Check failure on line 593 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `proposal`

error: unused variable: `proposal` --> zcash_client_backend/src/data_api/wallet.rs:593:5 | 593 | proposal: &Proposal<FeeRuleT, N>, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_proposal`

Check failure on line 593 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `proposal`

error: unused variable: `proposal` --> zcash_client_backend/src/data_api/wallet.rs:593:5 | 593 | proposal: &Proposal<FeeRuleT, N>, | ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_proposal`
) -> Result<
NonEmpty<TxId>,
Error<
Expand All @@ -606,7 +606,7 @@
FeeRuleT: FeeRule,
{
unimplemented!();
let mut step_results = Vec::with_capacity(proposal.steps().len());

Check failure on line 609 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unreachable statement

error: unreachable statement --> zcash_client_backend/src/data_api/wallet.rs:609:5 | 608 | unimplemented!(); | ---------------- any code following this expression is unreachable 609 | let mut step_results = Vec::with_capacity(proposal.steps().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: `-D unreachable-code` implied by `-D warnings`

Check failure on line 609 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unreachable statement

error: unreachable statement --> zcash_client_backend/src/data_api/wallet.rs:609:5 | 608 | unimplemented!(); | ---------------- any code following this expression is unreachable 609 | let mut step_results = Vec::with_capacity(proposal.steps().len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: `-D unreachable-code` implied by `-D warnings`
for step in proposal.steps() {
let step_result = calculate_proposed_transaction(
wallet_db,
Expand All @@ -619,6 +619,7 @@
proposal.min_target_height(),
&step_results,
step,
None,
)?;
step_results.push((step, step_result));
}
Expand Down Expand Up @@ -646,6 +647,9 @@
min_target_height: BlockHeight,
prior_step_results: &[(&proposal::Step<N>, BuildResult)],
proposal_step: &proposal::Step<N>,
usk_to_tkey: Option<
fn(&UnifiedSpendingKey, &TransparentAddressMetadata) -> hdwallet::secp256k1::SecretKey,
>,
) -> Result<
BuildResult,
Error<
Expand Down Expand Up @@ -800,7 +804,7 @@
}

#[cfg(feature = "transparent-inputs")]
let utxos_spent = {

Check failure on line 807 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `utxos_spent`

error: unused variable: `utxos_spent` --> zcash_client_backend/src/data_api/wallet.rs:807:9 | 807 | let utxos_spent = { | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_utxos_spent`

Check failure on line 807 in zcash_client_backend/src/data_api/wallet.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused variable: `utxos_spent`

error: unused variable: `utxos_spent` --> zcash_client_backend/src/data_api/wallet.rs:807:9 | 807 | let utxos_spent = { | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_utxos_spent`
let known_addrs = wallet_db
.get_transparent_receivers(account)
.map_err(Error::DataSource)?;
Expand All @@ -824,10 +828,16 @@
.clone()
.ok_or_else(|| Error::NoSpendingKey(addr.encode(params)))?;

let secret_key = usk
.transparent()
.derive_secret_key(address_metadata.scope(), address_metadata.address_index())
.unwrap();
let secret_key = usk_to_tkey
.map(|f| f(usk, &address_metadata))
.unwrap_or_else(|| {
usk.transparent()
.derive_secret_key(
address_metadata.scope(),
address_metadata.address_index(),
)
.unwrap()
});

utxos_spent.push(outpoint.clone());
builder.add_transparent_input(secret_key, outpoint, utxo)?;
Expand Down
10 changes: 9 additions & 1 deletion zcash_client_backend/src/fees/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ where
})?;

if proposed_change.is_zero() {
TransactionBalance::new(vec![], fee_amount).map_err(|_| overflow())
TransactionBalance::new(
vec![ChangeValue::new(
_fallback_change_pool,
NonNegativeAmount::const_from_u64(0),
change_memo,
)],
fee_amount,
)
.map_err(|_| overflow())
} else {
let dust_threshold = dust_output_policy
.dust_threshold()
Expand Down
14 changes: 14 additions & 0 deletions zcash_client_backend/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Structs representing transaction data scanned from the block chain by a wallet or
//! light client.

use std::fmt;

use incrementalmerkletree::Position;
use zcash_keys::address::Address;
use zcash_note_encryption::EphemeralKeyBytes;
Expand Down Expand Up @@ -62,6 +64,18 @@ impl NoteId {
}
}

impl fmt::Display for NoteId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"txid {} protocol {:?} output_index {}",
self.txid(),
self.protocol(),
self.output_index()
)
}
}

/// A type that represents the recipient of a transaction output: a recipient address (and, for
/// unified addresses, the pool to which the payment is sent) in the case of an outgoing output, or an
/// internal account ID and the pool to which funds were sent in the case of a wallet-internal
Expand Down
Loading