1

The default implementation is to use a u32 as AccountIndex. This means that only 2^32 claims can be made. Besides reserving an integer, can we use String as AccountIndex thereby referencing an account with a name instead of a number?

Edit #1: Can we use it in place of regular addresses to send/receive funds?

2
  • What do pallet indices in the title have to do with AccountIndex in the question? PS: For custom address lookup you can use the Account lookup. Commented Sep 12, 2022 at 14:16
  • Ah, you probably meant pallet-indices and not the plural of a pallet index. I see 😂 Commented Sep 12, 2022 at 14:31

1 Answer 1

1

The default implementation is to use a u32 as AccountIndex. This means that only 2^32 claims can be made.

Yes. This is an assumption that often occurs within Substrate. usize is truncated into u32 in multiple places. You can change it in your runtime though.

Besides reserving an integer, can we use String as AccountIndex thereby referencing an account with a name instead of a number?
[…] Can we use it in place of regular addresses to send/receive funds?

There exists the Lookup and StaticLookup trait which can translate a generic value into an AccountId. You probably want something like this:

fn transfer(
    origin: OriginFor<T>,
    receiver: String,
)

but that has the downside of being limited to String. So now you would need different functions depending on the receiver type; not good.
Instead Substrate uses Lookup in many places, so that it becomes:

fn transfer(
    origin: OriginFor<T>,
    receiver: <<T as frame_system::Config>::Lookup as StaticLookup>::Source,
)
{
    let target = T::Lookup::lookup(receiver)?;

You can now translate all kinds of types by implementing that trait.
There is a good example in the Darwinia repo where Ethereum addresses are translated to Substrate: here.

2
  • They are translating any address to an AccountId which I believe is the equivalent of the AccountId one would define in runtime/src/lib.rs yes? Commented Sep 13, 2022 at 8:04
  • Yes. (minimal comment length) Commented Sep 13, 2022 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.