@@ -88,8 +88,8 @@ use dashcore::secp256k1::Secp256k1;
8888use dashcore:: sighash:: { self , SighashCache , TapSighash , TapSighashType } ;
8989use dashcore:: taproot:: { self , LeafVersion , TapLeafHash , TaprootBuilder , TaprootSpendInfo } ;
9090use dashcore:: {
91- Address , Amount , Network , OutPoint , ScriptBuf , Transaction , TxIn , TxOut , Witness , absolute ,
92- script ,
91+ absolute , script , Address , Amount , Network , OutPoint , ScriptBuf , Transaction , TxIn , TxOut ,
92+ Witness ,
9393} ;
9494
9595fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -119,8 +119,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
119119 // Set these fields with valid data for the UTXO from step 5 above
120120 UTXO_1 ,
121121 vec ! [
122- TxOut { value: amount_to_send_in_sats, script_pubkey: to_address. script_pubkey( ) } ,
123- TxOut { value: change_amount, script_pubkey: change_address. script_pubkey( ) } ,
122+ TxOut {
123+ value: amount_to_send_in_sats,
124+ script_pubkey: to_address. script_pubkey( ) ,
125+ } ,
126+ TxOut {
127+ value: change_amount,
128+ script_pubkey: change_address. script_pubkey( ) ,
129+ } ,
124130 ] ,
125131 ) ?) ;
126132 println ! (
@@ -234,7 +240,10 @@ fn generate_bip86_key_spend_tx(
234240 version : 2 ,
235241 lock_time : 0 ,
236242 input : vec ! [ TxIn {
237- previous_output: OutPoint { txid: input_utxo. txid. parse( ) ?, vout: input_utxo. vout } ,
243+ previous_output: OutPoint {
244+ txid: input_utxo. txid. parse( ) ?,
245+ vout: input_utxo. vout,
246+ } ,
238247 script_sig: ScriptBuf :: new( ) ,
239248 sequence: 0xFFFFFFFF , // Ignore nSequence.
240249 witness: Witness :: default ( ) ,
@@ -262,7 +271,10 @@ fn generate_bip86_key_spend_tx(
262271 . expect ( "failed to parse input utxo scriptPubkey" ) ;
263272 let amount = Amount :: from_sat ( from_amount) ;
264273
265- Some ( TxOut { value : amount. to_sat ( ) , script_pubkey } )
274+ Some ( TxOut {
275+ value : amount. to_sat ( ) ,
276+ script_pubkey,
277+ } )
266278 } ,
267279 tap_key_origins : origins,
268280 ..Default :: default ( )
@@ -380,7 +392,10 @@ impl BenefactorWallet {
380392 lock_time : absolute:: LockTime ,
381393 input_utxo : P2trUtxo ,
382394 ) -> Result < ( Transaction , Psbt ) , Box < dyn std:: error:: Error > > {
383- if let ChildNumber :: Normal { index } = self . next {
395+ if let ChildNumber :: Normal {
396+ index,
397+ } = self . next
398+ {
384399 if index > 0 && self . current_spend_info . is_some ( ) {
385400 return Err ( "Transaction already exists, use refresh_inheritance_timelock to refresh the timelock" . into ( ) ) ;
386401 }
@@ -414,15 +429,21 @@ impl BenefactorWallet {
414429 & self . secp ,
415430 self . master_xpriv ,
416431 input_utxo,
417- vec ! [ TxOut { script_pubkey: script_pubkey. clone( ) , value } ] ,
432+ vec ! [ TxOut {
433+ script_pubkey: script_pubkey. clone( ) ,
434+ value,
435+ } ] ,
418436 ) ?;
419437
420438 // CREATOR + UPDATER
421439 let next_tx = Transaction {
422440 version : 2 ,
423441 lock_time : lock_time. to_consensus_u32 ( ) ,
424442 input : vec ! [ TxIn {
425- previous_output: OutPoint { txid: tx. txid( ) , vout: 0 } ,
443+ previous_output: OutPoint {
444+ txid: tx. txid( ) ,
445+ vout: 0 ,
446+ } ,
426447 script_sig: ScriptBuf :: new( ) ,
427448 sequence: 0xFFFFFFFD , // enable locktime and opt-in RBF
428449 witness: Witness :: default ( ) ,
@@ -452,7 +473,10 @@ impl BenefactorWallet {
452473 let script_pubkey = script_pubkey;
453474 let amount = Amount :: from_sat ( value) ;
454475
455- Some ( TxOut { value : amount. to_sat ( ) , script_pubkey } )
476+ Some ( TxOut {
477+ value : amount. to_sat ( ) ,
478+ script_pubkey,
479+ } )
456480 } ,
457481 tap_key_origins : origins,
458482 tap_merkle_root : taproot_spend_info. merkle_root ( ) ,
@@ -509,8 +533,10 @@ impl BenefactorWallet {
509533 taproot_spend_info. merkle_root ( ) ,
510534 ) ;
511535
512- psbt. unsigned_tx . output =
513- vec ! [ TxOut { script_pubkey: output_script_pubkey. clone( ) , value: output_value } ] ;
536+ psbt. unsigned_tx . output = vec ! [ TxOut {
537+ script_pubkey: output_script_pubkey. clone( ) ,
538+ value: output_value,
539+ } ] ;
514540 psbt. outputs = vec ! [ Output :: default ( ) ] ;
515541 psbt. unsigned_tx . lock_time = 0 ;
516542
@@ -562,15 +588,21 @@ impl BenefactorWallet {
562588 // EXTRACTOR
563589 let tx = psbt. extract_tx ( ) ;
564590 tx. verify ( |_| {
565- Some ( TxOut { value : input_value, script_pubkey : output_script_pubkey. clone ( ) } )
591+ Some ( TxOut {
592+ value : input_value,
593+ script_pubkey : output_script_pubkey. clone ( ) ,
594+ } )
566595 } )
567596 . expect ( "failed to verify transaction" ) ;
568597
569598 let next_tx = Transaction {
570599 version : 2 ,
571600 lock_time : lock_time. to_consensus_u32 ( ) ,
572601 input : vec ! [ TxIn {
573- previous_output: OutPoint { txid: tx. txid( ) , vout: 0 } ,
602+ previous_output: OutPoint {
603+ txid: tx. txid( ) ,
604+ vout: 0 ,
605+ } ,
574606 script_sig: ScriptBuf :: new( ) ,
575607 sequence: 0xFFFFFFFD , // enable locktime and opt-in RBF
576608 witness: Witness :: default ( ) ,
@@ -598,7 +630,10 @@ impl BenefactorWallet {
598630 let script_pubkey = output_script_pubkey;
599631 let amount = Amount :: from_sat ( output_value) ;
600632
601- Some ( TxOut { value : amount. to_sat ( ) , script_pubkey } )
633+ Some ( TxOut {
634+ value : amount. to_sat ( ) ,
635+ script_pubkey,
636+ } )
602637 } ,
603638 tap_key_origins : origins,
604639 tap_merkle_root : taproot_spend_info. merkle_root ( ) ,
@@ -628,7 +663,10 @@ struct BeneficiaryWallet {
628663
629664impl BeneficiaryWallet {
630665 fn new ( master_xpriv : ExtendedPrivKey ) -> Result < Self , Box < dyn std:: error:: Error > > {
631- Ok ( Self { master_xpriv, secp : Secp256k1 :: new ( ) } )
666+ Ok ( Self {
667+ master_xpriv,
668+ secp : Secp256k1 :: new ( ) ,
669+ } )
632670 }
633671
634672 fn master_xpub ( & self ) -> ExtendedPubKey {
@@ -707,7 +745,10 @@ impl BeneficiaryWallet {
707745 // EXTRACTOR
708746 let tx = psbt. extract_tx ( ) ;
709747 tx. verify ( |_| {
710- Some ( TxOut { value : input_value, script_pubkey : input_script_pubkey. clone ( ) } )
748+ Some ( TxOut {
749+ value : input_value,
750+ script_pubkey : input_script_pubkey. clone ( ) ,
751+ } )
711752 } )
712753 . expect ( "failed to verify transaction" ) ;
713754
@@ -746,7 +787,10 @@ fn sign_psbt_taproot(
746787
747788 let sig = secp. sign_schnorr ( & hash. into ( ) , & keypair) ;
748789
749- let final_signature = taproot:: Signature { sig, hash_ty } ;
790+ let final_signature = taproot:: Signature {
791+ sig,
792+ hash_ty,
793+ } ;
750794
751795 if let Some ( lh) = leaf_hash {
752796 psbt_input. tap_script_sigs . insert ( ( pubkey, lh) , final_signature) ;
0 commit comments