@@ -135,31 +135,31 @@ impl Script {
135
135
}
136
136
}
137
137
138
- mod tmp_pub {
139
- use super :: * ;
140
- impl Script {
138
+ crate :: internal_macros :: define_extension_trait! {
139
+ /// Extension functionality for the [`Script`] type.
140
+ pub trait ScriptExt impl for Script {
141
141
/// Returns an iterator over script bytes.
142
142
#[ inline]
143
- pub fn bytes ( & self ) -> Bytes < ' _ > { Bytes ( self . as_bytes ( ) . iter ( ) . copied ( ) ) }
143
+ fn bytes( & self ) -> Bytes <' _> { Bytes ( self . as_bytes( ) . iter( ) . copied( ) ) }
144
144
145
145
/// Creates a new script builder
146
- pub fn builder ( ) -> Builder { Builder :: new ( ) }
146
+ fn builder( ) -> Builder { Builder :: new( ) }
147
147
148
148
/// Returns 160-bit hash of the script for P2SH outputs.
149
149
#[ inline]
150
- pub fn script_hash ( & self ) -> Result < ScriptHash , RedeemScriptSizeError > {
150
+ fn script_hash( & self ) -> Result <ScriptHash , RedeemScriptSizeError > {
151
151
ScriptHash :: from_script( self )
152
152
}
153
153
154
154
/// Returns 256-bit hash of the script for P2WSH outputs.
155
155
#[ inline]
156
- pub fn wscript_hash ( & self ) -> Result < WScriptHash , WitnessScriptSizeError > {
156
+ fn wscript_hash( & self ) -> Result <WScriptHash , WitnessScriptSizeError > {
157
157
WScriptHash :: from_script( self )
158
158
}
159
159
160
160
/// Computes leaf hash of tapscript.
161
161
#[ inline]
162
- pub fn tapscript_leaf_hash ( & self ) -> TapLeafHash {
162
+ fn tapscript_leaf_hash( & self ) -> TapLeafHash {
163
163
TapLeafHash :: from_script( self , LeafVersion :: TapScript )
164
164
}
165
165
@@ -174,7 +174,7 @@ mod tmp_pub {
174
174
/// > special meaning. The value of the first push is called the "version byte". The following
175
175
/// > byte vector pushed is called the "witness program".
176
176
#[ inline]
177
- pub fn witness_version ( & self ) -> Option < WitnessVersion > {
177
+ fn witness_version( & self ) -> Option <WitnessVersion > {
178
178
let script_len = self . 0 . len( ) ;
179
179
if !( 4 ..=42 ) . contains( & script_len) {
180
180
return None ;
@@ -196,7 +196,7 @@ mod tmp_pub {
196
196
197
197
/// Checks whether a script pubkey is a P2SH output.
198
198
#[ inline]
199
- pub fn is_p2sh ( & self ) -> bool {
199
+ fn is_p2sh( & self ) -> bool {
200
200
self . 0 . len( ) == 23
201
201
&& self . 0 [ 0 ] == OP_HASH160 . to_u8( )
202
202
&& self . 0 [ 1 ] == OP_PUSHBYTES_20 . to_u8( )
@@ -205,7 +205,7 @@ mod tmp_pub {
205
205
206
206
/// Checks whether a script pubkey is a P2PKH output.
207
207
#[ inline]
208
- pub fn is_p2pkh ( & self ) -> bool {
208
+ fn is_p2pkh( & self ) -> bool {
209
209
self . 0 . len( ) == 25
210
210
&& self . 0 [ 0 ] == OP_DUP . to_u8( )
211
211
&& self . 0 [ 1 ] == OP_HASH160 . to_u8( )
@@ -219,7 +219,7 @@ mod tmp_pub {
219
219
/// Note: `OP_RESERVED` (`0x50`) and all the OP_PUSHNUM operations
220
220
/// are considered push operations.
221
221
#[ inline]
222
- pub fn is_push_only ( & self ) -> bool {
222
+ fn is_push_only( & self ) -> bool {
223
223
for inst in self . instructions( ) {
224
224
match inst {
225
225
Err ( _) => return false ,
@@ -240,7 +240,7 @@ mod tmp_pub {
240
240
///
241
241
/// `2 <pubkey1> <pubkey2> <pubkey3> 3 OP_CHECKMULTISIG`
242
242
#[ inline]
243
- pub fn is_multisig ( & self ) -> bool {
243
+ fn is_multisig( & self ) -> bool {
244
244
let required_sigs;
245
245
246
246
let mut instructions = self . instructions( ) ;
@@ -288,27 +288,27 @@ mod tmp_pub {
288
288
289
289
/// Checks whether a script pubkey is a Segregated Witness (segwit) program.
290
290
#[ inline]
291
- pub fn is_witness_program ( & self ) -> bool { self . witness_version ( ) . is_some ( ) }
291
+ fn is_witness_program( & self ) -> bool { self . witness_version( ) . is_some( ) }
292
292
293
293
/// Checks whether a script pubkey is a P2WSH output.
294
294
#[ inline]
295
- pub fn is_p2wsh ( & self ) -> bool {
295
+ fn is_p2wsh( & self ) -> bool {
296
296
self . 0 . len( ) == 34
297
297
&& self . witness_version( ) == Some ( WitnessVersion :: V0 )
298
298
&& self . 0 [ 1 ] == OP_PUSHBYTES_32 . to_u8( )
299
299
}
300
300
301
301
/// Checks whether a script pubkey is a P2WPKH output.
302
302
#[ inline]
303
- pub fn is_p2wpkh ( & self ) -> bool {
303
+ fn is_p2wpkh( & self ) -> bool {
304
304
self . 0 . len( ) == 22
305
305
&& self . witness_version( ) == Some ( WitnessVersion :: V0 )
306
306
&& self . 0 [ 1 ] == OP_PUSHBYTES_20 . to_u8( )
307
307
}
308
308
309
309
/// Checks whether a script pubkey is a P2TR output.
310
310
#[ inline]
311
- pub fn is_p2tr ( & self ) -> bool {
311
+ fn is_p2tr( & self ) -> bool {
312
312
self . 0 . len( ) == 34
313
313
&& self . witness_version( ) == Some ( WitnessVersion :: V1 )
314
314
&& self . 0 [ 1 ] == OP_PUSHBYTES_32 . to_u8( )
@@ -319,7 +319,7 @@ mod tmp_pub {
319
319
/// To validate if the OP_RETURN obeys Bitcoin Core's current standardness policy, use
320
320
/// [`is_standard_op_return()`](Self::is_standard_op_return) instead.
321
321
#[ inline]
322
- pub fn is_op_return ( & self ) -> bool {
322
+ fn is_op_return( & self ) -> bool {
323
323
match self . 0 . first( ) {
324
324
Some ( b) => * b == OP_RETURN . to_u8( ) ,
325
325
None => false ,
@@ -331,7 +331,7 @@ mod tmp_pub {
331
331
/// What this function considers to be standard may change without warning pending Bitcoin Core
332
332
/// changes.
333
333
#[ inline]
334
- pub fn is_standard_op_return ( & self ) -> bool { self . is_op_return ( ) && self . 0 . len ( ) <= 80 }
334
+ fn is_standard_op_return( & self ) -> bool { self . is_op_return( ) && self . 0 . len( ) <= 80 }
335
335
336
336
/// Checks whether a script is trivially known to have no satisfying input.
337
337
///
@@ -342,7 +342,7 @@ mod tmp_pub {
342
342
note = "The method has potentially confusing semantics and is going to be removed, you might want `is_op_return`"
343
343
) ]
344
344
#[ inline]
345
- pub fn is_provably_unspendable ( & self ) -> bool {
345
+ fn is_provably_unspendable( & self ) -> bool {
346
346
use crate :: opcodes:: Class :: { IllegalOp , ReturnOp } ;
347
347
348
348
match self . 0 . first( ) {
@@ -362,7 +362,7 @@ mod tmp_pub {
362
362
/// It merely gets the last push of the script.
363
363
///
364
364
/// Use [`Script::is_p2sh`] on the scriptPubKey to check whether it is actually a P2SH script.
365
- pub fn redeem_script ( & self ) -> Option < & Script > {
365
+ fn redeem_script( & self ) -> Option <& Script > {
366
366
// Script must consist entirely of pushes.
367
367
if self . instructions( ) . any( |i| i. is_err( ) || i. unwrap( ) . push_bytes( ) . is_none( ) ) {
368
368
return None ;
@@ -378,7 +378,7 @@ mod tmp_pub {
378
378
/// Returns the minimum value an output with this script should have in order to be
379
379
/// broadcastable on today’s Bitcoin network.
380
380
#[ deprecated( since = "0.32.0" , note = "use minimal_non_dust and friends" ) ]
381
- pub fn dust_value ( & self ) -> crate :: Amount { self . minimal_non_dust ( ) }
381
+ fn dust_value( & self ) -> crate :: Amount { self . minimal_non_dust( ) }
382
382
383
383
/// Returns the minimum value an output with this script should have in order to be
384
384
/// broadcastable on today's Bitcoin network.
@@ -389,7 +389,7 @@ mod tmp_pub {
389
389
/// To use a custom value, use [`minimal_non_dust_custom`].
390
390
///
391
391
/// [`minimal_non_dust_custom`]: Script::minimal_non_dust_custom
392
- pub fn minimal_non_dust ( & self ) -> crate :: Amount {
392
+ fn minimal_non_dust( & self ) -> crate :: Amount {
393
393
self . minimal_non_dust_internal( DUST_RELAY_TX_FEE . into( ) )
394
394
}
395
395
@@ -404,7 +404,7 @@ mod tmp_pub {
404
404
/// To use the default Bitcoin Core value, use [`minimal_non_dust`].
405
405
///
406
406
/// [`minimal_non_dust`]: Script::minimal_non_dust
407
- pub fn minimal_non_dust_custom ( & self , dust_relay_fee : FeeRate ) -> crate :: Amount {
407
+ fn minimal_non_dust_custom( & self , dust_relay_fee: FeeRate ) -> crate :: Amount {
408
408
self . minimal_non_dust_internal( dust_relay_fee. to_sat_per_kwu( ) * 4 )
409
409
}
410
410
@@ -422,7 +422,7 @@ mod tmp_pub {
422
422
/// (Note: Taproot scripts don't count toward the sigop count of the block,
423
423
/// nor do they have CHECKMULTISIG operations. This function does not count OP_CHECKSIGADD,
424
424
/// so do not use this to try and estimate if a Taproot script goes over the sigop budget.)
425
- pub fn count_sigops ( & self ) -> usize { self . count_sigops_internal ( true ) }
425
+ fn count_sigops( & self ) -> usize { self . count_sigops_internal( true ) }
426
426
427
427
/// Counts the sigops for this Script using legacy counting.
428
428
///
@@ -436,7 +436,7 @@ mod tmp_pub {
436
436
/// (Note: Taproot scripts don't count toward the sigop count of the block,
437
437
/// nor do they have CHECKMULTISIG operations. This function does not count OP_CHECKSIGADD,
438
438
/// so do not use this to try and estimate if a Taproot script goes over the sigop budget.)
439
- pub fn count_sigops_legacy ( & self ) -> usize { self . count_sigops_internal ( false ) }
439
+ fn count_sigops_legacy( & self ) -> usize { self . count_sigops_internal( false ) }
440
440
441
441
/// Iterates over the script instructions.
442
442
///
@@ -446,7 +446,7 @@ mod tmp_pub {
446
446
///
447
447
/// To force minimal pushes, use [`instructions_minimal`](Self::instructions_minimal).
448
448
#[ inline]
449
- pub fn instructions ( & self ) -> Instructions {
449
+ fn instructions( & self ) -> Instructions {
450
450
Instructions { data: self . 0 . iter( ) , enforce_minimal: false }
451
451
}
452
452
@@ -455,7 +455,7 @@ mod tmp_pub {
455
455
/// This is similar to [`instructions`](Self::instructions) but an error is returned if a push
456
456
/// is not minimal.
457
457
#[ inline]
458
- pub fn instructions_minimal ( & self ) -> Instructions {
458
+ fn instructions_minimal( & self ) -> Instructions {
459
459
Instructions { data: self . 0 . iter( ) , enforce_minimal: true }
460
460
}
461
461
@@ -467,7 +467,7 @@ mod tmp_pub {
467
467
///
468
468
/// To force minimal pushes, use [`Self::instruction_indices_minimal`].
469
469
#[ inline]
470
- pub fn instruction_indices ( & self ) -> InstructionIndices {
470
+ fn instruction_indices( & self ) -> InstructionIndices {
471
471
InstructionIndices :: from_instructions( self . instructions( ) )
472
472
}
473
473
@@ -476,17 +476,17 @@ mod tmp_pub {
476
476
/// This is similar to [`instruction_indices`](Self::instruction_indices) but an error is
477
477
/// returned if a push is not minimal.
478
478
#[ inline]
479
- pub fn instruction_indices_minimal ( & self ) -> InstructionIndices {
479
+ fn instruction_indices_minimal( & self ) -> InstructionIndices {
480
480
InstructionIndices :: from_instructions( self . instructions_minimal( ) )
481
481
}
482
482
483
483
/// Writes the human-readable assembly representation of the script to the formatter.
484
- pub fn fmt_asm ( & self , f : & mut dyn fmt:: Write ) -> fmt:: Result {
484
+ fn fmt_asm( & self , f: & mut dyn fmt:: Write ) -> fmt:: Result {
485
485
bytes_to_asm_fmt( self . as_ref( ) , f)
486
486
}
487
487
488
488
/// Returns the human-readable assembly representation of the script.
489
- pub fn to_asm_string ( & self ) -> String {
489
+ fn to_asm_string( & self ) -> String {
490
490
let mut buf = String :: new( ) ;
491
491
self . fmt_asm( & mut buf) . unwrap( ) ;
492
492
buf
@@ -497,19 +497,18 @@ mod tmp_pub {
497
497
/// This is a more convenient and performant way to write `format!("{:x}", script)`.
498
498
/// For better performance you should generally prefer displaying the script but if `String` is
499
499
/// required (this is common in tests) this method can be used.
500
- pub fn to_hex_string ( & self ) -> String { self . as_bytes ( ) . to_lower_hex_string ( ) }
500
+ fn to_hex_string( & self ) -> String { self . as_bytes( ) . to_lower_hex_string( ) }
501
501
502
502
/// Returns the first opcode of the script (if there is any).
503
- pub fn first_opcode ( & self ) -> Option < Opcode > {
503
+ fn first_opcode( & self ) -> Option <Opcode > {
504
504
self . as_bytes( ) . first( ) . copied( ) . map( From :: from)
505
505
}
506
506
}
507
507
}
508
508
509
- mod tmp_priv {
510
- use super :: * ;
511
- impl Script {
512
- pub ( crate ) fn minimal_non_dust_internal ( & self , dust_relay_fee : u64 ) -> crate :: Amount {
509
+ crate :: internal_macros:: define_extension_trait! {
510
+ pub ( crate ) trait ScriptExtPriv impl for Script {
511
+ fn minimal_non_dust_internal( & self , dust_relay_fee: u64 ) -> crate :: Amount {
513
512
// This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may
514
513
// otherwise allow users to create transactions which likely can never be broadcast/confirmed.
515
514
let sats = dust_relay_fee
@@ -532,7 +531,7 @@ mod tmp_priv {
532
531
crate :: Amount :: from_sat( sats)
533
532
}
534
533
535
- pub ( crate ) fn count_sigops_internal ( & self , accurate : bool ) -> usize {
534
+ fn count_sigops_internal( & self , accurate: bool ) -> usize {
536
535
let mut n = 0 ;
537
536
let mut pushnum_cache = None ;
538
537
for inst in self . instructions( ) {
@@ -575,7 +574,7 @@ mod tmp_priv {
575
574
/// Iterates the script to find the last opcode.
576
575
///
577
576
/// Returns `None` is the instruction is data push or if the script is empty.
578
- pub ( in crate :: blockdata :: script ) fn last_opcode ( & self ) -> Option < Opcode > {
577
+ fn last_opcode( & self ) -> Option <Opcode > {
579
578
match self . instructions( ) . last( ) {
580
579
Some ( Ok ( Instruction :: Op ( op) ) ) => Some ( op) ,
581
580
_ => None ,
@@ -585,7 +584,7 @@ mod tmp_priv {
585
584
/// Iterates the script to find the last pushdata.
586
585
///
587
586
/// Returns `None` if the instruction is an opcode or if the script is empty.
588
- pub ( crate ) fn last_pushdata ( & self ) -> Option < & PushBytes > {
587
+ fn last_pushdata( & self ) -> Option <& PushBytes > {
589
588
match self . instructions( ) . last( ) {
590
589
// Handles op codes up to (but excluding) OP_PUSHNUM_NEG.
591
590
Some ( Ok ( Instruction :: PushBytes ( bytes) ) ) => Some ( bytes) ,
0 commit comments