@@ -89,30 +89,30 @@ impl ScriptBuf {
89
89
}
90
90
}
91
91
92
- mod tmp_pub {
93
- use super :: * ;
94
- impl ScriptBuf {
92
+ crate :: internal_macros :: define_extension_trait! {
93
+ /// Extension functionality for the [`ScriptBuf`] type.
94
+ pub trait ScriptBufExt impl for ScriptBuf {
95
95
/// Creates a new script builder
96
- pub fn builder ( ) -> Builder { Builder :: new ( ) }
96
+ fn builder( ) -> Builder { Builder :: new( ) }
97
97
98
98
/// Generates OP_RETURN-type of scriptPubkey for the given data.
99
- pub fn new_op_return < T : AsRef < PushBytes > > ( data : T ) -> Self {
99
+ fn new_op_return<T : AsRef <PushBytes >>( data: T ) -> Self {
100
100
Builder :: new( ) . push_opcode( OP_RETURN ) . push_slice( data) . into_script( )
101
101
}
102
102
103
103
/// Creates a [`ScriptBuf`] from a hex string.
104
- pub fn from_hex ( s : & str ) -> Result < Self , hex:: HexToBytesError > {
104
+ fn from_hex( s: & str ) -> Result <ScriptBuf , hex:: HexToBytesError > {
105
105
let v = Vec :: from_hex( s) ?;
106
106
Ok ( ScriptBuf :: from_bytes( v) )
107
107
}
108
108
109
109
/// Adds a single opcode to the script.
110
- pub fn push_opcode ( & mut self , data : Opcode ) { self . as_byte_vec ( ) . push ( data. to_u8 ( ) ) ; }
110
+ fn push_opcode( & mut self , data: Opcode ) { self . as_byte_vec( ) . push( data. to_u8( ) ) ; }
111
111
112
112
/// Adds instructions to push some arbitrary data onto the stack.
113
- pub fn push_slice < T : AsRef < PushBytes > > ( & mut self , data : T ) {
113
+ fn push_slice<T : AsRef <PushBytes >>( & mut self , data: T ) {
114
114
let data = data. as_ref( ) ;
115
- self . reserve ( Self :: reserved_len_for_slice ( data. len ( ) ) ) ;
115
+ self . reserve( ScriptBuf :: reserved_len_for_slice( data. len( ) ) ) ;
116
116
self . push_slice_no_opt( data) ;
117
117
}
118
118
@@ -122,15 +122,15 @@ mod tmp_pub {
122
122
///
123
123
/// The method panics if the instruction is a data push with length greater or equal to
124
124
/// 0x100000000.
125
- pub fn push_instruction ( & mut self , instruction : Instruction < ' _ > ) {
125
+ fn push_instruction( & mut self , instruction: Instruction <' _>) {
126
126
match instruction {
127
127
Instruction :: Op ( opcode) => self . push_opcode( opcode) ,
128
128
Instruction :: PushBytes ( bytes) => self . push_slice( bytes) ,
129
129
}
130
130
}
131
131
132
132
/// Like push_instruction, but avoids calling `reserve` to not re-check the length.
133
- pub fn push_instruction_no_opt ( & mut self , instruction : Instruction < ' _ > ) {
133
+ fn push_instruction_no_opt( & mut self , instruction: Instruction <' _>) {
134
134
match instruction {
135
135
Instruction :: Op ( opcode) => self . push_opcode( opcode) ,
136
136
Instruction :: PushBytes ( bytes) => self . push_slice_no_opt( bytes) ,
@@ -151,23 +151,22 @@ mod tmp_pub {
151
151
/// This function needs to iterate over the script to find the last instruction. Prefer
152
152
/// `Builder` if you're creating the script from scratch or if you want to push `OP_VERIFY`
153
153
/// multiple times.
154
- pub fn scan_and_push_verify ( & mut self ) { self . push_verify ( self . last_opcode ( ) ) ; }
154
+ fn scan_and_push_verify( & mut self ) { self . push_verify( self . last_opcode( ) ) ; }
155
155
}
156
156
}
157
157
158
- mod tmp_priv {
159
- use super :: * ;
160
- impl ScriptBuf {
158
+ crate :: internal_macros:: define_extension_trait! {
159
+ pub ( crate ) trait ScriptBufExtPriv impl for ScriptBuf {
161
160
/// Pretends to convert `&mut ScriptBuf` to `&mut Vec<u8>` so that it can be modified.
162
161
///
163
162
/// Note: if the returned value leaks the original `ScriptBuf` will become empty.
164
- pub ( crate ) fn as_byte_vec ( & mut self ) -> ScriptBufAsVec < ' _ > {
163
+ fn as_byte_vec( & mut self ) -> ScriptBufAsVec <' _> {
165
164
let vec = core:: mem:: take( self ) . into_bytes( ) ;
166
165
ScriptBufAsVec ( self , vec)
167
166
}
168
167
169
168
/// Pushes the slice without reserving
170
- pub ( crate ) fn push_slice_no_opt ( & mut self , data : & PushBytes ) {
169
+ fn push_slice_no_opt( & mut self , data: & PushBytes ) {
171
170
let mut this = self . as_byte_vec( ) ;
172
171
// Start with a PUSH opcode
173
172
match data. len( ) . to_u64( ) {
@@ -197,7 +196,7 @@ mod tmp_priv {
197
196
}
198
197
199
198
/// Computes the sum of `len` and the length of an appropriate push opcode.
200
- pub ( crate ) fn reserved_len_for_slice ( len : usize ) -> usize {
199
+ fn reserved_len_for_slice( len: usize ) -> usize {
201
200
len + match len {
202
201
0 ..=0x4b => 1 ,
203
202
0x4c ..=0xff => 2 ,
@@ -211,7 +210,7 @@ mod tmp_priv {
211
210
/// alternative.
212
211
///
213
212
/// See the public fn [`Self::scan_and_push_verify`] to learn more.
214
- pub ( crate ) fn push_verify ( & mut self , last_opcode : Option < Opcode > ) {
213
+ fn push_verify( & mut self , last_opcode: Option <Opcode >) {
215
214
match opcode_to_verify( last_opcode) {
216
215
Some ( opcode) => {
217
216
self . as_byte_vec( ) . pop( ) ;
0 commit comments