Skip to content

Commit

Permalink
zcash_protocol: Rename value amounts to Zatoshis and ZatBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Jan 27, 2024
1 parent 9cf0d55 commit af15ecf
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 186 deletions.
319 changes: 161 additions & 158 deletions components/zcash_protocol/src/value.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions zcash_client_backend/src/data_api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use zcash_primitives::{
memo::MemoBytes,
transaction::{
builder::{BuildConfig, Builder},
components::{amount::{Amount, NonNegativeAmount}, sapling::zip212_enforcement},
components::{
amount::{Amount, NonNegativeAmount},
sapling::zip212_enforcement,
},
fees::{zip317::FeeError as Zip317FeeError, FeeRule, StandardFeeRule},
Transaction, TxId,
},
Expand Down Expand Up @@ -777,10 +780,7 @@ where
try_sapling_note_decryption(
&internal_ivk,
&bundle.shielded_outputs()[output_index],
zip212_enforcement(
params,
proposal.min_target_height(),
),
zip212_enforcement(params, proposal.min_target_height()),
)
.map(|(note, _, _)| (account, note))
})
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/src/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sapling::note_encryption::{
use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{Transaction, components::sapling::zip212_enforcement},
transaction::{components::sapling::zip212_enforcement, Transaction},
zip32::{AccountId, Scope},
};

Expand Down
19 changes: 10 additions & 9 deletions zcash_client_sqlite/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,12 @@ pub(crate) fn fake_compact_block<P: consensus::Parameters>(

// Create a fake Note for the account
let mut rng = OsRng;
let rseed = generate_random_rseed(
zip212_enforcement(params, height),
&mut rng,
);
let note = Note::from_parts(to,
let rseed = generate_random_rseed(zip212_enforcement(params, height), &mut rng);
let note = Note::from_parts(
to,
sapling::value::NoteValue::from_raw(value.into_u64()),
rseed);
rseed,
);
let encryptor = sapling_note_encryption(
Some(dfvk.fvk().ovk),
note.clone(),
Expand Down Expand Up @@ -876,9 +875,11 @@ pub(crate) fn fake_compact_block_spending<P: consensus::Parameters>(

// Create a fake Note for the payment
ctx.outputs.push({
let note = Note::from_parts(to,
sapling::value::NoteValue::from_raw(value.into_u64()),
rseed);
let note = Note::from_parts(
to,
sapling::value::NoteValue::from_raw(value.into_u64()),
rseed,
);
let encryptor = sapling_note_encryption(
Some(dfvk.fvk().ovk),
note.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use sapling::{
use zcash_client_backend::{data_api::SAPLING_SHARD_HEIGHT, keys::UnifiedFullViewingKey};
use zcash_primitives::{
consensus::{self, BlockHeight, BranchId},
transaction::{components::{amount::NonNegativeAmount, sapling::zip212_enforcement}, Transaction},
transaction::{
components::{amount::NonNegativeAmount, sapling::zip212_enforcement},
Transaction,
},
zip32::Scope,
};

Expand Down
7 changes: 2 additions & 5 deletions zcash_client_sqlite/src/wallet/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use sapling::{self, Diversifier, Nullifier, Rseed};
use zcash_primitives::{
consensus::{self, BlockHeight},
memo::MemoBytes,
transaction::{
components::Amount,
TxId,
},
transaction::{components::Amount, TxId},
zip32::{AccountId, Scope},
};

Expand Down Expand Up @@ -483,7 +480,7 @@ pub(crate) mod tests {
legacy::TransparentAddress,
memo::{Memo, MemoBytes},
transaction::{
components::{amount::NonNegativeAmount, Amount, sapling::zip212_enforcement},
components::{amount::NonNegativeAmount, sapling::zip212_enforcement, Amount},
fees::{
fixed::FeeRule as FixedFeeRule, zip317::FeeError as Zip317FeeError, StandardFeeRule,
},
Expand Down
2 changes: 1 addition & 1 deletion zcash_primitives/benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sapling::{
use zcash_note_encryption::batch;
use zcash_primitives::{
consensus::{NetworkUpgrade::Canopy, Parameters, TEST_NETWORK},
transaction::components::{Amount, sapling::zip212_enforcement},
transaction::components::{sapling::zip212_enforcement, Amount},
};

#[cfg(unix)]
Expand Down
13 changes: 12 additions & 1 deletion zcash_primitives/src/transaction/components.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
//! Structs representing the components within Zcash transactions.
pub mod amount {
pub use zcash_protocol::value::{
BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount, COIN,
};

pub use zcash_protocol::value as amount;
#[cfg(feature = "test-dependencies")]
pub mod testing {
pub use zcash_protocol::value::testing::{
arb_positive_zat_balance as arb_positive_amount, arb_zat_balance as arb_amount,
arb_zatoshis as arb_nonnegative_amount,
};
}
}
pub mod orchard;
pub mod sapling;
pub mod sprout;
Expand Down
7 changes: 2 additions & 5 deletions zcash_primitives/src/transaction/components/sapling.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ff::PrimeField;
use redjubjub::SpendAuth;
use sapling::note_encryption::Zip212Enforcement;
use zcash_protocol::consensus::{Parameters, NetworkUpgrade, BlockHeight, ZIP212_GRACE_PERIOD};
use zcash_protocol::consensus::{BlockHeight, NetworkUpgrade, Parameters, ZIP212_GRACE_PERIOD};

use std::io::{self, Read, Write};

Expand All @@ -24,10 +24,7 @@ use crate::{
use super::{Amount, GROTH_PROOF_SIZE};

/// Returns the enforcement policy for ZIP 212 at the given height.
pub fn zip212_enforcement(
params: &impl Parameters,
height: BlockHeight,
) -> Zip212Enforcement {
pub fn zip212_enforcement(params: &impl Parameters, height: BlockHeight) -> Zip212Enforcement {
if params.is_nu_active(NetworkUpgrade::Canopy, height) {
let grace_period_end_height =
params.activation_height(NetworkUpgrade::Canopy).unwrap() + ZIP212_GRACE_PERIOD;
Expand Down

0 comments on commit af15ecf

Please sign in to comment.