3

I want to get the meta function description of pallets storage maps. Returning an output like this:

{ Twox64Concat, [u8; 16], u32 } = query.storagemap(pallet: "template", storagemap: "SomeMap")

This is a storage map I created and spun up the substrate node template:

#[pallet::storage]
pub(super) type SomeMap<T: Config> = StorageMap<_, Twox64Concat, [u8; 16], u32>;

The metadata only gives limited information about the storage map:

              {
                name: SomeMap
                modifier: Optional
                type: {
                  Map: {
                    hashers: [
                      Twox64Concat
                    ]
                    key: 111
                    value: 4
                  }
                }
                fallback: 0x00
                docs: []
              }
            ]
          }

I'm trying to get the function input types,

The only type information I'm able to gathered is what polkadot.js gives me:

polkadot.js

Thanks!
~ flipchan

1 Answer 1

1

There is also a type map in the metadata.

Something like this:

 metadata: {
    V14: {
      lookup: {
        types: [
          {
            id: 0
            type: {
              path: [
                account
                AccountId20
              ]
              params: []
              def: {
                Composite: {
                  fields: [
                    {
                      name: null
                      type: 1
                      typeName: [u8; 20]
                      docs: []
                    }
                  ]
                }
              }
              docs: []
            }
          }

You need to follow the type id to construct the type base on that map to get the real type.

E.G. this is my chain's [u8; 16] which is located at 105:

{
  name: Array16
  fields: [
    {
      name: null
      type: 105
      typeName: [u8; 16]
      docs: []
    }
  ]
  index: 4
  docs: []
}
{
  id: 105
  type: {
    path: []
    params: []
    def: {
      Array: {
        len: 16
        type: 2
      }
    }
    docs: []
  }
}

In simple terms, find the storage, find the type id then construct the type.

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.