pub trait AccountIdConversion<AccountId>: Sized {
    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)>;

    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

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.

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.

Try to convert an account ID into this type. Might not succeed.

Provided Methods

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.

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.

Try to convert an account ID into this type. Might not succeed.


Format is TYPE_ID ++ encode(sub-seed) ++ 00…. where 00… is indefinite trailing zeroes to fill AccountId.