2222
2323use bitcoin:: blockdata:: block:: Header ;
2424use bitcoin:: blockdata:: transaction:: { OutPoint as BitcoinOutPoint , TxOut , Transaction } ;
25- use bitcoin:: blockdata:: script:: Script ;
25+ use bitcoin:: blockdata:: script:: { Script , ScriptBuf } ;
2626
2727use bitcoin:: hashes:: Hash ;
2828use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
@@ -517,7 +517,7 @@ pub(crate) enum ChannelMonitorUpdateStep {
517517 should_broadcast : bool ,
518518 } ,
519519 ShutdownScript {
520- scriptpubkey : Script ,
520+ scriptpubkey : ScriptBuf ,
521521 } ,
522522}
523523
@@ -751,19 +751,19 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
751751 latest_update_id : u64 ,
752752 commitment_transaction_number_obscure_factor : u64 ,
753753
754- destination_script : Script ,
755- broadcasted_holder_revokable_script : Option < ( Script , PublicKey , PublicKey ) > ,
756- counterparty_payment_script : Script ,
757- shutdown_script : Option < Script > ,
754+ destination_script : ScriptBuf ,
755+ broadcasted_holder_revokable_script : Option < ( ScriptBuf , PublicKey , PublicKey ) > ,
756+ counterparty_payment_script : ScriptBuf ,
757+ shutdown_script : Option < ScriptBuf > ,
758758
759759 channel_keys_id : [ u8 ; 32 ] ,
760760 holder_revocation_basepoint : PublicKey ,
761- funding_info : ( OutPoint , Script ) ,
761+ funding_info : ( OutPoint , ScriptBuf ) ,
762762 current_counterparty_commitment_txid : Option < Txid > ,
763763 prev_counterparty_commitment_txid : Option < Txid > ,
764764
765765 counterparty_commitment_params : CounterpartyCommitmentParameters ,
766- funding_redeemscript : Script ,
766+ funding_redeemscript : ScriptBuf ,
767767 channel_value_satoshis : u64 ,
768768 // first is the idx of the first of the two per-commitment points
769769 their_cur_per_commitment_points : Option < ( u64 , PublicKey , Option < PublicKey > ) > ,
@@ -832,7 +832,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
832832 // interface knows about the TXOs that we want to be notified of spends of. We could probably
833833 // be smart and derive them from the above storage fields, but its much simpler and more
834834 // Obviously Correct (tm) if we just keep track of them explicitly.
835- outputs_to_watch : HashMap < Txid , Vec < ( u32 , Script ) > > ,
835+ outputs_to_watch : HashMap < Txid , Vec < ( u32 , ScriptBuf ) > > ,
836836
837837 #[ cfg( test) ]
838838 pub onchain_tx_handler : OnchainTxHandler < Signer > ,
@@ -941,7 +941,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
941941 self . counterparty_payment_script . write ( writer) ?;
942942 match & self . shutdown_script {
943943 Some ( script) => script. write ( writer) ?,
944- None => Script :: new ( ) . write ( writer) ?,
944+ None => ScriptBuf :: new ( ) . write ( writer) ?,
945945 }
946946
947947 self . channel_keys_id . write ( writer) ?;
@@ -1133,10 +1133,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
11331133 ChannelMonitor { inner : Mutex :: new ( imp) }
11341134 }
11351135
1136- pub ( crate ) fn new ( secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < Script > ,
1137- on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , Script ) ,
1136+ pub ( crate ) fn new ( secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
1137+ on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , ScriptBuf ) ,
11381138 channel_parameters : & ChannelTransactionParameters ,
1139- funding_redeemscript : Script , channel_value_satoshis : u64 ,
1139+ funding_redeemscript : ScriptBuf , channel_value_satoshis : u64 ,
11401140 commitment_transaction_number_obscure_factor : u64 ,
11411141 initial_holder_commitment_tx : HolderCommitmentTransaction ,
11421142 best_block : BestBlock , counterparty_node_id : PublicKey ) -> ChannelMonitor < Signer > {
@@ -1175,7 +1175,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
11751175 } ;
11761176
11771177 let onchain_tx_handler = OnchainTxHandler :: new (
1178- channel_value_satoshis, channel_keys_id, destination_script. clone ( ) , keys,
1178+ channel_value_satoshis, channel_keys_id, destination_script. into ( ) , keys,
11791179 channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx
11801180 ) ;
11811181
@@ -1186,7 +1186,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
11861186 latest_update_id : 0 ,
11871187 commitment_transaction_number_obscure_factor,
11881188
1189- destination_script : destination_script. clone ( ) ,
1189+ destination_script : destination_script. into ( ) ,
11901190 broadcasted_holder_revokable_script : None ,
11911191 counterparty_payment_script,
11921192 shutdown_script,
@@ -1332,13 +1332,13 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13321332 }
13331333
13341334 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
1335- pub fn get_funding_txo ( & self ) -> ( OutPoint , Script ) {
1335+ pub fn get_funding_txo ( & self ) -> ( OutPoint , ScriptBuf ) {
13361336 self . inner . lock ( ) . unwrap ( ) . get_funding_txo ( ) . clone ( )
13371337 }
13381338
13391339 /// Gets a list of txids, with their output scripts (in the order they appear in the
13401340 /// transaction), which we must learn about spends of via block_connected().
1341- pub fn get_outputs_to_watch ( & self ) -> Vec < ( Txid , Vec < ( u32 , Script ) > ) > {
1341+ pub fn get_outputs_to_watch ( & self ) -> Vec < ( Txid , Vec < ( u32 , ScriptBuf ) > ) > {
13421342 self . inner . lock ( ) . unwrap ( ) . get_outputs_to_watch ( )
13431343 . iter ( ) . map ( |( txid, outputs) | ( * txid, outputs. clone ( ) ) ) . collect ( )
13441344 }
@@ -1707,12 +1707,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
17071707 }
17081708
17091709 #[ cfg( test) ]
1710- pub fn get_counterparty_payment_script ( & self ) -> Script {
1710+ pub fn get_counterparty_payment_script ( & self ) -> ScriptBuf {
17111711 self . inner . lock ( ) . unwrap ( ) . counterparty_payment_script . clone ( )
17121712 }
17131713
17141714 #[ cfg( test) ]
1715- pub fn set_counterparty_payment_script ( & self , script : Script ) {
1715+ pub fn set_counterparty_payment_script ( & self , script : ScriptBuf ) {
17161716 self . inner . lock ( ) . unwrap ( ) . counterparty_payment_script = script;
17171717 }
17181718}
@@ -2767,11 +2767,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
27672767 self . latest_update_id
27682768 }
27692769
2770- pub fn get_funding_txo ( & self ) -> & ( OutPoint , Script ) {
2770+ pub fn get_funding_txo ( & self ) -> & ( OutPoint , ScriptBuf ) {
27712771 & self . funding_info
27722772 }
27732773
2774- pub fn get_outputs_to_watch ( & self ) -> & HashMap < Txid , Vec < ( u32 , Script ) > > {
2774+ pub fn get_outputs_to_watch ( & self ) -> & HashMap < Txid , Vec < ( u32 , ScriptBuf ) > > {
27752775 // If we've detected a counterparty commitment tx on chain, we must include it in the set
27762776 // of outputs to watch for spends of, otherwise we're likely to lose user funds. Because
27772777 // its trivial to do, double-check that here.
@@ -3204,7 +3204,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32043204 // Returns (1) `PackageTemplate`s that can be given to the OnchainTxHandler, so that the handler can
32053205 // broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable
32063206 // script so we can detect whether a holder transaction has been seen on-chain.
3207- fn get_broadcasted_holder_claims ( & self , holder_tx : & HolderSignedTx , conf_height : u32 ) -> ( Vec < PackageTemplate > , Option < ( Script , PublicKey , PublicKey ) > ) {
3207+ fn get_broadcasted_holder_claims ( & self , holder_tx : & HolderSignedTx , conf_height : u32 ) -> ( Vec < PackageTemplate > , Option < ( ScriptBuf , PublicKey , PublicKey ) > ) {
32083208 let mut claim_requests = Vec :: with_capacity ( holder_tx. htlc_outputs . len ( ) ) ;
32093209
32103210 let redeemscript = chan_utils:: get_revokeable_redeemscript ( & holder_tx. revocation_key , self . on_holder_tx_csv , & holder_tx. delayed_payment_key ) ;
@@ -3792,7 +3792,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37923792 return true ;
37933793 }
37943794
3795- assert_eq ! ( & bitcoin:: Address :: p2wsh( & Script :: from( input. witness. last( ) . unwrap( ) . to_vec( ) ) , bitcoin:: Network :: Bitcoin ) . script_pubkey( ) , _script_pubkey) ;
3795+ assert_eq ! ( & bitcoin:: Address :: p2wsh( & ScriptBuf :: from( input. witness. last( ) . unwrap( ) . to_vec( ) ) , bitcoin:: Network :: Bitcoin ) . script_pubkey( ) , _script_pubkey) ;
37963796 } else if _script_pubkey. is_v0_p2wpkh ( ) {
37973797 assert_eq ! ( & bitcoin:: Address :: p2wpkh( & bitcoin:: PublicKey :: from_slice( & input. witness. last( ) . unwrap( ) ) . unwrap( ) , bitcoin:: Network :: Bitcoin ) . unwrap( ) . script_pubkey( ) , _script_pubkey) ;
37983798 } else { panic ! ( ) ; }
@@ -4208,9 +4208,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
42084208 1 => { None } ,
42094209 _ => return Err ( DecodeError :: InvalidValue ) ,
42104210 } ;
4211- let mut counterparty_payment_script: Script = Readable :: read ( reader) ?;
4211+ let mut counterparty_payment_script: ScriptBuf = Readable :: read ( reader) ?;
42124212 let shutdown_script = {
4213- let script = <Script as Readable >:: read ( reader) ?;
4213+ let script = <ScriptBuf as Readable >:: read ( reader) ?;
42144214 if script. is_empty ( ) { None } else { Some ( script) }
42154215 } ;
42164216
@@ -4353,11 +4353,11 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
43534353 }
43544354
43554355 let outputs_to_watch_len: u64 = Readable :: read ( reader) ?;
4356- let mut outputs_to_watch = HashMap :: with_capacity ( cmp:: min ( outputs_to_watch_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < Txid > ( ) + mem:: size_of :: < u32 > ( ) + mem:: size_of :: < Vec < Script > > ( ) ) ) ) ;
4356+ let mut outputs_to_watch = HashMap :: with_capacity ( cmp:: min ( outputs_to_watch_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < Txid > ( ) + mem:: size_of :: < u32 > ( ) + mem:: size_of :: < Vec < ScriptBuf > > ( ) ) ) ) ;
43574357 for _ in 0 ..outputs_to_watch_len {
43584358 let txid = Readable :: read ( reader) ?;
43594359 let outputs_len: u64 = Readable :: read ( reader) ?;
4360- let mut outputs = Vec :: with_capacity ( cmp:: min ( outputs_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < u32 > ( ) + mem:: size_of :: < Script > ( ) ) ) ) ;
4360+ let mut outputs = Vec :: with_capacity ( cmp:: min ( outputs_len as usize , MAX_ALLOC_SIZE / ( mem:: size_of :: < u32 > ( ) + mem:: size_of :: < ScriptBuf > ( ) ) ) ) ;
43614361 for _ in 0 ..outputs_len {
43624362 outputs. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
43634363 }
@@ -4481,7 +4481,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
44814481#[ cfg( test) ]
44824482mod tests {
44834483 use bitcoin:: blockdata:: locktime:: absolute:: LockTime ;
4484- use bitcoin:: blockdata:: script:: { Script , Builder } ;
4484+ use bitcoin:: blockdata:: script:: { ScriptBuf , Builder } ;
44854485 use bitcoin:: blockdata:: opcodes;
44864486 use bitcoin:: blockdata:: transaction:: { Transaction , TxIn , TxOut } ;
44874487 use bitcoin:: blockdata:: transaction:: OutPoint as BitcoinOutPoint ;
@@ -4696,9 +4696,9 @@ mod tests {
46964696 let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
46974697 let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
46984698 let monitor = ChannelMonitor :: new ( Secp256k1 :: new ( ) , keys,
4699- Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & Script :: new ( ) ,
4700- ( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , Script :: new ( ) ) ,
4701- & channel_parameters, Script :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
4699+ Some ( ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) . into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
4700+ ( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , ScriptBuf :: new ( ) ) ,
4701+ & channel_parameters, ScriptBuf :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( & mut Vec :: new ( ) ) ,
47024702 best_block, dummy_key) ;
47034703
47044704 let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -4814,7 +4814,7 @@ mod tests {
48144814 txid,
48154815 vout : i,
48164816 } ,
4817- script_sig : Script :: new ( ) ,
4817+ script_sig : ScriptBuf :: new ( ) ,
48184818 sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
48194819 witness : Witness :: new ( ) ,
48204820 } ) ;
@@ -4846,7 +4846,7 @@ mod tests {
48464846 txid,
48474847 vout : i,
48484848 } ,
4849- script_sig : Script :: new ( ) ,
4849+ script_sig : ScriptBuf :: new ( ) ,
48504850 sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
48514851 witness : Witness :: new ( ) ,
48524852 } ) ;
@@ -4877,7 +4877,7 @@ mod tests {
48774877 txid,
48784878 vout : 0 ,
48794879 } ,
4880- script_sig : Script :: new ( ) ,
4880+ script_sig : ScriptBuf :: new ( ) ,
48814881 sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
48824882 witness : Witness :: new ( ) ,
48834883 } ) ;
0 commit comments