@@ -16,11 +16,11 @@ use core2::io::{self, Read, Write};
1616use nonempty:: NonEmpty ;
1717use 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
3030use zcash_protocol:: value:: ZatBalance ;
3131
32+ #[ cfg( zcash_unstable = "nu7" ) ]
33+ use orchard:: orchard_sighash_versioning:: VerSpendAuthSig ;
3234#[ cfg( zcash_unstable = "nu7" /* TODO swap */ ) ]
3335use 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
4040pub const FLAG_SPENDS_ENABLED : u8 = 0b0000_0001 ;
4141pub 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" ) ]
445446fn 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" ) ]
532532fn write_bundle_balance_metadata < W : Write > (
0 commit comments