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§
Source§impl<Env> AnnotatedValue<Env, ManagedAddress<<Env as TxEnv>::Api>> for &Addresswhere
Env: TxEnv,
impl<Env> AnnotatedValue<Env, ManagedAddress<<Env as TxEnv>::Api>> for &Addresswhere
Env: TxEnv,
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api>
Source§fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api>
fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api>
.clone() in some cases.Source§fn into_value(self, env: &Env) -> T
fn into_value(self, env: &Env) -> T
Source§impl<Env> AnnotatedValue<Env, ManagedAddress<<Env as TxEnv>::Api>> for Addresswhere
Env: TxEnv,
impl<Env> AnnotatedValue<Env, ManagedAddress<<Env as TxEnv>::Api>> for Addresswhere
Env: TxEnv,
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api>
Source§fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api>
fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api>
.clone() in some cases.Source§fn into_value(self, env: &Env) -> T
fn into_value(self, env: &Env) -> T
Source§impl From<&Address> for Bech32Address
impl From<&Address> for Bech32Address
Source§fn from(value: &Address) -> Bech32Address
fn from(value: &Address) -> Bech32Address
Source§impl<M> From<&Address> for ManagedAddress<M>where
M: ManagedTypeApi,
impl<M> From<&Address> for ManagedAddress<M>where
M: ManagedTypeApi,
Source§impl From<Address> for Bech32Address
impl From<Address> for Bech32Address
Source§fn from(value: Address) -> Bech32Address
fn from(value: Address) -> Bech32Address
Source§impl<M> From<Address> for ManagedAddress<M>where
M: ManagedTypeApi,
impl<M> From<Address> for ManagedAddress<M>where
M: ManagedTypeApi,
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,
Source§impl PartialEq<Address> for Bech32Address
impl PartialEq<Address> for Bech32Address
Source§impl PartialEq<Address> for TestAddress<'_>
impl PartialEq<Address> for TestAddress<'_>
Source§impl PartialEq<Address> for TestSCAddress<'_>
impl PartialEq<Address> for TestSCAddress<'_>
Source§impl<'a> PartialEq<TestAddress<'a>> for Address
impl<'a> PartialEq<TestAddress<'a>> for Address
Source§fn eq(&self, other: &TestAddress<'a>) -> bool
fn eq(&self, other: &TestAddress<'a>) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a> PartialEq<TestSCAddress<'a>> for Address
impl<'a> PartialEq<TestSCAddress<'a>> for Address
Source§fn eq(&self, other: &TestSCAddress<'a>) -> bool
fn eq(&self, other: &TestSCAddress<'a>) -> bool
self and other values to be equal, and is used by ==.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,
Source§impl<Env> TxFrom<Env> for &Addresswhere
Env: TxEnv,
impl<Env> TxFrom<Env> for &Addresswhere
Env: TxEnv,
fn resolve_address(&self, _env: &Env) -> ManagedAddress<Env::Api>
Source§impl<Env> TxFrom<Env> for Addresswhere
Env: TxEnv,
impl<Env> TxFrom<Env> for Addresswhere
Env: TxEnv,
fn resolve_address(&self, _env: &Env) -> ManagedAddress<Env::Api>
Source§impl<Env> TxToSpecified<Env> for &Addresswhere
Env: TxEnv,
impl<Env> TxToSpecified<Env> for &Addresswhere
Env: TxEnv,
Source§fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
Source§impl<Env> TxToSpecified<Env> for Addresswhere
Env: TxEnv,
impl<Env> TxToSpecified<Env> for Addresswhere
Env: TxEnv,
Source§fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
Source§impl TypeAbi for Address
impl TypeAbi for Address
type Unmanaged = Address
Source§fn type_name_rust() -> TypeName
fn type_name_rust() -> TypeName
fn type_names() -> TypeNames
Source§fn type_name_specific() -> Option<TypeName>
fn type_name_specific() -> Option<TypeName>
Source§fn provide_type_descriptions<TDC: TypeDescriptionContainer>(
accumulator: &mut TDC,
)
fn provide_type_descriptions<TDC: TypeDescriptionContainer>( accumulator: &mut TDC, )
impl Eq for Address
impl StructuralPartialEq for Address
impl<Env> TxFromSpecified<Env> for &Addresswhere
Env: TxEnv,
impl<Env> TxFromSpecified<Env> for Addresswhere
Env: TxEnv,
impl<Env> TxTo<Env> for &Addresswhere
Env: TxEnv,
impl<Env> TxTo<Env> for Addresswhere
Env: TxEnv,
impl<M> TypeAbiFrom<&Address> for ManagedAddress<M>where
M: ManagedTypeApi,
impl<M> TypeAbiFrom<&ManagedAddress<M>> for Addresswhere
M: ManagedTypeApi,
impl TypeAbiFrom<Address> for Address
impl<M> TypeAbiFrom<Address> for ManagedAddress<M>where
M: ManagedTypeApi,
impl<M> TypeAbiFrom<ManagedAddress<M>> for Addresswhere
M: ManagedTypeApi,
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> 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> SCCodec for Twhere
T: TopEncode,
impl<T> SCCodec for Twhere
T: TopEncode,
fn fmt<F>(&self, f: &mut F)where
F: FormatByteReceiver,
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.