@@ -76,6 +76,30 @@ pub struct AnchorDescriptor {
7676}
7777
7878impl AnchorDescriptor {
79+ /// Returns the unsigned transaction input spending the anchor output in the commitment
80+ /// transaction.
81+ pub fn unsigned_tx_input ( & self ) -> TxIn {
82+ TxIn {
83+ previous_output : self . outpoint . clone ( ) ,
84+ script_sig : Script :: new ( ) ,
85+ sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
86+ witness : Witness :: new ( ) ,
87+ }
88+ }
89+
90+ /// Returns the witness script of the anchor output in the commitment transaction.
91+ pub fn witness_script ( & self ) -> Script {
92+ let channel_params = self . channel_derivation_parameters . transaction_parameters . as_holder_broadcastable ( ) ;
93+ chan_utils:: get_anchor_redeemscript ( & channel_params. broadcaster_pubkeys ( ) . funding_pubkey )
94+ }
95+
96+ /// Returns the fully signed witness required to spend the anchor output in the commitment
97+ /// transaction.
98+ pub fn tx_input_witness ( & self , signature : & Signature ) -> Witness {
99+ let channel_params = self . channel_derivation_parameters . transaction_parameters . as_holder_broadcastable ( ) ;
100+ chan_utils:: build_anchor_input_witness ( & channel_params. broadcaster_pubkeys ( ) . funding_pubkey , signature)
101+ }
102+
79103 /// Derives the channel signer required to sign the anchor input.
80104 pub fn derive_channel_signer < SP : Deref > ( & self , signer_provider : & SP ) -> <SP :: Target as SignerProvider >:: Signer
81105 where
@@ -649,12 +673,7 @@ where
649673 let mut tx = Transaction {
650674 version : 2 ,
651675 lock_time : PackedLockTime :: ZERO , // TODO: Use next best height.
652- input : vec ! [ TxIn {
653- previous_output: anchor_descriptor. outpoint,
654- script_sig: Script :: new( ) ,
655- sequence: Sequence :: ZERO ,
656- witness: Witness :: new( ) ,
657- } ] ,
676+ input : vec ! [ anchor_descriptor. unsigned_tx_input( ) ] ,
658677 output : vec ! [ ] ,
659678 } ;
660679 self . process_coin_selection ( & mut tx, coin_selection) ;
@@ -688,8 +707,7 @@ where
688707 self . utxo_source . sign_tx ( & mut anchor_tx) ?;
689708 let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
690709 let anchor_sig = signer. sign_holder_anchor_input ( & anchor_tx, 0 , & self . secp ) ?;
691- anchor_tx. input [ 0 ] . witness =
692- chan_utils:: build_anchor_input_witness ( & signer. pubkeys ( ) . funding_pubkey , & anchor_sig) ;
710+ anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
693711
694712 self . broadcaster . broadcast_transactions ( & [ & commitment_tx, & anchor_tx] ) ;
695713 Ok ( ( ) )
0 commit comments