[−][src]Enum bitcoin_cash::Opcode
All opcodes which can be used in a Bitcoin Cash script.
Can be used in #[bitcoin_cash::script]
functions.
Example
use bitcoin_cash::{Opcode::*, Address, ByteArray, Hashed}; struct Params { address: Address<'static>, } #[bitcoin_cash::script(P2pkhInputs)] fn p2pkh_script(params: &Params, signature: ByteArray, public_key: ByteArray) { OP_DUP(public_key); let pkh = OP_HASH160(public_key); let address = { params.address.hash().as_slice() }; OP_EQUALVERIFY(pkh, address); OP_CHECKSIG(signature, public_key); }
Variants
OP_0() -> Integer
Pushes the integer 0 onto the stack.
Usage:
let zero = OP_0; let expected = 0; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(zero, expected);
Pushes the next byte number of bytes. Not to be used in #[bitcoin_cash::script]
functions.
Pushes the next two byte number of bytes. Not to be used in #[bitcoin_cash::script]
functions.
Pushes the next four byte number of bytes. Not to be used in #[bitcoin_cash::script]
functions.
OP_1NEGATE() -> Integer
Pushes the integer -1 onto the stack.
Usage:
// push -1 let minus_one = OP_1NEGATE; let expected = -1; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(minus_one, expected);
Reserved opcode. Fails script if in executed branch immediately.
OP_1() -> Integer
Pushes the integer 1 onto the stack.
Usage:
// push 1 let one = OP_1; let expected = 1; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(one, expected);
OP_2() -> Integer
Pushes the integer 2 onto the stack.
Usage:
// push 2 let two = OP_2; let expected = 2; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(two, expected);
OP_3() -> Integer
Pushes the integer 3 onto the stack.
Usage:
// push 3 let three = OP_3; let expected = 3; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(three, expected);
OP_4() -> Integer
Pushes the integer 4 onto the stack.
Usage:
// push 4 let four = OP_4; let expected = 4; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(four, expected);
OP_5() -> Integer
Pushes the integer 5 onto the stack.
Usage:
// push 5 let five = OP_5; let expected = 5; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(five, expected);
OP_6() -> Integer
Pushes the integer 6 onto the stack.
Usage:
// push 6 let six = OP_6; let expected = 6; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(six, expected);
OP_7() -> Integer
Pushes the integer 7 onto the stack.
Usage:
// push 7 let seven = OP_7; let expected = 7; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(seven, expected);
OP_8() -> Integer
Pushes the integer 8 onto the stack.
Usage:
// push 8 let eight = OP_8; let expected = 8; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(eight, expected);
OP_9() -> Integer
Pushes the integer 9 onto the stack.
Usage:
// push 9 let nine = OP_9; let expected = 9; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(nine, expected);
OP_10() -> Integer
Pushes the integer 10 onto the stack.
Usage:
// push 10 let ten = OP_10; let expected = 10; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(ten, expected);
OP_11() -> Integer
Pushes the integer 11 onto the stack.
Usage:
// push 11 let eleven = OP_11; let expected = 11; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(eleven, expected);
OP_12() -> Integer
Pushes the integer 12 onto the stack.
Usage:
// push 12 let twelve = OP_12; let expected = 12; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(twelve, expected);
OP_13() -> Integer
Pushes the integer 13 onto the stack.
Usage:
// push 13 let thirteen = OP_13; let expected = 13; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(thirteen, expected);
OP_14() -> Integer
Pushes the integer 14 onto the stack.
Usage:
// push 14 let fourteen = OP_14; let expected = 14; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(fourteen, expected);
OP_15() -> Integer
Pushes the integer 15 onto the stack.
Usage:
// push 15 let fiveteen = OP_15; let expected = 15; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(fiveteen, expected);
OP_16() -> Integer
Pushes the integer 16 onto the stack.
Usage:
// push 16 let sixteen = OP_16; let expected = 16; // equivalent (and prefered) way to push numbers OP_EQUALVERIFY(sixteen, expected);
OP_NOP() -> ()
Does nothing.
Usage:
// do nothing OP_NOP();
Reserved opcode. Fails script if in executed branch immediately.
OP_IF(condition: bool) -> ()
Creates a branch (OP_IF
/OP_ELSE
/OP_ENDIF
construct) that will only execute
if condition
is true and will execute the alternative branch otherwise.
Usage:
let condition = true; // branch on condition OP_IF(condition); { let result = 5; } OP_ELSE; { let result = 6; } OP_ENDIF; let expected = 5; OP_EQUALVERIFY(result, expected);
Opposite of OP_NOTIF. Currently not supported in #[bitcoin_cash::script]
functions.
Disabled opcode. Fails script immediately even if not in executed branch.
Disabled opcode. Fails script immediately even if not in executed branch.
OP_ELSE() -> ()
Demarcates a branch (OP_IF
/OP_ELSE
/OP_ENDIF
construct) that will only execute
if condition
is true and will execute the alternative branch otherwise.
Usage:
let condition = true; // branch on condition OP_IF(condition); { let result = 5; } OP_ELSE; { let result = 6; } OP_ENDIF; let expected = 5; OP_EQUALVERIFY(result, expected);
OP_ENDIF() -> ()
Ends a branch (OP_IF
/OP_ELSE
/OP_ENDIF
construct) that will only execute
if condition
is true and will execute the alternative branch otherwise.
Usage:
let condition = true; // branch on condition OP_IF(condition); { let result = 5; } OP_ELSE; { let result = 6; } OP_ENDIF; let expected = 5; OP_EQUALVERIFY(result, expected);
OP_VERIFY(condition: bool) -> ()
Marks transaction as invalid if condition
is not true.
Usage:
let condition = true; // verify condition OP_VERIFY(condition);
Fails execution of the script immediately. Used to attach data to transactions.
OP_TOALTSTACK<T>(item: T) -> ()
Moves item
to the top of the altstack.
Usage:
let item = b"Bitcoin Cash"; // move item to altstack OP_TOALTSTACK(item); let expected = b"Bitcoin Cash"; OP_FROMALTSTACK(item); // Note: retains name "item" on altstack OP_EQUALVERIFY(expected, item);
OP_FROMALTSTACK<T>(altitem: T) -> T
Moves the top item of the altstack to the main stack.
Usage:
let item = b"Bitcoin Cash"; OP_TOALTSTACK(item); let expected = b"Bitcoin Cash"; // move item back to main stack OP_FROMALTSTACK(item); // Note: retains name "item" on main stack OP_EQUALVERIFY(expected, item);
OP_2DROP<T, U>(a: T, b: U) -> ()
Drops the two top stack items.
a b ->
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; // drop b and c OP_2DROP(b, c); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_2DUP<T, U>(a: T, b: U) -> (T, U, T, U)
Duplicates the top two stack items.
a b -> a b a b
Usage:
let a = b"A"; let b = b"B"; // duplicate a and b OP_2DUP(a, b); // Note: duplicated items retain name let expected = b"A"; OP_EQUALVERIFY(b, expected); let expected = b"B"; OP_EQUALVERIFY(a, expected); let expected = b"A"; OP_EQUALVERIFY(b, expected); let expected = b"B"; OP_EQUALVERIFY(a, expected);
OP_3DUP<T, U, V>(a: T, b: U, c: V) -> (T, U, V, T, U, V)
Duplicates the top two three items.
a b c -> a b c a b c
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; // duplicate a, b and c OP_3DUP(a, b, c); // Note: duplicated items retain name let expected = b"C"; OP_EQUALVERIFY(c, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"C"; OP_EQUALVERIFY(c, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_2OVER<T, U, V, W>(a: T, b: U, c: V, d: W) -> (T, U, V, W, T, U)
Copies the pair of items two spaces back in the stack to the front.
a b _ _ -> a b _ _ a b
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; let d = b"D"; // duplicate a and b OP_2OVER(a, b, __, __); // Note: duplicated items retain name let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"D"; OP_EQUALVERIFY(d, expected); let expected = b"C"; OP_EQUALVERIFY(c, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_2ROT<T, U, V, W, X, Y>(a: T, b: U, c: V, d: W, e: X, f: Y) -> (V, W, X, Y, T, U)
The fifth and sixth items back are moved to the top of the stack.
a b _ _ _ _ -> _ _ _ _ a b
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; let d = b"D"; let e = b"E"; let f = b"F"; // move a and b to the top OP_2ROT(a, b, __, __, __, __); // Note: moved items retain name let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"F"; OP_EQUALVERIFY(f, expected); let expected = b"E"; OP_EQUALVERIFY(e, expected); let expected = b"D"; OP_EQUALVERIFY(d, expected); let expected = b"C"; OP_EQUALVERIFY(c, expected);
OP_2SWAP<T, U, V, W>(a: T, b: U, c: V, d: W) -> (V, W, T, U)
Swaps the top two pairs of items.
a b c d -> c d a b
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; let d = b"D"; // swap a and b with c and d OP_2SWAP(a, b, c, d); // Note: moved items retain name let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"D"; OP_EQUALVERIFY(d, expected); let expected = b"C"; OP_EQUALVERIFY(c, expected);
If the top stack value is true, duplicate it. Not to be used in #[bitcoin_cash::script]
functions.
OP_DEPTH() -> Integer
Returns the number of stack items.
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; // number of items on the stack let n = OP_DEPTH(); let expected = 3; OP_EQUALVERIFY(n, expected);
OP_DROP<T>(a: T) -> ()
Drops the top stack item.
a ->
Usage:
let a = b"A"; let b = b"B"; // drop b OP_DROP(b); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_DUP<T>(a: T) -> (T, T)
Duplicates the top stack item.
a -> a a
Usage:
let a = b"A"; // drop b and c OP_DUP(a); // Note: duplicated item retains name let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_NIP<T, U>(a: T, b: U) -> T
Removes the second-to-top stack item.
a b -> b
Usage:
let a = b"A"; let b = b"B"; // drop a OP_NIP(a, __); let expected = b"B"; OP_EQUALVERIFY(b, expected);
OP_OVER<T, U>(a: T, b: U) -> (T, U, T)
Copies the second-to-top stack item to the top of the stack.
a b -> a b a
Usage:
let a = b"A"; let b = b"B"; // copy a OP_OVER(a, __); // Note: duplicated item retains name let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_PICK<T>(n: Integer) -> T
The item n
back in the stack is copied to the top.
xₙ ... x₂ x₁ x₀ <n> -> xₙ ... x₂ x₁ x₀ xₙ
Usage:
let a = b"A"; let b = b"B"; // calculate depth of a let depth_a = depth_of(a); // copy a OP_PICK(depth_a); // Note: duplicated item retains name let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected);
OP_ROLL<T>(n: Integer) -> T
The item n
back in the stack is moved to the top.
xₙ ... x₂ x₁ x₀ <n> -> xₙ₋₁ ... x₂ x₁ x₀ xₙ
Usage:
let a = b"A"; let b = b"B"; // calculate depth of a let depth_a = depth_of(a); // move a to the top of the stack OP_ROLL(depth_a); // Note: moved item retains name let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected);
OP_ROT<T, U, V>(a: T, b: U, c: V) -> (U, V, T)
The third-to-top item is moved to the top.
a b c -> b c a
Usage:
let a = b"A"; let b = b"B"; let c = b"C"; // move a to the top OP_ROT(a, __, __); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"C"; OP_EQUALVERIFY(c, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected);
OP_SWAP<T, U>(a: T, b: U) -> (U, T)
The top two items on the stack are swapped.
a b -> b a
Usage:
let a = b"A"; let b = b"B"; // swap a and b OP_SWAP(a, b); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected);
OP_TUCK<T, U>(a: T, b: U) -> (U, T, U)
The item at the top of the stack is copied and inserted before the second-to-top item.
a b -> b a b
Usage:
let a = b"A"; let b = b"B"; // insert b before a OP_TUCK(__, b); let expected = b"B"; OP_EQUALVERIFY(b, expected); let expected = b"A"; OP_EQUALVERIFY(a, expected); let expected = b"B"; OP_EQUALVERIFY(b, expected);
OP_CAT(left: ByteArray, right: ByteArray) -> ByteArray
Concatenates two byte sequences.
Usage:
let a = b"Bitcoin"; let b = b"Cash"; // concatenate a and b let ab = OP_CAT(a, b); let expected = b"BitcoinCash"; OP_EQUALVERIFY(ab, expected);
OP_SPLIT(array: ByteArray, split_index: Integer) -> (ByteArray, ByteArray)
Split array
at split_index
.
Usage:
let array = b"BitcoinCash"; let split_index = 7; // split array at index 7 let (a, b) = OP_SPLIT(array, split_index); let expected = b"Cash"; OP_EQUALVERIFY(b, expected); let expected = b"Bitcoin"; OP_EQUALVERIFY(a, expected);
OP_NUM2BIN(num: Integer, n_bytes: Integer) -> ByteArray
Convert num
into a byte sequence of size n_bytes
, taking account of
the sign bit. The byte sequence produced uses little-endian encoding.
Usage:
let num = 0x1337; let n_bytes = 2; // encode num as 2 bytes let num2le = OP_NUM2BIN(num, n_bytes); let expected = b"\x37\x13"; OP_EQUALVERIFY(num2le, expected);
OP_BIN2NUM(array: ByteArray) -> Integer
Convert array
into a numeric value, including minimal encoding.
array
must encode the value in little-endian encoding.
Usage:
let num_encoded = b"\x37\x13"; // decode num_encoded let num = OP_BIN2NUM(num_encoded); let expected = 0x1337; OP_EQUALVERIFY(num, expected);
OP_SIZE(array: ByteArray) -> (ByteArray, Integer)
Returns the byte length of array
, retaining array
.
Usage:
let array = b"BitcoinCash"; // calculate size of array let (__, size) = OP_SIZE(array); let expected = 11; OP_EQUALVERIFY(size, expected); let expected = b"BitcoinCash"; OP_EQUALVERIFY(array, expected);
Disabled opcode. Fails script immediately even if not in executed branch.
OP_AND(a: ByteArray, b: ByteArray) -> ByteArray
Boolean AND between each bit of a
and b
.
The two operands must be the same size.
Usage:
let a = b"\x0103"; let b = b"\x0302"; // calculate a & b let bits = OP_AND(a, b); let expected = b"\x0102"; OP_EQUALVERIFY(bits, expected);
OP_OR(a: ByteArray, b: ByteArray) -> ByteArray
Boolean OR between each bit of a
and b
.
The two operands must be the same size.
Usage:
let a = b"\x0103"; let b = b"\x0201"; // calculate a | b let bits = OP_OR(a, b); let expected = b"\x0203"; OP_EQUALVERIFY(bits, expected);
OP_XOR(a: ByteArray, b: ByteArray) -> ByteArray
Boolean XOR between each bit of a
and b
.
The two operands must be the same size.
Usage:
let a = b"\x0103"; let b = b"\x0302"; // calculate a ^ b let bits = OP_XOR(a, b); let expected = b"\x0201"; OP_EQUALVERIFY(bits, expected);
OP_EQUAL<T>(a: T, b: T) -> bool
Returns whether a == b
.
Usage:
let a = b"BitcoinCash"; let b = b"BitcoinCash"; // check if a == b let is_equal = OP_EQUAL(a, b); OP_VERIFY(is_equal);
OP_EQUALVERIFY<T>(a: T, b: T) -> ()
Verifies that a == b
.
Usage:
let a = b"BitcoinCash"; let b = b"BitcoinCash"; // verify that a == b OP_EQUALVERIFY(a, b);
Reserved opcode. Fails script if in executed branch immediately.
Reserved opcode. Fails script if in executed branch immediately.
OP_1ADD(a: Integer) -> Integer
Calculates a + 1
.
Usage:
let a = 7; // calculate a + 1 let result = OP_1ADD(a); let expected = 8; OP_EQUALVERIFY(result, expected);
OP_1SUB(a: Integer) -> Integer
Calculates a - 1
.
Usage:
let a = 7; // calculate a - 1 let result = OP_1SUB(a); let expected = 6; OP_EQUALVERIFY(result, expected);
Disabled opcode. Fails script immediately even if not in executed branch.
Disabled opcode. Fails script immediately even if not in executed branch.
OP_NEGATE(a: Integer) -> Integer
Calculates -a
.
Usage:
let a = 7; // calculate -a let result = OP_NEGATE(a); let expected = -7; OP_EQUALVERIFY(result, expected);
OP_ABS(a: Integer) -> Integer
Calculates abs(a)
.
Usage:
let a = -7; // calculate abs(a) let result = OP_ABS(a); let expected = 7; OP_EQUALVERIFY(result, expected);
OP_NOT(a: Integer) -> Integer
Calculates !a
.
Usage:
let a = false; // calculate !a let result = OP_NOT(a); OP_VERIFY(result);
OP_0NOTEQUAL(a: Integer) -> bool
Calculates a != 0
.
Usage:
let a = 7; // calculate a != 0 let result = OP_0NOTEQUAL(a); OP_VERIFY(result);
OP_ADD(a: Integer, b: Integer) -> Integer
Calculates a + b
.
Usage:
let a = 7; let b = 3; // calculate a + b let result = OP_ADD(a, b); let expected = 10; OP_EQUALVERIFY(result, expected);
OP_SUB(a: Integer, b: Integer) -> Integer
Calculates a - b
.
Usage:
let a = 7; let b = 3; // calculate a - b let result = OP_SUB(a, b); let expected = 4; OP_EQUALVERIFY(result, expected);
Disabled opcode. Fails script immediately even if not in executed branch.
OP_DIV(a: Integer, b: Integer) -> Integer
Calculates a / b
, truncating the fraction part.
Usage:
let a = 7; let b = 3; // calculate a / b let result = OP_DIV(a, b); let expected = 2; OP_EQUALVERIFY(result, expected);
OP_MOD(a: Integer, b: Integer) -> Integer
Calculates a % b
(a modulo b).
Usage:
let a = 7; let b = 3; // calculate a % b let result = OP_MOD(a, b); let expected = 1; OP_EQUALVERIFY(result, expected);
Disabled opcode. Fails script immediately even if not in executed branch.
Disabled opcode. Fails script immediately even if not in executed branch.
OP_BOOLAND(a: bool, b: bool) -> bool
Calculates a && b
, boolean AND (∧).
Usage:
let a = false; let b = true; // calculate a && b let result = OP_BOOLAND(a, b); let expected = false; OP_EQUALVERIFY(result, expected);
OP_BOOLOR(a: bool, b: bool) -> bool
Calculates a || b
, boolean OR (∨).
Usage:
let a = false; let b = true; // calculate a || b let result = OP_BOOLOR(a, b); OP_VERIFY(result);
OP_NUMEQUAL(a: Integer, b: Integer) -> bool
Calculates a == b
.
Usage:
let a = 7; let b = 7; // check if a == b let is_equal = OP_NUMEQUAL(a, b); OP_VERIFY(is_equal);
OP_NUMEQUALVERIFY(a: Integer, b: Integer) -> ()
Verifies that a == b
.
Usage:
let a = 7; let b = 7; // verify that a == b OP_NUMEQUALVERIFY(a, b);
OP_NUMNOTEQUAL(a: Integer, b: Integer) -> bool
Calculates a != b
.
Usage:
let a = 7; let b = 9; // check if a == b let is_not_equal = OP_NUMNOTEQUAL(a, b); OP_VERIFY(is_not_equal);
OP_LESSTHAN(a: Integer, b: Integer) -> bool
Calculates a < b
.
Usage:
let a = 7; let b = 9; // check if a < b let is_less = OP_LESSTHAN(a, b); OP_VERIFY(is_less);
OP_GREATERTHAN(a: Integer, b: Integer) -> bool
Calculates a > b
.
Usage:
let a = 11; let b = 9; // check if a > b let is_greater = OP_GREATERTHAN(a, b); OP_VERIFY(is_greater);
OP_LESSTHANOREQUAL(a: Integer, b: Integer) -> bool
Calculates a <= b
.
Usage:
let a = 7; let b = 7; // check if a <= b let is_at_most = OP_LESSTHANOREQUAL(a, b); OP_VERIFY(is_at_most);
OP_GREATERTHANOREQUAL(a: Integer, b: Integer) -> bool
Calculates a >= b
.
Usage:
let a = 9; let b = 9; // check if a >= b let is_at_least = OP_GREATERTHANOREQUAL(a, b); OP_VERIFY(is_at_least);
OP_MIN(a: Integer, b: Integer) -> bool
Calculates min(a, b)
, the lesser of a
and b
.
Usage:
let a = 3; let b = 9; // calculate min(a, b) let result = OP_MIN(a, b); let expected = 3; OP_EQUALVERIFY(result, expected);
OP_MAX(a: Integer, b: Integer) -> bool
Calculates max(a, b)
, the greater of a
and b
.
Usage:
let a = 3; let b = 9; // calculate max(a, b) let result = OP_MAX(a, b); let expected = 9; OP_EQUALVERIFY(result, expected);
OP_WITHIN(a: Integer, min: Integer, max: Integer) -> bool
Calculates a >= min && a <= max
.
Usage:
let a = 3; let min = 1; let max = 9; // calculate if a is within min and max let result = OP_WITHIN(a, min, max); OP_VERIFY(result);
OP_RIPEMD160(array: ByteArray) -> ByteArray
Hashes array
using RIPEMD-160.
Usage:
let array = b"BitcoinCash"; // calculate ripemd160(array) let hash = OP_RIPEMD160(array); let expected = hex!("0d2aa57463e5fac82f97f496ed98525fbec71c4c"); OP_EQUALVERIFY(hash, expected);
OP_SHA1(array: ByteArray) -> ByteArray
Hashes array
using SHA-1.
Usage:
let array = b"BitcoinCash"; // calculates sha1(array) let hash = OP_SHA1(array); let expected = hex!("a7a1986ab925f4d8a81fc0da1352c780ad2f5fe1"); OP_EQUALVERIFY(hash, expected);
OP_SHA256(array: ByteArray) -> ByteArray
Hashes array
using SHA-256.
Usage:
let array = b"BitcoinCash"; // calculates sha256(array) let hash = OP_SHA256(array); let expected = hex!("78e015aa460c0a5be71fe4618c72898200a45a20f9bd7048398971babc3b372b"); OP_EQUALVERIFY(hash, expected);
OP_HASH160(array: ByteArray) -> ByteArray
Hashes array
using first SHA-256 and then RIPEMD-160.
Usage:
let array = b"BitcoinCash"; // calculates ripemd160(sha256(array)) let hash = OP_HASH160(array); let expected = hex!("29e99ecb43b5a4c19aa2b05c7d6fc439bca5f023"); OP_EQUALVERIFY(hash, expected);
OP_HASH256(array: ByteArray) -> ByteArray
Hashes array
twice using SHA-256.
Usage:
let array = b"BitcoinCash"; // calculates sha256(sha256(array)) let hash = OP_HASH256(array); let expected = hex!("575d8ad02159b76cf2beda18c4ccb9bdb9a7ac894506d97e319c9e5c3096ca37"); OP_EQUALVERIFY(hash, expected);
OP_CODESEPARATOR() -> ()
Makes OP_CHECK(MULTI)SIG(VERIFY)
set scriptCode
to everything after
the most recently-executed OP_CODESEPARATOR
when computing the sighash.
Usage:
let array = b"BitcoinCash"; // removes "BitcoinCash" from scriptCode OP_CODESEPARATOR();
OP_CHECKSIG(public_key: ByteArray, signature: ByteArray) -> bool
The last byte (=sighash type) of signature
is removed.
The sighash for this input is calculated based on the sighash type.
The truncated signature used by OP_CHECKSIG
must be a valid ECDSA or
Schnorr signature for that hash and public_key
. If it is valid, 1 is
returned, if it is empty, 0 is returned, otherwise the operation fails.
Usage:
#[bitcoin_cash::script(P2PKInputs)] fn p2pk(_: (), signature: ByteArray) { let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519"); // check if `signature` signs current sighash for `public_key` let success = OP_CHECKSIG(signature, public_key); }
OP_CHECKSIGVERIFY(public_key: ByteArray, signature: ByteArray) -> ()
The last byte (=sighash type) of signature
is removed.
The sighash for this input is calculated based on the sighash type.
Verifies the truncated signature used by OP_CHECKSIGVERIFY
is a
valid ECDSA or Schnorr signature for that hash and public_key
.
Usage:
#[bitcoin_cash::script(P2PKInputs)] fn p2pk(_: (), signature: ByteArray) { let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519"); // verify `signature` signs current sighash for `public_key` OP_CHECKSIGVERIFY(signature, public_key); }
Performs a multisig check. Not to be used in #[bitcoin_cash::script]
functions.
Verifies a multisig check. Not to be used in #[bitcoin_cash::script]
functions.
OP_NOP1() -> ()
Does nothing.
Usage:
// do nothing OP_NOP1();
OP_CHECKLOCKTIMEVERIFY(locktime: Integer) -> Integer
Marks transaction as invalid if the top stack item is greater than the transaction's
nLockTime
field, otherwise script evaluation continues as though an OP_NOP
was
executed. Transaction is also invalid if
- the stack is empty or
- the top stack item is negative or
- the top stack item is greater than or equal to 500000000 while the transaction's
nLockTime
field is less than 500000000, or vice versa or - the input's nSequence field is equal to 0xffffffff.
The precise semantics are described in BIP65.
Usage:
let locktime = 400_000; // verify locktime OP_CHECKLOCKTIMEVERIFY(locktime); let expected = 400_000; OP_EQUALVERIFY(locktime, expected);
OP_CHECKSEQUENCEVERIFY(sequence: Integer) -> Integer
Marks transaction as invalid if the relative lock time of the input
(enforced by BIP68 with nSequence
) is not equal to or longer than
the value of the top stack item. The precise semantics are described
in BIP112.
Usage:
let sequence = 1000; // verify input age OP_CHECKSEQUENCEVERIFY(sequence); let expected = 1000; OP_EQUALVERIFY(sequence, expected);
OP_NOP4() -> ()
Does nothing.
Usage:
// do nothing OP_NOP4();
OP_NOP5() -> ()
Does nothing.
Usage:
// do nothing OP_NOP5();
OP_NOP6() -> ()
Does nothing.
Usage:
// do nothing OP_NOP6();
OP_NOP7() -> ()
Does nothing.
Usage:
// do nothing OP_NOP7();
OP_NOP8() -> ()
Does nothing.
Usage:
// do nothing OP_NOP8();
OP_NOP9() -> ()
Does nothing.
Usage:
// do nothing OP_NOP9();
OP_NOP10() -> ()
Does nothing.
Usage:
// do nothing OP_NOP10();
OP_CHECKDATASIG(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> bool
Checks whether signature
is a valid ECDSA or Schnorr signature for sha256(message)
and public_key
.
Usage:
let signature = [ hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(), hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(), ].concat(); let message = b"BitcoinCash"; let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496"); let is_valid_sig = OP_CHECKDATASIG(signature, message, public_key);
OP_CHECKDATASIGVERIFY(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> ()
Verifies that signature
is a valid ECDSA or Schnorr signature for sha256(message)
and public_key
.
Usage:
let signature = [ hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(), hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(), ].concat(); let message = b"BitcoinCash"; let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496"); OP_CHECKDATASIGVERIFY(signature, message, public_key);
OP_REVERSEBYTES(array: ByteArray) -> ByteArray
Reverse array
.
Usage:
let array = b"BitcoinCash"; // reverse array let reversed = OP_REVERSEBYTES(array); let expected = b"hsaCnioctiB"; OP_EQUALVERIFY(reversed, expected);
The first op_code value after all defined opcodes
Implementations
impl Opcode
[src]
pub fn is_disabled(self) -> bool
[src]
pub fn retains_input(self) -> bool
[src]
pub fn behavior(self) -> OpcodeBehavior
[src]
Trait Implementations
impl Clone for Opcode
[src]
impl Copy for Opcode
[src]
impl Debug for Opcode
[src]
impl Eq for Opcode
[src]
impl FromPrimitive for Opcode
[src]
fn from_i64(n: i64) -> Option<Opcode>
[src]
fn from_u64(n: u64) -> Option<Opcode>
[src]
fn from_isize(n: isize) -> Option<Self>
[src]
fn from_i8(n: i8) -> Option<Self>
[src]
fn from_i16(n: i16) -> Option<Self>
[src]
fn from_i32(n: i32) -> Option<Self>
[src]
fn from_i128(n: i128) -> Option<Self>
[src]
fn from_usize(n: usize) -> Option<Self>
[src]
fn from_u8(n: u8) -> Option<Self>
[src]
fn from_u16(n: u16) -> Option<Self>
[src]
fn from_u32(n: u32) -> Option<Self>
[src]
fn from_u128(n: u128) -> Option<Self>
[src]
fn from_f32(n: f32) -> Option<Self>
[src]
fn from_f64(n: f64) -> Option<Self>
[src]
impl Hash for Opcode
[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Opcode
[src]
fn cmp(&self, other: &Opcode) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Opcode> for Opcode
[src]
impl PartialOrd<Opcode> for Opcode
[src]
Auto Trait Implementations
impl RefUnwindSafe for Opcode
impl Send for Opcode
impl Sync for Opcode
impl Unpin for Opcode
impl UnwindSafe for Opcode
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,