A Rust library providing utilities for working with Tondi blockchain opcodes. This module extends the functionality of the tondi-txscript crate with additional helper functions and macros for opcode manipulation and conversion.
- Push Opcode Detection: Functions to identify push bytes and push data opcodes
- String Conversion: Macro-generated function for converting string representations to opcode values
- Comprehensive Opcode Support: Covers all standard Tondi opcodes including data operations, stack manipulation, arithmetic, and cryptographic functions
- Alias Support: Multiple string representations for common opcodes (e.g., "Op0", "FALSE", "TRUE")
Add this dependency to your Cargo.toml:
[dependencies]
tondi-opcode-utils = "0.17.0"This library depends on:
tondi-txscript = "0.17.0"- Core Tondi transaction script functionality
use tondi_opcode_utils::{is_push_bytes, is_push_data};
// Check if an opcode is a push bytes opcode (0x01-0x4b)
let is_push = is_push_bytes(0x01); // true
let is_not_push = is_push_bytes(0x61); // false (OpNop)
// Check if an opcode is a push data opcode
let is_push_data = is_push_data(0x4c); // true (OP_PUSH_DATA1)use tondi_opcode_utils::from_str;
// Convert string representations to opcode values
let opcode = from_str("Op0").unwrap(); // Returns 0x00
let opcode = from_str("TRUE").unwrap(); // Returns 0x51
let opcode = from_str("OpFalse").unwrap(); // Returns 0x00
// Supports both prefixed and non-prefixed formats
let opcode1 = from_str("OpAdd").unwrap(); // Returns 0x93
let opcode2 = from_str("Add").unwrap(); // Returns 0x93- Push Operations:
OpData1throughOpData75,OP_PUSH_DATA1,OP_PUSH_DATA2,OP_PUSH_DATA4 - Constants:
OpFalse(0x00),OpTrue(0x51),Op1Negate(0x4f)
- Duplication:
OpDup,Op2Dup,Op3Dup,OpIfDup - Movement:
OpDrop,Op2Drop,OpNip,OpOver,OpPick,OpRoll,OpRot,OpSwap,OpTuck - Stack Info:
OpDepth,OpSize
- Basic Math:
OpAdd,OpSub,OpMul,OpDiv,OpMod - Bitwise:
OpAnd,OpOr,OpXor,OpInvert - Comparison:
OpEqual,OpNumEqual,OpLessThan,OpGreaterThan - Increment/Decrement:
Op1Add,Op1Sub,Op2Mul,Op2Div
- Conditionals:
OpIf,OpNotIf,OpElse,OpEndIf - Verification:
OpVerify,OpEqualVerify,OpNumEqualVerify - Time Locks:
OpCheckLockTimeVerify,OpCheckSequenceVerify
- Hashing:
OpSHA256,OpBlake3 - Signatures:
OpCheckSig,OpCheckSigVerify,OpCheckMultiSig,OpCheckMultiSigVerify - ECDSA:
OpCheckSigECDSA,OpCheckMultiSigECDSA
Determines if the given opcode is a push bytes opcode (0x01-0x4b).
Determines if the given opcode is one of the push data opcodes (0x4c, 0x4d, 0x4e).
Converts a string representation of an opcode to its byte value. Returns Err(()) if the string is not recognized.
OP_PUSH_DATA1: 0x4cOP_PUSH_DATA2: 0x4dOP_PUSH_DATA4: 0x4e
- The library uses workarounds to determine opcode classes due to limited access to internal
Opcodestruct values - String conversion supports multiple aliases for common opcodes
- All opcodes are defined as constants with their hexadecimal values
- Reserved and undefined opcodes are marked appropriately
This project is licensed under the terms specified in the LICENSE file.
Contributions are welcome! Please feel free to submit issues and pull requests.
- Tondi - Core Tondi blockchain implementation
- tondi-txscript - Tondi transaction script functionality