Struct Address

Source
pub struct Address(/* private fields */);
Expand description

A struct representing a blockchain address. This struct provides various utility methods for working with addresses, including conversions from and to Bech32 string representations and byte arrays.

§Serialization

This struct is serializable with the serde crate.

§Cloning

Cloning is supported.

§Debugging

Debug printouts are supported.

§Examples

Basic usage:

let address = Address::from_bech32_string("erd1qqqqqqqqqqqqqpgq7ykazrzd905zvnlr88dpfw06677lxe9w0n4suz00uh").unwrap();
let bech32 = address.to_bech32_string().unwrap();
assert_eq!(bech32, "erd1qqqqqqqqqqqqqpgq7ykazrzd905zvnlr88dpfw06677lxe9w0n4suz00uh");

Implementations§

Source§

impl Address

The Address struct provides an abstraction over a blockchain address, with various utility methods for working with addresses.

Source

pub fn from_bech32_string(bech32: &str) -> Result<Address, DataError>

Creates an Address instance from a Bech32 string representation.

§Parameters
  • bech32: The Bech32 string representation of the address.
§Returns
  • An Ok(Address) instance if the conversion is successful.
  • An Err(DataError) if the Bech32 string is invalid.
§Example
let address = Address::from_bech32_string("erd1qqqqqqqqqqqqqpgq7ykazrzd905zvnlr88dpfw06677lxe9w0n4suz00uh").unwrap();
Source

pub fn from_bytes(bytes: [u8; 32]) -> Address

Creates an Address instance from a byte array.

§Parameters
  • bytes: A byte array of length 32.
§Returns
  • An Address instance.
§Example
let address = Address::from_bytes([0_u8; 32]);
Source

pub fn to_bech32_string(&self) -> Result<String, DataError>

Converts the Address instance to a Bech32 string representation.

§Returns
  • An Ok(String) containing the Bech32 string representation if successful.
  • An Err(DataError) if the conversion fails.
§Example
let bech32_string = address.to_bech32_string().unwrap();
Source

pub fn to_bytes(&self) -> [u8; 32]

Converts the Address instance to a byte array.

§Returns
  • A byte array of length 32.
§Example
let bytes = address.to_bytes();
assert_eq!(bytes, [0_u8; 32]);

Methods from Deref<Target = Address>§

Source

pub fn to_bytes(&self) -> [u8; 32]

Source

pub fn to_bech32_string(&self) -> Result<String, Error>

Source

pub fn is_valid(&self) -> bool

Trait Implementations§

Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Address

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Address

Source§

type Target = Address

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> Deserialize<'a> for Address

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'a>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&Address> for Address

Source§

fn from(value: &SDKAddress) -> Self

Converts to this type from the input type.
Source§

impl From<&Address> for Address

Source§

fn from(value: &Address) -> Self

Converts to this type from the input type.
Source§

impl From<&Address> for AddressValue

Source§

fn from(value: &Address) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for Address

Source§

fn from(value: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Address

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for Address

Source§

fn from(value: SDKAddress) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for Address

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for Address

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl Hash for Address

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl ManagedConvertible<ManagedAddress<VMHooksApi<StaticApiBackend>>> for Address

Source§

fn to_managed(&self) -> ManagedAddress<StaticApi>

Converts the native Rust type to the specified managed type.
Source§

impl NativeConvertible for Address

Source§

type Native = Address

The native Rust type to which the managed type will be converted.
Source§

fn to_native(&self) -> Self::Native

Converts the managed type to the specified native Rust type.
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Address

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TopDecode for Address

Source§

fn top_decode<I>(input: I) -> Result<Self, DecodeError>
where I: TopDecodeInput,

Attempt to deserialize the value from input.
Source§

fn top_decode_or_handle_err<I, H>( input: I, h: H, ) -> Result<Self, <H as DecodeErrorHandler>::HandledErr>

Version of top_decode that can handle errors as soon as they occur. For instance it can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> InterpretableFrom<&T> for T
where T: Clone,

Source§

fn interpret_from(from: &T, _context: &InterpreterContext) -> T

Source§

impl<T> InterpretableFrom<T> for T

Source§

fn interpret_from(from: T, _context: &InterpreterContext) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ReconstructableFrom<&T> for T
where T: Clone,

Source§

impl<T> ReconstructableFrom<T> for T

Source§

fn reconstruct_from(from: T, _builder: &ReconstructorContext) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TopDecodeMulti for T
where T: TopDecode,

Source§

const IS_SINGLE_VALUE: bool = true

Used to optimize single value loading of endpoint arguments.
Source§

fn multi_decode_or_handle_err<I, H>( input: &mut I, h: H, ) -> Result<T, <H as DecodeErrorHandler>::HandledErr>

Source§

fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T