polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
241 stars 115 forks source link

Not all storage functions are available (i.e. contracts.palletVersion) #320

Closed rogerjbos closed 1 year ago

rogerjbos commented 1 year ago

The Contracts pallet has a storage function called PalletVersion, but this is not available in py-substrate-interface. Currently only a few parachains use the contracts pallet, but two examples are shiden and rococo. The following works in JS:

    console.log(await api.query.contracts.palletVersion());

but it does not work in python. In fact if I list all the storage functions available in the metadata, PalletVersion does not show up:

url = 'wss://rococo-contracts-rpc.polkadot.io'
  substrate = SubstrateInterface(url)
  df = substrate.get_metadata_storage_functions()
  tmp = pd.DataFrame(df)
  tmp[tmp['module_id'] == 'Contracts']

Do recently added storage functions need to be manually added, or am I missing something?

arjanz commented 1 year ago

This is a very interesting question, as I also confirmed that this was working in PolkadotJS, but there was no such storage function in the metadata.

All calls, storage functions, constants etc are extracted from the metadata found on-chain, so this is always be up-to-date with the runtime (you can even historically call storage functions back in time that have been removed later on, by specifying a block_hash).

So I went on searching and found out it is a fixed storage key suffix per pallet, a convention in Substrate: https://github.com/polkadot-js/api/issues/3323

I was aware there were static 'well-known' storage keys as specified here but I wasn't aware of generic per pallet keys.

Thanks for pointing this out, I will make a PR for this soon.

arjanz commented 1 year ago

Storage function PalletVersion available in release https://github.com/polkascan/py-substrate-interface/releases/tag/v1.5.1