Trait AddressExtension

Source
pub trait AddressExtension {
    // Required methods
    fn address_to_script_hash(&self) -> Result<ScriptHash, TypeError>;
    fn script_to_script_hash(&self) -> Result<ScriptHash, TypeError>;
    fn hex_to_script_hash(&self) -> Result<ScriptHash, TypeError>;
    fn random() -> Self;
}

Required Methods§

Source

fn address_to_script_hash(&self) -> Result<ScriptHash, TypeError>

Converts a Base58-encoded address (common in many blockchain systems) to a ScriptHash.

§Examples

Basic usage:

use neo3::neo_types::AddressExtension;
// Example with a valid Neo N3 address format
let address = "NNLi44dJNXtDNSBkofB48aTVYtb1zZrNEs";
let result = address.address_to_script_hash();
// This demonstrates the function's capability to convert addresses
Source

fn script_to_script_hash(&self) -> Result<ScriptHash, TypeError>

Decodes a hex-encoded script into a ScriptHash, demonstrating error handling for invalid hex strings.

§Examples

Basic usage:

use neo3::neo_types::AddressExtension;
let script = "abcdef1234567890";
let script_hash = script.script_to_script_hash().unwrap();
Source

fn hex_to_script_hash(&self) -> Result<ScriptHash, TypeError>

Validates a hex string and converts it to a ScriptHash, showcasing error handling for non-hex strings.

§Examples

Basic usage:

use neo3::neo_types::AddressExtension;
let hex_string = "abcdef1234567890abcdef1234567890abcdef12";
let script_hash = hex_string.hex_to_script_hash().unwrap();
Source

fn random() -> Self

Generates a random address using cryptographic-safe random number generation, ideal for creating new wallet addresses.

§Examples

Basic usage:

use neo3::neo_types::AddressExtension;
let random_address = String::random();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AddressExtension for &str

Source§

impl AddressExtension for String

Implementors§