Skip to content

Commit dfd8c06

Browse files
committed
fmt
1 parent 3d1fd27 commit dfd8c06

File tree

5 files changed

+124
-126
lines changed

5 files changed

+124
-126
lines changed

pczt/tests/end_to_end.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use ::transparent::{
55
bundle as transparent,
66
keys::{AccountPrivKey, IncomingViewingKey},
77
};
8-
use orchard::primitives::OrchardDomain;
98
use orchard::note::AssetBase;
109
use orchard::orchard_flavor::OrchardVanilla;
1110
use orchard::primitives::OrchardDomain;
11+
use orchard::primitives::OrchardDomain;
1212
use orchard::tree::MerkleHashOrchard;
1313
use pczt::{
1414
roles::{

zcash_primitives/src/transaction/builder.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ use crate::{
6060
},
6161
};
6262
use orchard::builder::BuildError::BundleTypeNotSatisfiable;
63+
#[cfg(zcash_unstable = "nu7" /* TODO swap */ )]
64+
use orchard::{
65+
primitives::redpallas::{Binding, SigningKey},
66+
swap_bundle::{ActionGroupAuthorized, SwapBundle},
67+
};
6368
#[cfg(zcash_unstable = "nu7")]
6469
use {
6570
orchard::{
@@ -72,11 +77,6 @@ use {
7277
},
7378
rand_core::OsRng,
7479
};
75-
#[cfg(zcash_unstable = "nu7" /* TODO swap */ )]
76-
use orchard::{
77-
primitives::redpallas::{Binding, SigningKey},
78-
swap_bundle::{ActionGroupAuthorized, SwapBundle},
79-
};
8080

8181
use super::components::sapling::zip212_enforcement;
8282

@@ -1046,7 +1046,7 @@ impl<P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<'_,
10461046
if bundle_type == BundleType::DEFAULT_SWAP {
10471047
#[cfg(zcash_unstable = "nu7")]
10481048
{
1049-
if !builder.is_empty() || self.action_groups.is_empty() {
1049+
if !builder.is_empty() || self.action_groups.is_empty() {
10501050
// TODO should build empty too
10511051
let timelimit: u32 = (self.target_height + 10).into(); // TODO default(?) timelimit
10521052

@@ -1085,24 +1085,23 @@ impl<P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder<'_,
10851085
.iter()
10861086
.map(|b| {
10871087
b.clone()
1088-
.try_map_value_balance(|v| Ok::<i64, core::convert::Infallible>(v.into()))
1088+
.try_map_value_balance(|v| {
1089+
Ok::<i64, core::convert::Infallible>(v.into())
1090+
})
10891091
.unwrap()
10901092
})
10911093
.collect();
10921094

10931095
// Create a temporary SwapBundle<i64> to compute the binding signature
1094-
let temp_swap_bundle =
1095-
SwapBundle::new(&mut rng, action_groups_i64, bsks);
1096+
let temp_swap_bundle = SwapBundle::new(&mut rng, action_groups_i64, bsks);
10961097

10971098
// Extract the binding signature and use it with the original ZatBalance action_groups
10981099
let binding_signature = temp_swap_bundle.binding_signature().clone();
10991100

11001101
// In this case the bundle is, in fact, already authorized
1101-
unproven_orchard_bundle = Some(OrchardBundle::OrchardSwap(SwapBundle::from_parts(
1102-
action_groups,
1103-
value_balance,
1104-
binding_signature,
1105-
)));
1102+
unproven_orchard_bundle = Some(OrchardBundle::OrchardSwap(
1103+
SwapBundle::from_parts(action_groups, value_balance, binding_signature),
1104+
));
11061105
}
11071106
#[cfg(not(zcash_unstable = "nu7"))]
11081107
return Err(Error::OrchardBuild(BundleTypeNotSatisfiable));
@@ -1425,8 +1424,8 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Extensio
14251424

14261425
#[cfg(any(test, feature = "test-dependencies"))]
14271426
mod testing {
1428-
use std::convert::Infallible;
14291427
use super::{BuildResult, Builder, Error};
1428+
use std::convert::Infallible;
14301429

14311430
use crate::transaction::fees::zip317;
14321431
use ::sapling::prover::mock::{MockOutputProver, MockSpendProver};
@@ -1524,7 +1523,8 @@ mod testing {
15241523
&MockOutputProver,
15251524
#[allow(deprecated)]
15261525
&fee_rule,
1527-
#[cfg(zcash_unstable = "nu7")] |_| true,
1526+
#[cfg(zcash_unstable = "nu7")]
1527+
|_| true,
15281528
)
15291529
}
15301530
}
@@ -1557,16 +1557,14 @@ mod tests {
15571557
use {
15581558
crate::transaction::fees::zip317::FeeError,
15591559
orchard::builder::BundleType,
1560-
orchard::keys::{
1561-
FullViewingKey, SpendingKey,
1562-
},
1560+
orchard::keys::{FullViewingKey, SpendingKey},
15631561
orchard::note::AssetBase,
15641562
orchard::orchard_flavor::OrchardZSA,
15651563
orchard::tree::MerklePath,
15661564
orchard::value::NoteValue,
15671565
orchard::Address,
15681566
orchard::Note,
1569-
zcash_protocol::consensus::{REGTEST_NETWORK, RegtestNetwork},
1567+
zcash_protocol::consensus::{RegtestNetwork, REGTEST_NETWORK},
15701568
zcash_protocol::constants::testnet::COIN_TYPE,
15711569
zip32::Scope::External,
15721570
};
@@ -1601,7 +1599,7 @@ mod tests {
16011599
orchard::{
16021600
issuance::{compute_asset_desc_hash, IssueInfo},
16031601
issuance_auth::{IssueAuthKey, IssueValidatingKey},
1604-
keys::{SpendAuthorizingKey},
1602+
keys::SpendAuthorizingKey,
16051603
orchard_flavor::OrchardVanilla,
16061604
primitives::OrchardDomain,
16071605
},

zcash_primitives/src/transaction/components/orchard.rs

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use core2::io::{self, Read, Write};
1616
use nonempty::NonEmpty;
1717
use orchard::{
1818
bundle::{Authorization, Authorized, Flags},
19-
primitives::OrchardPrimitives,
2019
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext},
2120
orchard_flavor::OrchardVanilla,
2221
orchard_sighash_versioning::{OrchardSighashVersion, OrchardVersionedSig},
2322
primitives::redpallas::{self, SigType, Signature, SpendAuth, VerificationKey},
23+
primitives::OrchardPrimitives,
2424
value::ValueCommitment,
2525
Action, Anchor, Bundle, Proof,
2626
};
@@ -29,13 +29,13 @@ use zcash_note_encryption::note_bytes::NoteBytes;
2929

3030
use zcash_protocol::value::ZatBalance;
3131

32+
#[cfg(zcash_unstable = "nu7")]
33+
use orchard::orchard_sighash_versioning::VerSpendAuthSig;
3234
#[cfg(zcash_unstable = "nu7" /* TODO swap */ )]
3335
use orchard::{
34-
swap_bundle::{ActionGroupAuthorized, SwapBundle},
3536
primitives::redpallas::Binding,
37+
swap_bundle::{ActionGroupAuthorized, SwapBundle},
3638
};
37-
#[cfg(zcash_unstable = "nu7")]
38-
use orchard::orchard_sighash_versioning::VerSpendAuthSig;
3939

4040
pub const FLAG_SPENDS_ENABLED: u8 = 0b0000_0001;
4141
pub const FLAG_OUTPUTS_ENABLED: u8 = 0b0000_0010;
@@ -134,10 +134,12 @@ pub fn read_v6_bundle<R: Read>(
134134

135135
/// Reads an [`orchard::Bundle`] from a v6 transaction format.
136136
#[cfg(zcash_unstable = "nu7")]
137-
pub fn read_orchard_swap_bundle<R: Read>(mut reader: R) -> io::Result<Option<SwapBundle<ZatBalance>>> {
137+
pub fn read_orchard_swap_bundle<R: Read>(
138+
mut reader: R,
139+
) -> io::Result<Option<SwapBundle<ZatBalance>>> {
138140
let action_groups = read_action_groups(&mut reader)?;
139141

140-
if action_groups.is_empty() {
142+
if action_groups.is_empty() {
141143
return Ok(None);
142144
}
143145

@@ -392,54 +394,53 @@ pub fn write_versioned_signature<W: Write, T: SigType>(
392394
writer.write_all(&<[u8; 64]>::from(versioned_sig.sig()))
393395
}
394396

395-
/// Writes an [`orchard::Bundle`] in the appropriate transaction format.
396-
pub fn write_orchard_bundle<W: Write>(
397-
mut writer: W,
398-
bundle: Option<&OrchardBundle<Authorized>>,
399-
) -> io::Result<()> {
400-
if let Some(bundle) = bundle {
401-
match bundle {
402-
OrchardBundle::OrchardVanilla(b) => write_v5_bundle(b, writer)?,
403-
#[cfg(zcash_unstable = "nu7")]
404-
OrchardBundle::OrchardZSA(b) => write_v6_bundle(writer, b)?,
405-
#[cfg(zcash_unstable = "nu7")]
406-
OrchardBundle::OrchardSwap(b) => write_orchard_swap_bundle(writer, b)?,
407-
}
408-
} else {
409-
CompactSize::write(&mut writer, 0)?;
397+
/// Writes an [`orchard::Bundle`] in the appropriate transaction format.
398+
pub fn write_orchard_bundle<W: Write>(
399+
mut writer: W,
400+
bundle: Option<&OrchardBundle<Authorized>>,
401+
) -> io::Result<()> {
402+
if let Some(bundle) = bundle {
403+
match bundle {
404+
OrchardBundle::OrchardVanilla(b) => write_v5_bundle(b, writer)?,
405+
#[cfg(zcash_unstable = "nu7")]
406+
OrchardBundle::OrchardZSA(b) => write_v6_bundle(writer, b)?,
407+
#[cfg(zcash_unstable = "nu7")]
408+
OrchardBundle::OrchardSwap(b) => write_orchard_swap_bundle(writer, b)?,
410409
}
411-
412-
Ok(())
410+
} else {
411+
CompactSize::write(&mut writer, 0)?;
413412
}
414413

414+
Ok(())
415+
}
415416

416-
/// Writes an [`orchard::Bundle`] in the v5 transaction format.
417-
pub fn write_v5_bundle<W: Write>(
418-
bundle: &Bundle<Authorized, ZatBalance, OrchardVanilla>,
419-
mut writer: W,
420-
) -> io::Result<()> {
421-
Vector::write_nonempty(&mut writer, bundle.actions(), |w, a| {
422-
write_action_without_auth(w, a)
423-
})?;
417+
/// Writes an [`orchard::Bundle`] in the v5 transaction format.
418+
pub fn write_v5_bundle<W: Write>(
419+
bundle: &Bundle<Authorized, ZatBalance, OrchardVanilla>,
420+
mut writer: W,
421+
) -> io::Result<()> {
422+
Vector::write_nonempty(&mut writer, bundle.actions(), |w, a| {
423+
write_action_without_auth(w, a)
424+
})?;
424425

425-
writer.write_all(&[bundle.flags().to_byte()])?;
426-
writer.write_all(&bundle.value_balance().to_i64_le_bytes())?;
427-
writer.write_all(&bundle.anchor().to_bytes())?;
428-
Vector::write(
429-
&mut writer,
430-
bundle.authorization().proof().unwrap().as_ref(),
431-
|w, b| w.write_all(&[*b]),
432-
)?;
433-
Array::write(
434-
&mut writer,
435-
bundle.actions().iter().map(|a| a.authorization().sig()),
436-
|w, auth| w.write_all(&<[u8; 64]>::from(*auth)),
437-
)?;
438-
writer.write_all(&<[u8; 64]>::from(
439-
bundle.authorization().binding_signature().sig(),
440-
))?;
441-
Ok(())
442-
}
426+
writer.write_all(&[bundle.flags().to_byte()])?;
427+
writer.write_all(&bundle.value_balance().to_i64_le_bytes())?;
428+
writer.write_all(&bundle.anchor().to_bytes())?;
429+
Vector::write(
430+
&mut writer,
431+
bundle.authorization().proof().unwrap().as_ref(),
432+
|w, b| w.write_all(&[*b]),
433+
)?;
434+
Array::write(
435+
&mut writer,
436+
bundle.actions().iter().map(|a| a.authorization().sig()),
437+
|w, auth| w.write_all(&<[u8; 64]>::from(*auth)),
438+
)?;
439+
writer.write_all(&<[u8; 64]>::from(
440+
bundle.authorization().binding_signature().sig(),
441+
))?;
442+
Ok(())
443+
}
443444

444445
#[cfg(zcash_unstable = "nu7")]
445446
fn read_note_value<R: Read>(mut reader: R) -> io::Result<NoteValue> {
@@ -477,56 +478,55 @@ pub fn write_v6_bundle<W: Write>(
477478
Ok(())
478479
}
479480

481+
/// Writes an [`orchard::Bundle`] in the appropriate transaction format.
482+
#[cfg(zcash_unstable = "nu7")]
483+
pub fn write_orchard_swap_bundle<W: Write>(
484+
mut writer: W,
485+
bundle: &SwapBundle<ZatBalance>,
486+
) -> io::Result<()> {
487+
CompactSize::write(&mut writer, bundle.action_groups().len())?;
488+
bundle
489+
.action_groups()
490+
.into_iter()
491+
.for_each(|ag| write_action_group(&mut writer, ag).unwrap());
492+
write_bundle_balance_metadata(
493+
&mut writer,
494+
bundle.value_balance(),
495+
bundle.binding_signature(),
496+
)?;
497+
Ok(())
498+
}
480499

481-
/// Writes an [`orchard::Bundle`] in the appropriate transaction format.
482-
#[cfg(zcash_unstable = "nu7")]
483-
pub fn write_orchard_swap_bundle<W: Write>(
484-
mut writer: W,
485-
bundle: &SwapBundle<ZatBalance>,
486-
) -> io::Result<()> {
487-
CompactSize::write(&mut writer, bundle.action_groups().len())?;
488-
bundle
489-
.action_groups()
490-
.into_iter()
491-
.for_each(|ag| write_action_group(&mut writer, ag).unwrap());
492-
write_bundle_balance_metadata(
493-
&mut writer,
494-
bundle.value_balance(),
495-
bundle.binding_signature(),
496-
)?;
497-
Ok(())
498-
}
499-
500-
#[cfg(zcash_unstable = "nu7")]
501-
fn write_action_group<W: Write, A: Authorization<SpendAuth = VerSpendAuthSig>>(
502-
mut writer: W,
503-
bundle: &orchard::Bundle<A, ZatBalance, OrchardZSA>,
504-
) -> io::Result<()> {
505-
Vector::write_nonempty(&mut writer, bundle.actions(), |w, a| {
506-
write_action_without_auth(w, a)
507-
})?;
500+
#[cfg(zcash_unstable = "nu7")]
501+
fn write_action_group<W: Write, A: Authorization<SpendAuth = VerSpendAuthSig>>(
502+
mut writer: W,
503+
bundle: &orchard::Bundle<A, ZatBalance, OrchardZSA>,
504+
) -> io::Result<()> {
505+
Vector::write_nonempty(&mut writer, bundle.actions(), |w, a| {
506+
write_action_without_auth(w, a)
507+
})?;
508508

509-
writer.write_all(&[bundle.flags().to_byte()])?;
510-
writer.write_all(&bundle.anchor().to_bytes())?;
509+
writer.write_all(&[bundle.flags().to_byte()])?;
510+
writer.write_all(&bundle.anchor().to_bytes())?;
511511

512-
// Timelimit must be zero for NU7
513-
writer.write_u32_le(bundle.expiry_height())?;
512+
// Timelimit must be zero for NU7
513+
writer.write_u32_le(bundle.expiry_height())?;
514514

515-
write_burn(&mut writer, bundle.burn())?;
515+
write_burn(&mut writer, bundle.burn())?;
516516

517-
Vector::write(
518-
&mut writer,
519-
bundle.authorization().proof().unwrap().as_ref(),
520-
|w, b| w.write_u8(*b),
521-
)?;
522-
Array::write(
523-
&mut writer,
524-
bundle.actions().iter().map(|a| a.authorization()),
525-
|w, auth| write_versioned_signature(w, auth),
526-
)?;
517+
Vector::write(
518+
&mut writer,
519+
bundle.authorization().proof().unwrap().as_ref(),
520+
|w, b| w.write_u8(*b),
521+
)?;
522+
Array::write(
523+
&mut writer,
524+
bundle.actions().iter().map(|a| a.authorization()),
525+
|w, auth| write_versioned_signature(w, auth),
526+
)?;
527527

528-
Ok(())
529-
}
528+
Ok(())
529+
}
530530

531531
#[cfg(zcash_unstable = "nu7")]
532532
fn write_bundle_balance_metadata<W: Write>(

0 commit comments

Comments
 (0)