#![allow(non_camel_case_types)]
use serde;
use std::mem::transmute;
use network::serialize::{SimpleDecoder, SimpleEncoder};
use network::encodable::{ConsensusDecodable, ConsensusEncodable};
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[repr(u8)]
pub enum All {
OP_PUSHBYTES_0 = 0x0,
OP_PUSHBYTES_1 = 0x01,
OP_PUSHBYTES_2 = 0x02,
OP_PUSHBYTES_3 = 0x03,
OP_PUSHBYTES_4 = 0x04,
OP_PUSHBYTES_5 = 0x05,
OP_PUSHBYTES_6 = 0x06,
OP_PUSHBYTES_7 = 0x07,
OP_PUSHBYTES_8 = 0x08,
OP_PUSHBYTES_9 = 0x09,
OP_PUSHBYTES_10 = 0x0a,
OP_PUSHBYTES_11 = 0x0b,
OP_PUSHBYTES_12 = 0x0c,
OP_PUSHBYTES_13 = 0x0d,
OP_PUSHBYTES_14 = 0x0e,
OP_PUSHBYTES_15 = 0x0f,
OP_PUSHBYTES_16 = 0x10,
OP_PUSHBYTES_17 = 0x11,
OP_PUSHBYTES_18 = 0x12,
OP_PUSHBYTES_19 = 0x13,
OP_PUSHBYTES_20 = 0x14,
OP_PUSHBYTES_21 = 0x15,
OP_PUSHBYTES_22 = 0x16,
OP_PUSHBYTES_23 = 0x17,
OP_PUSHBYTES_24 = 0x18,
OP_PUSHBYTES_25 = 0x19,
OP_PUSHBYTES_26 = 0x1a,
OP_PUSHBYTES_27 = 0x1b,
OP_PUSHBYTES_28 = 0x1c,
OP_PUSHBYTES_29 = 0x1d,
OP_PUSHBYTES_30 = 0x1e,
OP_PUSHBYTES_31 = 0x1f,
OP_PUSHBYTES_32 = 0x20,
OP_PUSHBYTES_33 = 0x21,
OP_PUSHBYTES_34 = 0x22,
OP_PUSHBYTES_35 = 0x23,
OP_PUSHBYTES_36 = 0x24,
OP_PUSHBYTES_37 = 0x25,
OP_PUSHBYTES_38 = 0x26,
OP_PUSHBYTES_39 = 0x27,
OP_PUSHBYTES_40 = 0x28,
OP_PUSHBYTES_41 = 0x29,
OP_PUSHBYTES_42 = 0x2a,
OP_PUSHBYTES_43 = 0x2b,
OP_PUSHBYTES_44 = 0x2c,
OP_PUSHBYTES_45 = 0x2d,
OP_PUSHBYTES_46 = 0x2e,
OP_PUSHBYTES_47 = 0x2f,
OP_PUSHBYTES_48 = 0x30,
OP_PUSHBYTES_49 = 0x31,
OP_PUSHBYTES_50 = 0x32,
OP_PUSHBYTES_51 = 0x33,
OP_PUSHBYTES_52 = 0x34,
OP_PUSHBYTES_53 = 0x35,
OP_PUSHBYTES_54 = 0x36,
OP_PUSHBYTES_55 = 0x37,
OP_PUSHBYTES_56 = 0x38,
OP_PUSHBYTES_57 = 0x39,
OP_PUSHBYTES_58 = 0x3a,
OP_PUSHBYTES_59 = 0x3b,
OP_PUSHBYTES_60 = 0x3c,
OP_PUSHBYTES_61 = 0x3d,
OP_PUSHBYTES_62 = 0x3e,
OP_PUSHBYTES_63 = 0x3f,
OP_PUSHBYTES_64 = 0x40,
OP_PUSHBYTES_65 = 0x41,
OP_PUSHBYTES_66 = 0x42,
OP_PUSHBYTES_67 = 0x43,
OP_PUSHBYTES_68 = 0x44,
OP_PUSHBYTES_69 = 0x45,
OP_PUSHBYTES_70 = 0x46,
OP_PUSHBYTES_71 = 0x47,
OP_PUSHBYTES_72 = 0x48,
OP_PUSHBYTES_73 = 0x49,
OP_PUSHBYTES_74 = 0x4a,
OP_PUSHBYTES_75 = 0x4b,
OP_PUSHDATA1 = 0x4c,
OP_PUSHDATA2 = 0x4d,
OP_PUSHDATA4 = 0x4e,
OP_PUSHNUM_NEG1 = 0x4f,
OP_RESERVED = 0x50,
OP_PUSHNUM_1 = 0x51,
OP_PUSHNUM_2 = 0x52,
OP_PUSHNUM_3 = 0x53,
OP_PUSHNUM_4 = 0x54,
OP_PUSHNUM_5 = 0x55,
OP_PUSHNUM_6 = 0x56,
OP_PUSHNUM_7 = 0x57,
OP_PUSHNUM_8 = 0x58,
OP_PUSHNUM_9 = 0x59,
OP_PUSHNUM_10 = 0x5a,
OP_PUSHNUM_11 = 0x5b,
OP_PUSHNUM_12 = 0x5c,
OP_PUSHNUM_13 = 0x5d,
OP_PUSHNUM_14 = 0x5e,
OP_PUSHNUM_15 = 0x5f,
OP_PUSHNUM_16 = 0x60,
OP_NOP = 0x61,
OP_VER = 0x62,
OP_IF = 0x63,
OP_NOTIF = 0x64,
OP_VERIF = 0x65,
OP_VERNOTIF = 0x66,
OP_ELSE = 0x67,
OP_ENDIF = 0x68,
OP_VERIFY = 0x69,
OP_RETURN = 0x6a,
OP_TOALTSTACK = 0x6b,
OP_FROMALTSTACK = 0x6c,
OP_2DROP = 0x6d,
OP_2DUP = 0x6e,
OP_3DUP = 0x6f,
OP_2OVER = 0x70,
OP_2ROT = 0x71,
OP_2SWAP = 0x72,
OP_IFDUP = 0x73,
OP_DEPTH = 0x74,
OP_DROP = 0x75,
OP_DUP = 0x76,
OP_NIP = 0x77,
OP_OVER = 0x78,
OP_PICK = 0x79,
OP_ROLL = 0x7a,
OP_ROT = 0x7b,
OP_SWAP = 0x7c,
OP_TUCK = 0x7d,
OP_CAT = 0x7e,
OP_SUBSTR = 0x7f,
OP_LEFT = 0x80,
OP_RIGHT = 0x81,
OP_SIZE = 0x82,
OP_INVERT = 0x83,
OP_AND = 0x84,
OP_OR = 0x85,
OP_XOR = 0x86,
OP_EQUAL = 0x87,
OP_EQUALVERIFY = 0x88,
OP_RESERVED1 = 0x89,
OP_RESERVED2 = 0x8a,
OP_1ADD = 0x8b,
OP_1SUB = 0x8c,
OP_2MUL = 0x8d,
OP_2DIV = 0x8e,
OP_NEGATE = 0x8f,
OP_ABS = 0x90,
OP_NOT = 0x91,
OP_0NOTEQUAL = 0x92,
OP_ADD = 0x93,
OP_SUB = 0x94,
OP_MUL = 0x95,
OP_DIV = 0x96,
OP_MOD = 0x97,
OP_LSHIFT = 0x98,
OP_RSHIFT = 0x99,
OP_BOOLAND = 0x9a,
OP_BOOLOR = 0x9b,
OP_NUMEQUAL = 0x9c,
OP_NUMEQUALVERIFY = 0x9d,
OP_NUMNOTEQUAL = 0x9e,
OP_LESSTHAN = 0x9f,
OP_GREATERTHAN = 0xa0,
OP_LESSTHANOREQUAL = 0xa1,
OP_GREATERTHANOREQUAL = 0xa2,
OP_MIN = 0xa3,
OP_MAX = 0xa4,
OP_WITHIN = 0xa5,
OP_RIPEMD160 = 0xa6,
OP_SHA1 = 0xa7,
OP_SHA256 = 0xa8,
OP_HASH160 = 0xa9,
OP_HASH256 = 0xaa,
OP_CODESEPARATOR = 0xab,
OP_CHECKSIG = 0xac,
OP_CHECKSIGVERIFY = 0xad,
OP_CHECKMULTISIG = 0xae,
OP_CHECKMULTISIGVERIFY = 0xaf,
OP_NOP1 = 0xb0,
OP_NOP2 = 0xb1,
OP_NOP3 = 0xb2,
OP_NOP4 = 0xb3,
OP_NOP5 = 0xb4,
OP_NOP6 = 0xb5,
OP_NOP7 = 0xb6,
OP_NOP8 = 0xb7,
OP_NOP9 = 0xb8,
OP_NOP10 = 0xb9,
OP_RETURN_186 = 0xba,
OP_RETURN_187 = 0xbb,
OP_RETURN_188 = 0xbc,
OP_RETURN_189 = 0xbd,
OP_RETURN_190 = 0xbe,
OP_RETURN_191 = 0xbf,
OP_RETURN_192 = 0xc0,
OP_RETURN_193 = 0xc1,
OP_RETURN_194 = 0xc2,
OP_RETURN_195 = 0xc3,
OP_RETURN_196 = 0xc4,
OP_RETURN_197 = 0xc5,
OP_RETURN_198 = 0xc6,
OP_RETURN_199 = 0xc7,
OP_RETURN_200 = 0xc8,
OP_RETURN_201 = 0xc9,
OP_RETURN_202 = 0xca,
OP_RETURN_203 = 0xcb,
OP_RETURN_204 = 0xcc,
OP_RETURN_205 = 0xcd,
OP_RETURN_206 = 0xce,
OP_RETURN_207 = 0xcf,
OP_RETURN_208 = 0xd0,
OP_RETURN_209 = 0xd1,
OP_RETURN_210 = 0xd2,
OP_RETURN_211 = 0xd3,
OP_RETURN_212 = 0xd4,
OP_RETURN_213 = 0xd5,
OP_RETURN_214 = 0xd6,
OP_RETURN_215 = 0xd7,
OP_RETURN_216 = 0xd8,
OP_RETURN_217 = 0xd9,
OP_RETURN_218 = 0xda,
OP_RETURN_219 = 0xdb,
OP_RETURN_220 = 0xdc,
OP_RETURN_221 = 0xdd,
OP_RETURN_222 = 0xde,
OP_RETURN_223 = 0xdf,
OP_RETURN_224 = 0xe0,
OP_RETURN_225 = 0xe1,
OP_RETURN_226 = 0xe2,
OP_RETURN_227 = 0xe3,
OP_RETURN_228 = 0xe4,
OP_RETURN_229 = 0xe5,
OP_RETURN_230 = 0xe6,
OP_RETURN_231 = 0xe7,
OP_RETURN_232 = 0xe8,
OP_RETURN_233 = 0xe9,
OP_RETURN_234 = 0xea,
OP_RETURN_235 = 0xeb,
OP_RETURN_236 = 0xec,
OP_RETURN_237 = 0xed,
OP_RETURN_238 = 0xee,
OP_RETURN_239 = 0xef,
OP_RETURN_240 = 0xf0,
OP_RETURN_241 = 0xf1,
OP_RETURN_242 = 0xf2,
OP_RETURN_243 = 0xf3,
OP_RETURN_244 = 0xf4,
OP_RETURN_245 = 0xf5,
OP_RETURN_246 = 0xf6,
OP_RETURN_247 = 0xf7,
OP_RETURN_248 = 0xf8,
OP_RETURN_249 = 0xf9,
OP_RETURN_250 = 0xfa,
OP_RETURN_251 = 0xfb,
OP_RETURN_252 = 0xfc,
OP_RETURN_253 = 0xfd,
OP_RETURN_254 = 0xfe,
OP_RETURN_255 = 0xff,
}
impl All {
#[inline]
pub fn classify(&self) -> Class {
if *self == All::OP_VERIF || *self == All::OP_VERNOTIF ||
*self == All::OP_CAT || *self == All::OP_SUBSTR ||
*self == All::OP_LEFT || *self == All::OP_RIGHT ||
*self == All::OP_INVERT || *self == All::OP_AND ||
*self == All::OP_OR || *self == All::OP_XOR ||
*self == All::OP_2MUL || *self == All::OP_2DIV ||
*self == All::OP_MUL || *self == All::OP_DIV || *self == All::OP_MOD ||
*self == All::OP_LSHIFT || *self == All::OP_RSHIFT {
Class::IllegalOp
} else if *self == All::OP_NOP ||
(All::OP_NOP1 as u8 <= *self as u8 &&
*self as u8 <= All::OP_NOP10 as u8) {
Class::NoOp
} else if *self == All::OP_RESERVED || *self == All::OP_VER || *self == All::OP_RETURN ||
*self == All::OP_RESERVED1 || *self == All::OP_RESERVED2 ||
*self as u8 >= All::OP_RETURN_186 as u8 {
Class::ReturnOp
} else if *self == All::OP_PUSHNUM_NEG1 {
Class::PushNum(-1)
} else if All::OP_PUSHNUM_1 as u8 <= *self as u8 &&
*self as u8 <= All::OP_PUSHNUM_16 as u8 {
Class::PushNum(1 + *self as i32 - All::OP_PUSHNUM_1 as i32)
} else if *self as u8 <= All::OP_PUSHBYTES_75 as u8 {
Class::PushBytes(*self as u32)
} else {
Class::Ordinary(unsafe { transmute(*self) })
}
}
}
impl From<u8> for All {
#[inline]
fn from(b: u8) -> All {
unsafe { transmute(b) }
}
}
display_from_debug!(All);
impl<D: SimpleDecoder> ConsensusDecodable<D> for All {
#[inline]
fn consensus_decode(d: &mut D) -> Result<All, D::Error> {
Ok(All::from(try!(d.read_u8())))
}
}
impl<S: SimpleEncoder> ConsensusEncodable<S> for All {
#[inline]
fn consensus_encode(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_u8(*self as u8)
}
}
impl serde::Serialize for All {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer,
{
serializer.visit_str(&self.to_string())
}
}
pub static OP_FALSE: All = All::OP_PUSHBYTES_0;
pub static OP_TRUE: All = All::OP_PUSHNUM_1;
pub static OP_CLTV: All = All::OP_NOP2;
pub static OP_CSV: All = All::OP_NOP3;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Class {
PushNum(i32),
PushBytes(u32),
ReturnOp,
IllegalOp,
NoOp,
Ordinary(Ordinary)
}
display_from_debug!(Class);
impl serde::Serialize for Class {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer,
{
serializer.visit_str(&self.to_string())
}
}
macro_rules! ordinary_opcode {
($($op:ident),*) => (
#[repr(u8)]
#[doc(hidden)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Ordinary {
$( $op = All::$op as u8 ),*
}
);
}
ordinary_opcode! {
OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4,
OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF, OP_VERIFY,
OP_TOALTSTACK, OP_FROMALTSTACK,
OP_2DROP, OP_2DUP, OP_3DUP, OP_2OVER, OP_2ROT, OP_2SWAP,
OP_DROP, OP_DUP, OP_NIP, OP_OVER, OP_PICK, OP_ROLL, OP_ROT, OP_SWAP, OP_TUCK,
OP_IFDUP, OP_DEPTH, OP_SIZE,
OP_EQUAL, OP_EQUALVERIFY,
OP_1ADD, OP_1SUB, OP_NEGATE, OP_ABS, OP_NOT, OP_0NOTEQUAL,
OP_ADD, OP_SUB, OP_BOOLAND, OP_BOOLOR,
OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_LESSTHAN,
OP_GREATERTHAN, OP_LESSTHANOREQUAL, OP_GREATERTHANOREQUAL,
OP_MIN, OP_MAX, OP_WITHIN,
OP_RIPEMD160, OP_SHA1, OP_SHA256, OP_HASH160, OP_HASH256,
OP_CODESEPARATOR, OP_CHECKSIG, OP_CHECKSIGVERIFY,
OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY
}