@@ -114,6 +114,45 @@ impl ScriptBuf {
114114 self . push_slice_no_opt ( data) ;
115115 }
116116
117+ /// Add a single instruction to the script.
118+ ///
119+ /// # Panics
120+ ///
121+ /// The method panics if the instruction is a data push with length greater or equal to
122+ /// 0x100000000.
123+ pub fn push_instruction ( & mut self , instruction : Instruction < ' _ > ) {
124+ match instruction {
125+ Instruction :: Op ( opcode) => self . push_opcode ( opcode) ,
126+ Instruction :: PushBytes ( bytes) => self . push_slice ( bytes) ,
127+ }
128+ }
129+
130+ /// Like push_instruction, but avoids calling `reserve` to not re-check the length.
131+ pub fn push_instruction_no_opt ( & mut self , instruction : Instruction < ' _ > ) {
132+ match instruction {
133+ Instruction :: Op ( opcode) => self . push_opcode ( opcode) ,
134+ Instruction :: PushBytes ( bytes) => self . push_slice_no_opt ( bytes) ,
135+ }
136+ }
137+
138+ /// Adds an `OP_VERIFY` to the script or replaces the last opcode with VERIFY form.
139+ ///
140+ /// Some opcodes such as `OP_CHECKSIG` have a verify variant that works as if `VERIFY` was
141+ /// in the script right after. To save space this function appends `VERIFY` only if
142+ /// the most-recently-added opcode *does not* have an alternate `VERIFY` form. If it does
143+ /// the last opcode is replaced. E.g., `OP_CHECKSIG` will become `OP_CHECKSIGVERIFY`.
144+ ///
145+ /// Note that existing `OP_*VERIFY` opcodes do not lead to the instruction being ignored
146+ /// because `OP_VERIFY` consumes an item from the stack so ignoring them would change the
147+ /// semantics.
148+ ///
149+ /// This function needs to iterate over the script to find the last instruction. Prefer
150+ /// `Builder` if you're creating the script from scratch or if you want to push `OP_VERIFY`
151+ /// multiple times.
152+ pub fn scan_and_push_verify ( & mut self ) { self . push_verify ( self . last_opcode ( ) ) ; }
153+ }
154+
155+ impl ScriptBuf {
117156 /// Pushes the slice without reserving
118157 fn push_slice_no_opt ( & mut self , data : & PushBytes ) {
119158 // Start with a PUSH opcode
@@ -154,43 +193,6 @@ impl ScriptBuf {
154193 }
155194 }
156195
157- /// Add a single instruction to the script.
158- ///
159- /// # Panics
160- ///
161- /// The method panics if the instruction is a data push with length greater or equal to
162- /// 0x100000000.
163- pub fn push_instruction ( & mut self , instruction : Instruction < ' _ > ) {
164- match instruction {
165- Instruction :: Op ( opcode) => self . push_opcode ( opcode) ,
166- Instruction :: PushBytes ( bytes) => self . push_slice ( bytes) ,
167- }
168- }
169-
170- /// Like push_instruction, but avoids calling `reserve` to not re-check the length.
171- pub fn push_instruction_no_opt ( & mut self , instruction : Instruction < ' _ > ) {
172- match instruction {
173- Instruction :: Op ( opcode) => self . push_opcode ( opcode) ,
174- Instruction :: PushBytes ( bytes) => self . push_slice_no_opt ( bytes) ,
175- }
176- }
177-
178- /// Adds an `OP_VERIFY` to the script or replaces the last opcode with VERIFY form.
179- ///
180- /// Some opcodes such as `OP_CHECKSIG` have a verify variant that works as if `VERIFY` was
181- /// in the script right after. To save space this function appends `VERIFY` only if
182- /// the most-recently-added opcode *does not* have an alternate `VERIFY` form. If it does
183- /// the last opcode is replaced. E.g., `OP_CHECKSIG` will become `OP_CHECKSIGVERIFY`.
184- ///
185- /// Note that existing `OP_*VERIFY` opcodes do not lead to the instruction being ignored
186- /// because `OP_VERIFY` consumes an item from the stack so ignoring them would change the
187- /// semantics.
188- ///
189- /// This function needs to iterate over the script to find the last instruction. Prefer
190- /// `Builder` if you're creating the script from scratch or if you want to push `OP_VERIFY`
191- /// multiple times.
192- pub fn scan_and_push_verify ( & mut self ) { self . push_verify ( self . last_opcode ( ) ) ; }
193-
194196 /// Adds an `OP_VERIFY` to the script or changes the most-recently-added opcode to `VERIFY`
195197 /// alternative.
196198 ///
0 commit comments