polkascan / py-substrate-interface

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

Implement support for subscribing to multiple keys #327

Closed realblackbot closed 1 year ago

realblackbot commented 1 year ago

Discussed in https://github.com/polkascan/py-substrate-interface/discussions/326

Originally posted by **gergelykrasznai** March 5, 2023 Hey py-substrate-interface community! Polkadot.js clearly states it's possible (and even encouraged) to subscribe to events of multiple subjects: https://polkadot.js.org/docs/api/start/api.query.multi/ Let's say I would like to track the balance change of two wallets, how could I do that using SubstrateInterface, as the following code for a single wallet doesn't work: `self._substrate.query( 'System', 'Account', [[walletaddress1, walletaddress2]], None, self.__on_balance_changed, None )` and query_map() doesn't have subscription support. Could somebody point me to the right direction on how can I do such a Multi Query via SubstrateInterface please? Thanks for any help in advance!
arjanz commented 1 year ago

Now it's only possible to subscribe to a single storage key (Pallet + storage function + params) with the query() method.

Support for multiple storage keys at once is desired, this will require to refactor this functionality from the query() method.

Proposed new methods: