@@ -89,30 +89,30 @@ impl ScriptBuf {
8989 }
9090}
9191
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 {
9595 /// Creates a new script builder
96- pub fn builder ( ) -> Builder { Builder :: new ( ) }
96+ fn builder( ) -> Builder { Builder :: new( ) }
9797
9898 /// 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 {
100100 Builder :: new( ) . push_opcode( OP_RETURN ) . push_slice( data) . into_script( )
101101 }
102102
103103 /// 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 > {
105105 let v = Vec :: from_hex( s) ?;
106106 Ok ( ScriptBuf :: from_bytes( v) )
107107 }
108108
109109 /// 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( ) ) ; }
111111
112112 /// 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 ) {
114114 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( ) ) ) ;
116116 self . push_slice_no_opt( data) ;
117117 }
118118
@@ -122,15 +122,15 @@ mod tmp_pub {
122122 ///
123123 /// The method panics if the instruction is a data push with length greater or equal to
124124 /// 0x100000000.
125- pub fn push_instruction ( & mut self , instruction : Instruction < ' _ > ) {
125+ fn push_instruction( & mut self , instruction: Instruction <' _>) {
126126 match instruction {
127127 Instruction :: Op ( opcode) => self . push_opcode( opcode) ,
128128 Instruction :: PushBytes ( bytes) => self . push_slice( bytes) ,
129129 }
130130 }
131131
132132 /// 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 <' _>) {
134134 match instruction {
135135 Instruction :: Op ( opcode) => self . push_opcode( opcode) ,
136136 Instruction :: PushBytes ( bytes) => self . push_slice_no_opt( bytes) ,
@@ -151,23 +151,22 @@ mod tmp_pub {
151151 /// This function needs to iterate over the script to find the last instruction. Prefer
152152 /// `Builder` if you're creating the script from scratch or if you want to push `OP_VERIFY`
153153 /// 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( ) ) ; }
155155 }
156156}
157157
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 {
161160 /// Pretends to convert `&mut ScriptBuf` to `&mut Vec<u8>` so that it can be modified.
162161 ///
163162 /// 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 <' _> {
165164 let vec = core:: mem:: take( self ) . into_bytes( ) ;
166165 ScriptBufAsVec ( self , vec)
167166 }
168167
169168 /// 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 ) {
171170 let mut this = self . as_byte_vec( ) ;
172171 // Start with a PUSH opcode
173172 match data. len( ) . to_u64( ) {
@@ -197,7 +196,7 @@ mod tmp_priv {
197196 }
198197
199198 /// 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 {
201200 len + match len {
202201 0 ..=0x4b => 1 ,
203202 0x4c ..=0xff => 2 ,
@@ -211,7 +210,7 @@ mod tmp_priv {
211210 /// alternative.
212211 ///
213212 /// 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 >) {
215214 match opcode_to_verify( last_opcode) {
216215 Some ( opcode) => {
217216 self . as_byte_vec( ) . pop( ) ;
0 commit comments