polkascan / py-substrate-interface

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

'ConvictionVoting.VotingFor' storage function history without parameters" #350

Closed ruiparitydata closed 10 months ago

ruiparitydata commented 11 months ago

Hello there,

I want to query the ConvictionVoting.VotingFor storage function to return Polkadot’s voting and delegating history, similar to how the Democracy.VotingOf function works if no parameters are passed.

result = substrate.query_map('ConvictionVoting', 'VotingFor')

However, when I query it with no parameters I get the error below, suggesting I need to pass an address as a parameter.

ValueError                                Traceback (most recent call last)
Cell In[7], line 4
      1 substrate = SubstrateInterface(url = 'wss://rpc.polkadot.io', ss58_format=2,
      2             type_registry_preset='polkadot')
----> 4 result = substrate.query_map('ConvictionVoting', 'VotingFor')

File /Python.framework/Versions/3.11/lib/python3.11/site-packages/substrateinterface/base.py:790, in SubstrateInterface.query_map(self, module, storage_function, params, block_hash, max_results, start_key, page_size, ignore_decoding_errors)
    787     raise ValueError('Given storage function is not a map')
    789 if len(params) != len(param_types) - 1:
--> 790     raise ValueError(f'Storage function map requires {len(param_types) -1} parameters, {len(params)} given')
    792 # Generate storage key prefix
    793 storage_key = StorageKey.create_from_storage_function(
    794     module, storage_function, params, runtime_config=self.runtime_config, metadata=self.metadata
    795 )

ValueError: Storage function map requires 1 parameters, 0 given

An equivalent way to do this with the Polkadot JS API could be:

const voting = await api.query.convictionVoting.votingFor.entries();

Is it possible to modify my approach so the ConvictionVoting.VotingFor storage function will work as described above and return the desired voting and delegating history without the need to provide any parameters? If so, could you please guide me on how to achieve this, and if not, are there any alternative approaches or workarounds?

Thanks in advance

arjanz commented 10 months ago

Released: https://github.com/polkascan/py-substrate-interface/releases/tag/v1.7.4