Module neo_protocol

Source
Expand description

§Neo Protocol

Core protocol types and interfaces for the Neo N3 blockchain.

§Overview

The neo_protocol module provides the core types and interfaces for interacting with the Neo N3 blockchain protocol. It includes:

  • Account management and address handling
  • NEP-2 password-protected key format support
  • Protocol error definitions and handling
  • Response types for Neo N3 RPC calls
  • Role-based access control definitions

This module forms the foundation for blockchain interactions, defining the data structures and interfaces that represent the Neo N3 protocol.

§Examples

§Working with Neo N3 accounts

use neo3::neo_protocol::{Account, AccountTrait};

// Create a new account
let account = Account::create().unwrap();
println!("Address: {}", account.address());
println!("Script Hash: {}", account.script_hash());

// Create an account from a WIF (Wallet Import Format) string
let wif = "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7";
let account = Account::from_wif(wif).unwrap();

// Sign a message
let message = b"Hello, Neo!";
let signature = account.sign(message).unwrap();

// Verify the signature
let is_valid = account.verify(message, &signature).unwrap();
assert!(is_valid);

§Using NEP-2 password-protected keys

use neo3::neo_crypto::PrivateKey;
use neo3::neo_protocol::nep2::{encrypt_to_nep2, decrypt_from_nep2};

// Encrypt a private key with a password (NEP-2 format)
let private_key = PrivateKey::from_slice(&[/* 32 bytes */]).unwrap();
let password = "your_secure_password_here";
let nep2_string = encrypt_to_nep2(&private_key, password).unwrap();

// Decrypt a NEP-2 string back to a private key
let nep2_string = "6PYVPVe1fQznphjbUxXP9KZJqPMVnVwCx5s5pr5axRJ8uHkMtZg97eT5kL";
let password = "your_secure_password_here";
let private_key = decrypt_from_nep2(nep2_string, password).unwrap();

Structs§

Account
AccountState
AddressEntry
ApplicationLog
Balance
Claim
Claimables
ConflictsAttribute
Diagnostics
Execution
ExpressContractState
ExpressShutdown
HardForks
HighPriorityAttribute
InvokedContract
LogNotification
MemPoolDetails
NEP2
NEP2 provides methods for encrypting and decrypting NEO private keys according to the NEP2 standard specification.
NeoAddress
NeoBlock
NeoNetworkFee
NeoProtocol
NeoTransactionSigner
NeoVersion
NeoWitness
Nep11Balance
Nep11Balances
Nep11Token
Nep11Transfer
Nep11Transfers
Nep17Balance
Nep17Balances
Nep17Transfer
Nep17Transfers
NotValidBeforeAttribute
OracleRequest
OracleResponse
OracleResponseAttribute
Peers
Plugin
PopulatedBlocks
RTransaction
RTransactionSigner
RawTransaction
StateHeight
StateResult
StateRoot
States
StorageChange
SubmitBlock
TransactionResult
UnclaimedGas
UnspentTransaction
Unspents
ValidateAddress
Validator

Enums§

ProtocolError
TransactionAttributeEnum
TransactionAttributeType

Traits§

AccountTrait
TokenBalance
TokenBalances
TokenTransfer
TokenTransfers

Functions§

get_nep2_from_private_key
Compatibility functions to maintain backward compatibility with existing code These functions are provided for convenience and compatibility with the old API Encrypts a private key in hexadecimal format using NEP2.
get_private_key_from_nep2
Decrypts a NEP2-formatted string to retrieve the original private key.