@@ -148,27 +148,27 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
148
148
149
149
pub struct Builder ( pub BitcoinBuilder ) ;
150
150
151
- pub fn check_optimality( opcode: Opcode , next_opcode: Opcode ) {
151
+ pub fn check_optimality( opcode: Opcode , next_opcode: Opcode , file : & str , line : u32 ) {
152
152
match ( opcode, next_opcode) {
153
- ( OP_PUSHNUM_1 , OP_ADD ) => eprintln!( "Script can be optimized: 1 OP_ADD => OP_1ADD" ) ,
154
- ( OP_PUSHNUM_1 , OP_SUB ) => eprintln!( "Script can be optimized: 1 OP_SUB => OP_1SUB" ) ,
153
+ ( OP_PUSHNUM_1 , OP_ADD ) => eprintln!( "Script at {}:{} can be optimized: 1 OP_ADD => OP_1ADD" , file , line ) ,
154
+ ( OP_PUSHNUM_1 , OP_SUB ) => eprintln!( "Script at {}:{} can be optimized: 1 OP_SUB => OP_1SUB" , file , line ) ,
155
155
( OP_DROP , OP_DROP ) => {
156
- eprintln!( "Script can be optimized: OP_DROP OP_DROP => OP_2DROP" )
156
+ eprintln!( "Script at {}:{} can be optimized: OP_DROP OP_DROP => OP_2DROP" , file , line )
157
157
}
158
- ( OP_PUSHBYTES_0 , OP_ROLL ) => eprintln!( "Script can be optimized: Remove 0 OP_ROLL" ) ,
158
+ ( OP_PUSHBYTES_0 , OP_ROLL ) => eprintln!( "Script at {}:{} can be optimized: Remove 0 OP_ROLL" , file , line ) ,
159
159
( OP_PUSHNUM_1 , OP_ROLL ) => {
160
- eprintln!( "Script can be optimized: 1 OP_ROLL => OP_SWAP" )
160
+ eprintln!( "Script at {}:{} can be optimized: 1 OP_ROLL => OP_SWAP" , file , line )
161
161
}
162
162
( OP_PUSHNUM_2 , OP_ROLL ) => {
163
- eprintln!( "Script can be optimized: 2 OP_ROLL => OP_ROT" )
163
+ eprintln!( "Script at {}:{} can be optimized: 2 OP_ROLL => OP_ROT" , file , line )
164
164
}
165
165
( OP_PUSHBYTES_0 , OP_PICK ) => {
166
- eprintln!( "Script can be optimized: 0 OP_PICK => OP_DUP" )
166
+ eprintln!( "Script at {}:{} can be optimized: 0 OP_PICK => OP_DUP" , file , line )
167
167
}
168
168
( OP_PUSHBYTES_1 , OP_PICK ) => {
169
- eprintln!( "Script can be optimized: 1 OP_PICK => OP_OVER" )
169
+ eprintln!( "Script at {}:{} can be optimized: 1 OP_PICK => OP_OVER" , file , line )
170
170
}
171
- ( OP_IF , OP_ELSE ) => eprintln!( "Script can be optimized: OP_IF OP_ELSE => OP_NOTIF" ) ,
171
+ ( OP_IF , OP_ELSE ) => eprintln!( "Script at {}:{} can be optimized: OP_IF OP_ELSE => OP_NOTIF" , file , line ) ,
172
172
( _, _) => ( ) ,
173
173
}
174
174
}
@@ -187,20 +187,20 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
187
187
self . 0 . as_script( )
188
188
}
189
189
190
- pub fn push_opcode( mut self , opcode: Opcode ) -> Builder {
190
+ pub fn push_opcode( mut self , opcode: Opcode , file : & str , line : u32 ) -> Builder {
191
191
match self . as_script( ) . instructions_minimal( ) . last( ) {
192
192
Some ( instr_result) => match instr_result {
193
193
Ok ( instr) => match instr {
194
194
bitcoin:: script:: Instruction :: PushBytes ( push_bytes) => {
195
195
if push_bytes. as_bytes( ) == [ ] {
196
- check_optimality( :: bitcoin:: opcodes:: all:: OP_PUSHBYTES_0 , opcode)
196
+ check_optimality( :: bitcoin:: opcodes:: all:: OP_PUSHBYTES_0 , opcode, file , line )
197
197
}
198
198
} ,
199
199
bitcoin:: script:: Instruction :: Op ( previous_opcode) => {
200
- check_optimality( previous_opcode, opcode)
200
+ check_optimality( previous_opcode, opcode, file , line )
201
201
}
202
202
} ,
203
- Err ( _) => eprintln!( "Script includes non-minimal pushes." ) ,
203
+ Err ( _) => eprintln!( "Script at {}:{} includes non-minimal pushes." , file , line ) ,
204
204
} ,
205
205
None => ( ) ,
206
206
} ;
@@ -223,7 +223,7 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
223
223
self
224
224
}
225
225
226
- pub fn push_expression<T : Pushable >( self , expression: T ) -> Builder {
226
+ pub fn push_expression<T : Pushable >( self , expression: T , file : & str , line : u32 ) -> Builder {
227
227
let last_opcode_index = match self . as_script( ) . instruction_indices_minimal( ) . last( )
228
228
{
229
229
Some ( instr_result) => match instr_result {
@@ -240,7 +240,7 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
240
240
bitcoin:: script:: Instruction :: Op ( opcode) => Some ( ( index, opcode) ) ,
241
241
} ,
242
242
Err ( _) => {
243
- eprintln!( "Script includes non-minimal pushes." ) ;
243
+ eprintln!( "Script at {}:{} includes non-minimal pushes." , file , line ) ;
244
244
None
245
245
}
246
246
} ,
@@ -258,12 +258,12 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
258
258
Ok ( instr) => match instr {
259
259
bitcoin:: script:: Instruction :: PushBytes ( _) => ( ) ,
260
260
bitcoin:: script:: Instruction :: Op ( opcode) => {
261
- check_optimality( previous_opcode, opcode)
261
+ check_optimality( previous_opcode, opcode, file , line )
262
262
}
263
263
} ,
264
- Err ( _) => eprintln!( "Script includes non-minimal pushes." ) ,
264
+ Err ( _) => eprintln!( "Script at {}:{} includes non-minimal pushes." , file , line ) ,
265
265
} ,
266
- None => eprintln!( "Script extends an empty script!" ) ,
266
+ None => eprintln!( "Script at {}:{} extends an empty script!" , file , line ) ,
267
267
} ;
268
268
}
269
269
builder
@@ -325,7 +325,7 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
325
325
}
326
326
} ,
327
327
Err ( _) => {
328
- eprintln!( "Script includes non-minimal pushes." ) ;
328
+ eprintln!( "A Script includes non-minimal pushes." ) ;
329
329
None
330
330
}
331
331
} ,
@@ -338,10 +338,10 @@ pub fn define_pushable(_: TokenStream) -> TokenStream {
338
338
Ok ( instr) => match instr {
339
339
bitcoin:: script:: Instruction :: PushBytes ( _) => ( ) ,
340
340
bitcoin:: script:: Instruction :: Op ( opcode) => {
341
- check_optimality( previous_opcode, opcode)
341
+ check_optimality( previous_opcode, opcode, file! ( ) , line! ( ) )
342
342
}
343
343
} ,
344
- Err ( _) => eprintln!( "Script includes non-minimal pushes." ) ,
344
+ Err ( _) => eprintln!( "A Script includes non-minimal pushes." ) ,
345
345
} ,
346
346
None => ( ) ,
347
347
}
0 commit comments