polkascan/py-substrate-interface

Implement support for subscribing to multiple keys

realblackbot opened this issue · 1 comments

Discussed in #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!

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:

  • subscribe_storage(pallet: str, storage_function: str, params, [])
  • subscribe_storage_multi(keys: list[StorageKey])