Module neo_types

Source
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§

contract
error
nns
script_hash
serde_value
serde_with_utils

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 a StackItem::Map.
Metadata
Metadata about a log message.
MetadataBuilder
Builder for Metadata.
OperandSize
ParseLevelError
The type returned by from_str when the string doesn’t match any of the log levels.
Record
The “payload” of a log message.
RecordBuilder
Builder for Record.
ScryptParamsDef
SetLoggerError
The type returned by set_logger if set_logger has already been called.
SyncProgress
Represents the sync status of the node
TxPoolInspectSummary
Transaction summary as found in the Txpool Inspection property.
TxpoolContent
Transaction Pool Content
TxpoolInspect
Transaction Pool Inspect
TxpoolStatus
Transaction Pool Status
URLSession

Enums§

AddressOrScriptHash
An enum that can represent either a blockchain Address or a ScriptHash, offering flexibility for APIs that can work with either.
Level
An enum representing the available verbosity levels of the logger.
LevelFilter
An enum representing the available verbosity level filters of the logger.
NameOrAddress
NodePluginType
OpCode
PathOrString
A type that can either be a Path or a String
StackItem
The StackItem enum represents an item on the Neo virtual machine stack.
SyncingStatus
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§

AddressExtension
Base64Encode
ExternBase64
Log
A trait encapsulating the operations required of a logger.
ReverseTrait
StringExt
ToBase58
ToBase64
ToBytes
Trait to convert types to byte vectors.
ToBytesPadded
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 a U256 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 another U256.
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.

Type Aliases§

Address
Byte
Bytes
TxHash