polkascan / py-substrate-interface

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

Subscription handler should not be limited by params count #266

Open sergpsu opened 1 year ago

sergpsu commented 1 year ago

I'd like to be able to track any account balance change, so trying

query('System', 'Account', subscription_handler=...)

but the following happens

if len(params) != len(param_types):
    raise ValueError(f'Storage function requires {len(param_types)} parameters, {len(params)} given')

Tried to subscribe to Substrate events by calling "state_subscribeStorage" directly and it works, so it seems that SubstrateInterface limitation on params length is not correct

arjanz commented 1 year ago

System.Account needs a parameter to be able to add a subscription, as far as I know it won't be possible to create a storage subscription an a Mapped storage function without the required parameters.

arjanz commented 1 year ago

System.Events is not a Mapped storage function and that's why it can be subscribed without parameters. Actually I was curious as well and commented out the restriction to see what happens, but no updates are received from the RPC.

sergpsu commented 1 year ago

You partially right: subscription does not work if passing storage_hash which was created only with "System" + "Account" and without param. But if send data to websocket without "params" completely then all storage changes returned and System.Account changes can be fetched

{"jsonrpc":"2.0", "method":"state_subscribeStorage", "id":1}
sergpsu commented 1 year ago

I'm wrong. Though it is possible to see that some account balance changed, but it is not possible to know which one exactly