Trait sp_runtime::traits::AccountIdConversion
source · pub trait AccountIdConversion<AccountId>: Sized {
// Required methods
fn into_sub_account_truncating<S: Encode>(&self, sub: S) -> AccountId;
fn try_into_sub_account<S: Encode>(&self, sub: S) -> Option<AccountId>;
fn try_from_sub_account<S: Decode>(x: &AccountId) -> Option<(Self, S)>;
// Provided methods
fn into_account_truncating(&self) -> AccountId { ... }
fn try_into_account(&self) -> Option<AccountId> { ... }
fn try_from_account(a: &AccountId) -> Option<Self> { ... }
}
Expand description
This type can be converted into and possibly from an AccountId (which itself is generic).
Required Methods§
sourcefn into_sub_account_truncating<S: Encode>(&self, sub: S) -> AccountId
fn into_sub_account_truncating<S: Encode>(&self, sub: S) -> AccountId
Convert this value amalgamated with the a secondary “sub” value into an account ID, truncating any unused bytes. This is infallible.
NOTE: The account IDs from this and from into_account
are not guaranteed to be distinct
for any given value of self
, nor are different invocations to this with different types
T
. For example, the following will all encode to the same account ID value:
self.into_sub_account(0u32)
self.into_sub_account(vec![0u8; 0])
self.into_account()
Also, if the seed provided to this function is greater than the number of bytes which fit
into this AccountId
type, then it will lead to truncation of the seed, and potentially
non-unique accounts.
sourcefn try_into_sub_account<S: Encode>(&self, sub: S) -> Option<AccountId>
fn try_into_sub_account<S: Encode>(&self, sub: S) -> Option<AccountId>
Same as into_sub_account_truncating
, but ensuring that all bytes of the account’s seed are
used when generating an account. This can help guarantee that different accounts are unique,
besides types which encode the same as noted above.
sourcefn try_from_sub_account<S: Decode>(x: &AccountId) -> Option<(Self, S)>
fn try_from_sub_account<S: Decode>(x: &AccountId) -> Option<(Self, S)>
Try to convert an account ID into this type. Might not succeed.
Provided Methods§
sourcefn into_account_truncating(&self) -> AccountId
fn into_account_truncating(&self) -> AccountId
Convert into an account ID. This is infallible, and may truncate bytes to provide a result.
This may lead to duplicate accounts if the size of AccountId
is less than the seed.
sourcefn try_into_account(&self) -> Option<AccountId>
fn try_into_account(&self) -> Option<AccountId>
Convert into an account ID, checking that all bytes of the seed are being used in the final
AccountId
generated. If any bytes are dropped, this returns None
.
sourcefn try_from_account(a: &AccountId) -> Option<Self>
fn try_from_account(a: &AccountId) -> Option<Self>
Try to convert an account ID into this type. Might not succeed.