@@ -47,18 +47,70 @@ macro_rules! all_opcodes {
4747 #[ doc = $doc]
4848 pub const $op: Opcode = Opcode { code: $val} ;
4949 ) *
50- }
5150
52- /// Push an empty array onto the stack.
53- pub static OP_0 : Opcode = OP_PUSHBYTES_0 ;
54- /// Empty stack is also FALSE.
55- pub static OP_FALSE : Opcode = OP_PUSHBYTES_0 ;
56- /// Number 1 is also TRUE.
57- pub static OP_TRUE : Opcode = OP_PUSHNUM_1 ;
58- /// Previously called OP_NOP2.
59- pub static OP_NOP2 : Opcode = OP_CLTV ;
60- /// Previously called OP_NOP3.
61- pub static OP_NOP3 : Opcode = OP_CSV ;
51+ /// Push an empty array onto the stack.
52+ pub const OP_0 : Opcode = OP_PUSHBYTES_0 ;
53+ /// Empty stack is also FALSE.
54+ pub const OP_FALSE : Opcode = OP_PUSHBYTES_0 ;
55+ /// Number 1 is also TRUE.
56+ pub const OP_TRUE : Opcode = OP_1 ;
57+ /// Previously called OP_NOP2.
58+ pub const OP_NOP2 : Opcode = OP_CLTV ;
59+ /// Previously called OP_NOP3.
60+ pub const OP_NOP3 : Opcode = OP_CSV ;
61+
62+ /// Push the array `0x81` onto the stack.
63+ #[ deprecated( since = "TBD" , note = "use OP_1NEGATE instead" ) ]
64+ pub const OP_PUSHNUM_NEG1 : Opcode = OP_1NEGATE ;
65+ /// Push the array `0x01` onto the stack.
66+ #[ deprecated( since = "TBD" , note = "use OP_1 instead" ) ]
67+ pub const OP_PUSHNUM_1 : Opcode = OP_1 ;
68+ /// Push the array `0x02` onto the stack.
69+ #[ deprecated( since = "TBD" , note = "use OP_2 instead" ) ]
70+ pub const OP_PUSHNUM_2 : Opcode = OP_2 ;
71+ /// Push the array `0x03` onto the stack.
72+ #[ deprecated( since = "TBD" , note = "use OP_3 instead" ) ]
73+ pub const OP_PUSHNUM_3 : Opcode = OP_3 ;
74+ /// Push the array `0x04` onto the stack.
75+ #[ deprecated( since = "TBD" , note = "use OP_4 instead" ) ]
76+ pub const OP_PUSHNUM_4 : Opcode = OP_4 ;
77+ /// Push the array `0x05` onto the stack.
78+ #[ deprecated( since = "TBD" , note = "use OP_5 instead" ) ]
79+ pub const OP_PUSHNUM_5 : Opcode = OP_5 ;
80+ /// Push the array `0x06` onto the stack.
81+ #[ deprecated( since = "TBD" , note = "use OP_6 instead" ) ]
82+ pub const OP_PUSHNUM_6 : Opcode = OP_6 ;
83+ /// Push the array `0x07` onto the stack.
84+ #[ deprecated( since = "TBD" , note = "use OP_7 instead" ) ]
85+ pub const OP_PUSHNUM_7 : Opcode = OP_7 ;
86+ /// Push the array `0x08` onto the stack.
87+ #[ deprecated( since = "TBD" , note = "use OP_8 instead" ) ]
88+ pub const OP_PUSHNUM_8 : Opcode = OP_8 ;
89+ /// Push the array `0x09` onto the stack.
90+ #[ deprecated( since = "TBD" , note = "use OP_9 instead" ) ]
91+ pub const OP_PUSHNUM_9 : Opcode = OP_9 ;
92+ /// Push the array `0x0a` onto the stack.
93+ #[ deprecated( since = "TBD" , note = "use OP_10 instead" ) ]
94+ pub const OP_PUSHNUM_10 : Opcode = OP_10 ;
95+ /// Push the array `0x0b` onto the stack.
96+ #[ deprecated( since = "TBD" , note = "use OP_11 instead" ) ]
97+ pub const OP_PUSHNUM_11 : Opcode = OP_11 ;
98+ /// Push the array `0x0c` onto the stack.
99+ #[ deprecated( since = "TBD" , note = "use OP_12 instead" ) ]
100+ pub const OP_PUSHNUM_12 : Opcode = OP_12 ;
101+ /// Push the array `0x0d` onto the stack.
102+ #[ deprecated( since = "TBD" , note = "use OP_13 instead" ) ]
103+ pub const OP_PUSHNUM_13 : Opcode = OP_13 ;
104+ /// Push the array `0x0e` onto the stack.
105+ #[ deprecated( since = "TBD" , note = "use OP_14 instead" ) ]
106+ pub const OP_PUSHNUM_14 : Opcode = OP_14 ;
107+ /// Push the array `0x0f` onto the stack.
108+ #[ deprecated( since = "TBD" , note = "use OP_15 instead" ) ]
109+ pub const OP_PUSHNUM_15 : Opcode = OP_15 ;
110+ /// Push the array `0x10` onto the stack.
111+ #[ deprecated( since = "TBD" , note = "use OP_16 instead" ) ]
112+ pub const OP_PUSHNUM_16 : Opcode = OP_16 ;
113+ }
62114
63115 impl fmt:: Display for Opcode {
64116 fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
@@ -152,24 +204,24 @@ all_opcodes! {
152204 OP_PUSHDATA1 => 0x4c , "Read the next byte as N; push the next N bytes as an array onto the stack." ;
153205 OP_PUSHDATA2 => 0x4d , "Read the next 2 bytes as N; push the next N bytes as an array onto the stack." ;
154206 OP_PUSHDATA4 => 0x4e , "Read the next 4 bytes as N; push the next N bytes as an array onto the stack." ;
155- OP_PUSHNUM_NEG1 => 0x4f , "Push the array `0x81` onto the stack." ;
207+ OP_1NEGATE => 0x4f , "Push the array `0x81` onto the stack." ;
156208 OP_RESERVED => 0x50 , "Synonym for `OP_RETURN`." ;
157- OP_PUSHNUM_1 => 0x51 , "Push the array `0x01` onto the stack." ;
158- OP_PUSHNUM_2 => 0x52 , "Push the array `0x02` onto the stack." ;
159- OP_PUSHNUM_3 => 0x53 , "Push the array `0x03` onto the stack." ;
160- OP_PUSHNUM_4 => 0x54 , "Push the array `0x04` onto the stack." ;
161- OP_PUSHNUM_5 => 0x55 , "Push the array `0x05` onto the stack." ;
162- OP_PUSHNUM_6 => 0x56 , "Push the array `0x06` onto the stack." ;
163- OP_PUSHNUM_7 => 0x57 , "Push the array `0x07` onto the stack." ;
164- OP_PUSHNUM_8 => 0x58 , "Push the array `0x08` onto the stack." ;
165- OP_PUSHNUM_9 => 0x59 , "Push the array `0x09` onto the stack." ;
166- OP_PUSHNUM_10 => 0x5a , "Push the array `0x0a` onto the stack." ;
167- OP_PUSHNUM_11 => 0x5b , "Push the array `0x0b` onto the stack." ;
168- OP_PUSHNUM_12 => 0x5c , "Push the array `0x0c` onto the stack." ;
169- OP_PUSHNUM_13 => 0x5d , "Push the array `0x0d` onto the stack." ;
170- OP_PUSHNUM_14 => 0x5e , "Push the array `0x0e` onto the stack." ;
171- OP_PUSHNUM_15 => 0x5f , "Push the array `0x0f` onto the stack." ;
172- OP_PUSHNUM_16 => 0x60 , "Push the array `0x10` onto the stack." ;
209+ OP_1 => 0x51 , "Push the array `0x01` onto the stack." ;
210+ OP_2 => 0x52 , "Push the array `0x02` onto the stack." ;
211+ OP_3 => 0x53 , "Push the array `0x03` onto the stack." ;
212+ OP_4 => 0x54 , "Push the array `0x04` onto the stack." ;
213+ OP_5 => 0x55 , "Push the array `0x05` onto the stack." ;
214+ OP_6 => 0x56 , "Push the array `0x06` onto the stack." ;
215+ OP_7 => 0x57 , "Push the array `0x07` onto the stack." ;
216+ OP_8 => 0x58 , "Push the array `0x08` onto the stack." ;
217+ OP_9 => 0x59 , "Push the array `0x09` onto the stack." ;
218+ OP_10 => 0x5a , "Push the array `0x0a` onto the stack." ;
219+ OP_11 => 0x5b , "Push the array `0x0b` onto the stack." ;
220+ OP_12 => 0x5c , "Push the array `0x0c` onto the stack." ;
221+ OP_13 => 0x5d , "Push the array `0x0d` onto the stack." ;
222+ OP_14 => 0x5e , "Push the array `0x0e` onto the stack." ;
223+ OP_15 => 0x5f , "Push the array `0x0f` onto the stack." ;
224+ OP_16 => 0x60 , "Push the array `0x10` onto the stack." ;
173225 OP_NOP => 0x61 , "Does nothing." ;
174226 OP_VER => 0x62 , "Synonym for `OP_RETURN`." ;
175227 OP_IF => 0x63 , "Pop and execute the next statements if a nonzero element was popped." ;
@@ -397,11 +449,11 @@ impl Opcode {
397449 | ( OP_CHECKMULTISIGVERIFY , ClassifyContext :: TapScript ) => Class :: ReturnOp ,
398450
399451 // 1 opcode of PushNum class
400- ( OP_PUSHNUM_NEG1 , _) => Class :: PushNum ( -1 ) ,
452+ ( OP_1NEGATE , _) => Class :: PushNum ( -1 ) ,
401453
402454 // 16 opcodes of PushNum class
403- ( op, _) if op. code >= OP_PUSHNUM_1 . code && op. code <= OP_PUSHNUM_16 . code =>
404- Class :: PushNum ( 1 + self . code as i32 - OP_PUSHNUM_1 . code as i32 ) ,
455+ ( op, _) if op. code >= OP_1 . code && op. code <= OP_16 . code =>
456+ Class :: PushNum ( 1 + self . code as i32 - OP_1 . code as i32 ) ,
405457
406458 // 76 opcodes of PushBytes class
407459 ( op, _) if op. code <= OP_PUSHBYTES_75 . code => Class :: PushBytes ( self . code as u32 ) ,
@@ -415,7 +467,7 @@ impl Opcode {
415467 #[ inline]
416468 pub const fn to_u8 ( self ) -> u8 { self . code }
417469
418- /// Encodes PUSHNUM [`Opcode`] as a `u8` representing its number (1-16).
470+ /// Decodes PUSHNUM [`Opcode`] as a `u8` representing its number (1-16).
419471 ///
420472 /// Does not convert `OP_FALSE` to 0. Only `1` to `OP_PUSHNUM_16` are covered.
421473 ///
@@ -425,8 +477,8 @@ impl Opcode {
425477 #[ inline]
426478 #[ must_use]
427479 pub const fn decode_pushnum ( self ) -> Option < u8 > {
428- const START : u8 = OP_PUSHNUM_1 . code ;
429- const END : u8 = OP_PUSHNUM_16 . code ;
480+ const START : u8 = OP_1 . code ;
481+ const END : u8 = OP_16 . code ;
430482 match self . code {
431483 START ..=END => Some ( self . code - START + 1 ) ,
432484 _ => None ,
@@ -575,11 +627,11 @@ mod tests {
575627 fn decode_pushnum ( ) {
576628 // Test all possible opcodes
577629 // - Sanity check
578- assert_eq ! ( OP_PUSHNUM_1 . code, 0x51_u8 ) ;
579- assert_eq ! ( OP_PUSHNUM_16 . code, 0x60_u8 ) ;
630+ assert_eq ! ( OP_1 . code, 0x51_u8 ) ;
631+ assert_eq ! ( OP_16 . code, 0x60_u8 ) ;
580632 for i in 0x00 ..=0xff_u8 {
581633 let expected = match i {
582- // OP_PUSHNUM_1 ..= OP_PUSHNUM_16
634+ // OP_1 ..= OP_16
583635 0x51 ..=0x60 => Some ( i - 0x50 ) ,
584636 _ => None ,
585637 } ;
@@ -589,22 +641,22 @@ mod tests {
589641 // Test the named opcode constants
590642 // - This is the OP right before PUSHNUMs start
591643 assert ! ( OP_RESERVED . decode_pushnum( ) . is_none( ) ) ;
592- assert_eq ! ( OP_PUSHNUM_1 . decode_pushnum( ) . expect( "pushnum" ) , 1 ) ;
593- assert_eq ! ( OP_PUSHNUM_2 . decode_pushnum( ) . expect( "pushnum" ) , 2 ) ;
594- assert_eq ! ( OP_PUSHNUM_3 . decode_pushnum( ) . expect( "pushnum" ) , 3 ) ;
595- assert_eq ! ( OP_PUSHNUM_4 . decode_pushnum( ) . expect( "pushnum" ) , 4 ) ;
596- assert_eq ! ( OP_PUSHNUM_5 . decode_pushnum( ) . expect( "pushnum" ) , 5 ) ;
597- assert_eq ! ( OP_PUSHNUM_6 . decode_pushnum( ) . expect( "pushnum" ) , 6 ) ;
598- assert_eq ! ( OP_PUSHNUM_7 . decode_pushnum( ) . expect( "pushnum" ) , 7 ) ;
599- assert_eq ! ( OP_PUSHNUM_8 . decode_pushnum( ) . expect( "pushnum" ) , 8 ) ;
600- assert_eq ! ( OP_PUSHNUM_9 . decode_pushnum( ) . expect( "pushnum" ) , 9 ) ;
601- assert_eq ! ( OP_PUSHNUM_10 . decode_pushnum( ) . expect( "pushnum" ) , 10 ) ;
602- assert_eq ! ( OP_PUSHNUM_11 . decode_pushnum( ) . expect( "pushnum" ) , 11 ) ;
603- assert_eq ! ( OP_PUSHNUM_12 . decode_pushnum( ) . expect( "pushnum" ) , 12 ) ;
604- assert_eq ! ( OP_PUSHNUM_13 . decode_pushnum( ) . expect( "pushnum" ) , 13 ) ;
605- assert_eq ! ( OP_PUSHNUM_14 . decode_pushnum( ) . expect( "pushnum" ) , 14 ) ;
606- assert_eq ! ( OP_PUSHNUM_15 . decode_pushnum( ) . expect( "pushnum" ) , 15 ) ;
607- assert_eq ! ( OP_PUSHNUM_16 . decode_pushnum( ) . expect( "pushnum" ) , 16 ) ;
644+ assert_eq ! ( OP_1 . decode_pushnum( ) . expect( "pushnum" ) , 1 ) ;
645+ assert_eq ! ( OP_2 . decode_pushnum( ) . expect( "pushnum" ) , 2 ) ;
646+ assert_eq ! ( OP_3 . decode_pushnum( ) . expect( "pushnum" ) , 3 ) ;
647+ assert_eq ! ( OP_4 . decode_pushnum( ) . expect( "pushnum" ) , 4 ) ;
648+ assert_eq ! ( OP_5 . decode_pushnum( ) . expect( "pushnum" ) , 5 ) ;
649+ assert_eq ! ( OP_6 . decode_pushnum( ) . expect( "pushnum" ) , 6 ) ;
650+ assert_eq ! ( OP_7 . decode_pushnum( ) . expect( "pushnum" ) , 7 ) ;
651+ assert_eq ! ( OP_8 . decode_pushnum( ) . expect( "pushnum" ) , 8 ) ;
652+ assert_eq ! ( OP_9 . decode_pushnum( ) . expect( "pushnum" ) , 9 ) ;
653+ assert_eq ! ( OP_10 . decode_pushnum( ) . expect( "pushnum" ) , 10 ) ;
654+ assert_eq ! ( OP_11 . decode_pushnum( ) . expect( "pushnum" ) , 11 ) ;
655+ assert_eq ! ( OP_12 . decode_pushnum( ) . expect( "pushnum" ) , 12 ) ;
656+ assert_eq ! ( OP_13 . decode_pushnum( ) . expect( "pushnum" ) , 13 ) ;
657+ assert_eq ! ( OP_14 . decode_pushnum( ) . expect( "pushnum" ) , 14 ) ;
658+ assert_eq ! ( OP_15 . decode_pushnum( ) . expect( "pushnum" ) , 15 ) ;
659+ assert_eq ! ( OP_16 . decode_pushnum( ) . expect( "pushnum" ) , 16 ) ;
608660 // - This is the OP right after PUSHNUMs end
609661 assert ! ( OP_NOP . decode_pushnum( ) . is_none( ) ) ;
610662 }
@@ -719,24 +771,24 @@ mod tests {
719771 roundtrip ! ( unique, OP_PUSHDATA1 ) ;
720772 roundtrip ! ( unique, OP_PUSHDATA2 ) ;
721773 roundtrip ! ( unique, OP_PUSHDATA4 ) ;
722- roundtrip ! ( unique, OP_PUSHNUM_NEG1 ) ;
774+ roundtrip ! ( unique, OP_1NEGATE ) ;
723775 roundtrip ! ( unique, OP_RESERVED ) ;
724- roundtrip ! ( unique, OP_PUSHNUM_1 ) ;
725- roundtrip ! ( unique, OP_PUSHNUM_2 ) ;
726- roundtrip ! ( unique, OP_PUSHNUM_3 ) ;
727- roundtrip ! ( unique, OP_PUSHNUM_4 ) ;
728- roundtrip ! ( unique, OP_PUSHNUM_5 ) ;
729- roundtrip ! ( unique, OP_PUSHNUM_6 ) ;
730- roundtrip ! ( unique, OP_PUSHNUM_7 ) ;
731- roundtrip ! ( unique, OP_PUSHNUM_8 ) ;
732- roundtrip ! ( unique, OP_PUSHNUM_9 ) ;
733- roundtrip ! ( unique, OP_PUSHNUM_10 ) ;
734- roundtrip ! ( unique, OP_PUSHNUM_11 ) ;
735- roundtrip ! ( unique, OP_PUSHNUM_12 ) ;
736- roundtrip ! ( unique, OP_PUSHNUM_13 ) ;
737- roundtrip ! ( unique, OP_PUSHNUM_14 ) ;
738- roundtrip ! ( unique, OP_PUSHNUM_15 ) ;
739- roundtrip ! ( unique, OP_PUSHNUM_16 ) ;
776+ roundtrip ! ( unique, OP_1 ) ;
777+ roundtrip ! ( unique, OP_2 ) ;
778+ roundtrip ! ( unique, OP_3 ) ;
779+ roundtrip ! ( unique, OP_4 ) ;
780+ roundtrip ! ( unique, OP_5 ) ;
781+ roundtrip ! ( unique, OP_6 ) ;
782+ roundtrip ! ( unique, OP_7 ) ;
783+ roundtrip ! ( unique, OP_8 ) ;
784+ roundtrip ! ( unique, OP_9 ) ;
785+ roundtrip ! ( unique, OP_10 ) ;
786+ roundtrip ! ( unique, OP_11 ) ;
787+ roundtrip ! ( unique, OP_12 ) ;
788+ roundtrip ! ( unique, OP_13 ) ;
789+ roundtrip ! ( unique, OP_14 ) ;
790+ roundtrip ! ( unique, OP_15 ) ;
791+ roundtrip ! ( unique, OP_16 ) ;
740792 roundtrip ! ( unique, OP_NOP ) ;
741793 roundtrip ! ( unique, OP_VER ) ;
742794 roundtrip ! ( unique, OP_IF ) ;
0 commit comments