Expand description
§Neo Types (v0.4.1)
Core data types for the Neo N3 blockchain.
§Overview
The neo_types module provides fundamental data types and structures for working with the Neo N3 blockchain. It includes:
- Address and ScriptHash types for identifying accounts and contracts
- Contract-related types (parameters, manifests, NEF files)
- Neo Name Service (NNS) types
- Numeric types with blockchain-specific operations
- Serialization and deserialization utilities
- Stack item representations for VM operations
- Blockchain-specific enumerations (OpCode, VMState)
This module forms the type foundation for the entire SDK, providing the core data structures that represent Neo N3 blockchain concepts.
§Examples
§Working with Neo N3 addresses and script hashes
use neo3::prelude::*;
use std::str::FromStr;
// Create a script hash from a string
let script_hash = ScriptHash::from_str("0xd2a4cff31913016155e38e474a2c06d08be276cf").unwrap();
println!("Script hash: {}", script_hash);
// Convert between address and script hash
let address = script_hash.to_address();
println!("Address: {}", address);
let recovered_hash = ScriptHash::from_str(&address).unwrap();
assert_eq!(script_hash, recovered_hash);
§Working with contract parameters
use neo3::prelude::*;
use std::str::FromStr;
// Create different types of contract parameters
let string_param = ContractParameter::string("Hello, Neo!".to_string());
let integer_param = ContractParameter::integer(42);
let bool_param = ContractParameter::bool(true);
// Create a parameter array for a contract invocation
let params = vec![string_param, integer_param, bool_param];
§Working with stack items
ⓘ
use neo3::neo_types::StackItem;
use serde_json::json;
// Create stack items of various types
let int_item = StackItem::Integer { value: 123 };
let bool_item = StackItem::Boolean { value: true };
let bytes_item = StackItem::new_byte_string(b"Neo".to_vec());
// Convert between stack items and JSON values
let json_value = int_item.to_json_value();
assert_eq!(json_value, json!(123));
Re-exports§
pub use script_hash::ScriptHash;
pub use script_hash::ScriptHashExtension;
pub use serde_with_utils::deserialize_h160;
pub use serde_with_utils::deserialize_h256;
pub use serde_with_utils::deserialize_script_hash;
pub use serde_with_utils::deserialize_u256;
pub use serde_with_utils::deserialize_u64;
pub use serde_with_utils::deserialize_vec_h256;
pub use serde_with_utils::deserialize_vec_u256;
pub use serde_with_utils::deserialize_wildcard;
pub use serde_with_utils::serialize_h160;
pub use serde_with_utils::serialize_h256;
pub use serde_with_utils::serialize_script_hash;
pub use serde_with_utils::serialize_u256;
pub use serde_with_utils::serialize_u64;
pub use serde_with_utils::serialize_vec_h256;
pub use serde_with_utils::serialize_vec_u256;
pub use serde_with_utils::serialize_wildcard;
pub use serde_value::ValueExtension;
pub use contract::*;
pub use error::*;
pub use nns::*;
pub use serde_value::*;
pub use serde_with_utils::*;
Modules§
Macros§
- debug
- Logs a message at the debug level.
- error
- Logs a message at the error level.
- info
- Logs a message at the info level.
- log
- The standard logging macro.
- log_
enabled - Determines if a message logged at the specified level in that module will be logged.
- trace
- Logs a message at the trace level.
- warn
- Logs a message at the warn level.
Structs§
- MapEntry
- The
MapEntry
struct represents a key-value pair in aStackItem::Map
. - Metadata
- Metadata about a log message.
- Metadata
Builder - Builder for
Metadata
. - Operand
Size - Parse
Level Error - The type returned by
from_str
when the string doesn’t match any of the log levels. - Record
- The “payload” of a log message.
- Record
Builder - Builder for
Record
. - Scrypt
Params Def - SetLogger
Error - The type returned by
set_logger
ifset_logger
has already been called. - Sync
Progress - Represents the sync status of the node
- TxPool
Inspect Summary - Transaction summary as found in the Txpool Inspection property.
- Txpool
Content - Transaction Pool Content
- Txpool
Inspect - Transaction Pool Inspect
- Txpool
Status - Transaction Pool Status
- URLSession
Enums§
- Address
OrScript Hash - An enum that can represent either a blockchain
Address
or aScriptHash
, offering flexibility for APIs that can work with either. - Level
- An enum representing the available verbosity levels of the logger.
- Level
Filter - An enum representing the available verbosity level filters of the logger.
- Name
OrAddress - Node
Plugin Type - OpCode
- Path
OrString - A type that can either be a
Path
or aString
- Stack
Item - The
StackItem
enum represents an item on the Neo virtual machine stack. - Syncing
Status - Structure used in
neo_syncing
RPC - VMState
- Represents the state of a virtual machine.
Constants§
- STATIC_
MAX_ LEVEL - The statically resolved maximum log level.
Traits§
- Address
Extension - Base64
Encode - Extern
Base64 - Log
- A trait encapsulating the operations required of a logger.
- Reverse
Trait - String
Ext - ToBase58
- ToBase64
- ToBytes
- Trait to convert types to byte vectors.
- ToBytes
Padded - Trait to convert types to padded byte vectors.
Functions§
- bytes_
to_ string - Converts a byte slice into a hexadecimal string prefixed with “0x”.
- encode_
string_ h160 - Encodes an
H160
hash into a string representation. - encode_
string_ h256 - Encodes an
H256
hash into a string representation. - encode_
string_ u256 - Encodes a
U256
value into a hexadecimal string prefixed with “0x”. - encode_
vec_ string_ vec_ u256 - Encodes a vector of
U256
values into a vector of hexadecimal strings. - from_
script_ hash - h256_
to_ u256 - Converts an
H256
hash into aU256
value. - logger
- Returns a reference to the logger.
- max_
level - Returns the current maximum log level.
- parse_
address - Converts a hexadecimal string representation of an address into a
ScriptHash
. - parse_
string_ h160 - Parses a hexadecimal string into an
H160
hash, padding with zeros if necessary. - parse_
string_ h256 - Parses a hexadecimal string into an
H256
hash, padding with zeros if necessary. - parse_
string_ u64 - Parses a string into a
u64
, supporting both decimal and hexadecimal (prefixed with “0x”) formats. - parse_
string_ u256 - Parses a string into a
U256
, accepting both decimal and hex (prefixed with “0x”) formats. - parse_
vec_ string_ vec_ u256 - Parses a vector of hexadecimal string representations into a vector of
U256
values. - set_
boxed_ logger - Sets the global logger to a
Box<Log>
. - set_
logger - Sets the global logger to a
&'static Log
. - set_
logger_ ⚠racy - A thread-unsafe version of
set_logger
. - set_
max_ level - Sets the global maximum log level.
- set_
max_ ⚠level_ racy - A thread-unsafe version of
set_max_level
. - string_
to_ bytes - Attempts to convert a hexadecimal string (optionally prefixed with “0x”) into a byte vector.
- to_
checksum - u256_
min - Returns the minimum of two
U256
values. - u256_
sqrt - Calculates the square root of a
U256
value, returning anotherU256
. - var_
size - Calculates the size of a variable as the number of bytes required to represent it.
- vec_
to_ array32 - Converts a vector of bytes into an array of 32 bytes. Returns an error if the vector is not exactly 32 bytes long.