When for example querying storage function Tokens.TotalIssuance on Karura, which need 1 param, it is quitte cumbersome without prior example to figure out the format of the param:
# Retrieve storage function to get information about value and param types
storage_function = substrate.get_metadata_storage_function("Tokens", "TotalIssuance")
# Amount of params
print(len(storage_function.get_params_type_string())) # 1
# Retrieve a SCALE object of the param type
param_type = substrate.create_scale_object(storage_function.get_params_type_string()[0])
# Possible options of Enum type
print(param_type.type_mapping)
# [('Token', 'scale_info::42'), ('DexShare', '(scale_info::43, scale_info::43)'), ('Erc20', 'scale_info::44'), ('StableAssetPoolToken', 'scale_info::4'), ('LiquidCrowdloan', 'scale_info::4'), ('ForeignAsset', 'scale_info::35')]
# So if I want to use the 'Token' option: SCALE type is 'scale_info::42'
token_param = substrate.create_scale_object(param_type.type_mapping[0][1])
# Show possible options of Tokens
print(token_param.type_mapping)
# [('ACA', 'Null'), ('AUSD', 'Null'), ('DOT', 'Null'), ('LDOT', 'Null'), (None, 'Null'), (None, 'Null') ....
# So now if I want to show the TotalIssuance of the `Token` `KSM`:
result = substrate.query(
module='Tokens',
storage_function='TotalIssuance',
params=[{'Token': 'KSM'}]
)
# Result is U128 object with value 81190424615873229
print(result.value)
# 81190424615873229
It becomes more clear when using the query_map() function (get all results, omitting the param)
When for example querying storage function
Tokens.TotalIssuance
on Karura, which need 1 param, it is quitte cumbersome without prior example to figure out the format of the param:It becomes more clear when using the
query_map()
function (get all results, omitting the param)Idea could be to create a new method like
storage_function.show_param_specification()
that returns adict
like:Which can easier lead to figuring out the input e.g.
{'Token': 'DOT'}