neo_solidity/runtime/
spec.rs

1//! Neo N3 opcode/syscall/native-contract registry
2
3use once_cell::sync::Lazy;
4use std::collections::HashMap;
5
6use crate::codegen::interop_id_bytes;
7
8/// Opcode metadata (lightweight – only what the runtime needs today).
9#[derive(Debug, Clone, Copy)]
10pub struct OpcodeSpec {
11    pub code: u8,
12    pub name: &'static str,
13    pub gas: u64,
14}
15
16impl OpcodeSpec {
17    /// Check if this is a push opcode
18    pub fn is_push(&self) -> bool {
19        self.code <= 0x20 || (self.code >= 0x0C && self.code <= 0x0E)
20    }
21
22    /// Check if this is a jump opcode
23    pub fn is_jump(&self) -> bool {
24        self.code >= 0x22 && self.code <= 0x33
25    }
26
27    /// Check if this is a call opcode
28    pub fn is_call(&self) -> bool {
29        self.code >= 0x34 && self.code <= 0x37
30    }
31}
32
33/// Syscall metadata.
34#[derive(Debug, Clone, Copy)]
35pub struct SyscallSpec {
36    pub id: [u8; 4],
37    pub name: &'static str,
38}
39
40impl SyscallSpec {
41    /// Get the syscall ID as hex string
42    pub fn id_hex(&self) -> String {
43        hex::encode(self.id)
44    }
45}
46
47/// Native contract metadata.
48#[derive(Debug, Clone, Copy)]
49pub struct NativeContractSpec {
50    pub hash: [u8; 20],
51    pub name: &'static str,
52}
53
54impl NativeContractSpec {
55    /// Get the contract hash as hex string
56    pub fn hash_hex(&self) -> String {
57        hex::encode(self.hash)
58    }
59}
60
61include!("spec/opcodes.rs");
62include!("spec/syscalls.rs");
63include!("spec/native_contracts.rs");
64include!("spec/gas.rs");
65
66#[cfg(test)]
67mod tests;