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§
Sourcefn address_to_script_hash(&self) -> Result<ScriptHash, TypeError>
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
Sourcefn script_to_script_hash(&self) -> Result<ScriptHash, TypeError>
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();
Sourcefn hex_to_script_hash(&self) -> Result<ScriptHash, TypeError>
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();
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.