@@ -76,6 +76,30 @@ pub struct AnchorDescriptor {
76
76
}
77
77
78
78
impl 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
+
79
103
/// Derives the channel signer required to sign the anchor input.
80
104
pub fn derive_channel_signer < SP : Deref > ( & self , signer_provider : & SP ) -> <SP :: Target as SignerProvider >:: Signer
81
105
where
@@ -646,12 +670,7 @@ where
646
670
let mut tx = Transaction {
647
671
version : 2 ,
648
672
lock_time : PackedLockTime :: ZERO , // TODO: Use next best height.
649
- input : vec ! [ TxIn {
650
- previous_output: anchor_descriptor. outpoint,
651
- script_sig: Script :: new( ) ,
652
- sequence: Sequence :: ZERO ,
653
- witness: Witness :: new( ) ,
654
- } ] ,
673
+ input : vec ! [ anchor_descriptor. unsigned_tx_input( ) ] ,
655
674
output : vec ! [ ] ,
656
675
} ;
657
676
self . process_coin_selection ( & mut tx, coin_selection) ;
@@ -685,8 +704,7 @@ where
685
704
self . utxo_source . sign_tx ( & mut anchor_tx) ?;
686
705
let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
687
706
let anchor_sig = signer. sign_holder_anchor_input ( & anchor_tx, 0 , & self . secp ) ?;
688
- anchor_tx. input [ 0 ] . witness =
689
- chan_utils:: build_anchor_input_witness ( & signer. pubkeys ( ) . funding_pubkey , & anchor_sig) ;
707
+ anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
690
708
691
709
self . broadcaster . broadcast_transactions ( & [ & commitment_tx, & anchor_tx] ) ;
692
710
Ok ( ( ) )
0 commit comments