pub struct Address(/* private fields */);Expand description
An Address is just a H256 with a different name. Has a different ABI name than H256.
Note: we are currently using ManagedAddress in contracts. While this also works, its use in contracts is discouraged.
Implementations§
Source§impl Address
impl Address
Sourcepub const fn from_hex(hex_str: &str) -> Address
pub const fn from_hex(hex_str: &str) -> Address
Constructs an Address from a hex string at compile time. The hex string can optionally start with “0x” or “0X”. The hex string must represent exactly 32 bytes (64 hex characters).
§Panics
Panics at compile time if:
- The hex string is not exactly 64 characters (excluding optional “0x” prefix)
- Any character is not a valid hex digit (0-9, a-f, A-F)
§Example
const ADDR: Address = Address::from_hex("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
const ADDR_WITH_PREFIX: Address = Address::from_hex("0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");Sourcepub fn shard_of_3(&self) -> ShardId
pub fn shard_of_3(&self) -> ShardId
Returns the shard ID of this address in a 3-shard configuration.
Sourcepub fn to_bech32(&self, hrp: &str) -> Bech32Address
pub fn to_bech32(&self, hrp: &str) -> Bech32Address
Encodes the address as a bech32 string using the given human-readable part (HRP).
Sourcepub fn to_bech32_default(&self) -> Bech32Address
pub fn to_bech32_default(&self) -> Bech32Address
Encodes the address as a bech32 string using the default HRP (erd).
Source§impl Address
impl Address
Sourcepub fn from_slice(slice: &[u8]) -> Address
pub fn from_slice(slice: &[u8]) -> Address
Constructs an Address from a byte slice. Pads with zeros if shorter than 32 bytes,
truncates if longer.
Source§impl Address
impl Address
Sourcepub fn zero() -> Address
pub fn zero() -> Address
Returns a new address of 32 zeros. Allocates directly in heap. Minimal resulting wasm code (14 bytes if not inlined).
Sourcepub fn copy_to_array(&self, target: &mut [u8; 32])
pub fn copy_to_array(&self, target: &mut [u8; 32])
Copies the address bytes into the provided 32-byte array.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Returns an unsafe mutable pointer to the data on the heap. Used by the API to populate data.
Sourcepub fn is_smart_contract_address(&self) -> bool
pub fn is_smart_contract_address(&self) -> bool
Returns true if this address belongs to a smart contract. A smart contract address has its first 8 bytes set to zero.
Sourcepub fn is_smart_contract_on_metachain(&self) -> bool
pub fn is_smart_contract_on_metachain(&self) -> bool
Returns true if this is a smart contract address deployed on the metachain. Conditions:
- The last two bytes are both 0xFF (metachain identifier).
- The address is a smart contract address (first 8 bytes are zero).
- Bytes [10..25] (the “on-meta” region) are all zero.
Trait Implementations§
impl Eq for Address
Source§impl NestedDecode for Address
impl NestedDecode for Address
Source§fn dep_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<Address, <H as DecodeErrorHandler>::HandledErr>where
I: NestedDecodeInput,
H: DecodeErrorHandler,
fn dep_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<Address, <H as DecodeErrorHandler>::HandledErr>where
I: NestedDecodeInput,
H: DecodeErrorHandler,
dep_decode that can handle errors as soon as they occur.
For instance in 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.Source§fn dep_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: NestedDecodeInput,
fn dep_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: NestedDecodeInput,
Source§impl NestedEncode for Address
impl NestedEncode for Address
Source§fn dep_encode_or_handle_err<O, H>(
&self,
dest: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: NestedEncodeOutput,
H: EncodeErrorHandler,
fn dep_encode_or_handle_err<O, H>(
&self,
dest: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: NestedEncodeOutput,
H: EncodeErrorHandler,
dep_encode that can handle errors as soon as they occur.
For instance in 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.Source§fn dep_encode<O>(&self, dest: &mut O) -> Result<(), EncodeError>where
O: NestedEncodeOutput,
fn dep_encode<O>(&self, dest: &mut O) -> Result<(), EncodeError>where
O: NestedEncodeOutput,
impl StructuralPartialEq for Address
Source§impl TopDecode for Address
impl TopDecode for Address
Source§fn top_decode_or_handle_err<I, H>(
input: I,
h: H,
) -> Result<Address, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeInput,
H: DecodeErrorHandler,
fn top_decode_or_handle_err<I, H>(
input: I,
h: H,
) -> Result<Address, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeInput,
H: DecodeErrorHandler,
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.Source§fn top_decode<I>(input: I) -> Result<Self, DecodeError>where
I: TopDecodeInput,
fn top_decode<I>(input: I) -> Result<Self, DecodeError>where
I: TopDecodeInput,
Source§impl TopEncode for Address
impl TopEncode for Address
Source§fn top_encode_or_handle_err<O, H>(
&self,
output: O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeOutput,
H: EncodeErrorHandler,
fn top_encode_or_handle_err<O, H>(
&self,
output: O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeOutput,
H: EncodeErrorHandler,
top_encode that can handle errors as soon as they occur.
For instance in 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.Source§fn top_encode<O>(&self, output: O) -> Result<(), EncodeError>where
O: TopEncodeOutput,
fn top_encode<O>(&self, output: O) -> Result<(), EncodeError>where
O: TopEncodeOutput,
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> MultiValueConstLength for T
impl<T> MultiValueConstLength for T
Source§const MULTI_VALUE_CONST_LEN: usize = 1
const MULTI_VALUE_CONST_LEN: usize = 1
Source§impl<T> MultiValueLength for T
impl<T> MultiValueLength for T
Source§fn multi_value_len(&self) -> usize
fn multi_value_len(&self) -> usize
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)Source§impl<T> TopDecodeMulti for Twhere
T: TopDecode,
impl<T> TopDecodeMulti for Twhere
T: TopDecode,
Source§const IS_SINGLE_VALUE: bool = true
const IS_SINGLE_VALUE: bool = true
fn multi_decode_or_handle_err<I, H>(
input: &mut I,
h: H,
) -> Result<T, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeMultiInput,
H: DecodeErrorHandler,
fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: TopDecodeMultiInput,
Source§impl<T> TopEncodeMulti for Twhere
T: TopEncode,
impl<T> TopEncodeMulti for Twhere
T: TopEncode,
Source§fn multi_encode_or_handle_err<O, H>(
&self,
output: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
fn multi_encode_or_handle_err<O, H>(
&self,
output: &mut O,
h: H,
) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where
O: TopEncodeMultiOutput,
H: EncodeErrorHandler,
top_encode that can handle errors as soon as they occur.
For instance in 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.