@@ -1718,16 +1718,18 @@ def rpc_request(
1718
1718
self ,
1719
1719
method : str ,
1720
1720
params : Optional [list ],
1721
+ result_handler : Optional [Callable ] = None ,
1721
1722
block_hash : Optional [str ] = None ,
1722
1723
reuse_block_hash : bool = False ,
1723
1724
) -> Any :
1724
1725
"""
1725
- Makes an RPC request to the subtensor. Use this only if `self.query`` and `self.query_multiple` and
1726
+ Makes an RPC request to the subtensor. Use this only if `self.query` and `self.query_multiple` and
1726
1727
`self.query_map` do not meet your needs.
1727
1728
1728
1729
Args:
1729
1730
method: str the method in the RPC request
1730
1731
params: list of the params in the RPC request
1732
+ result_handler: Callback function that processes the result received from the node
1731
1733
block_hash: the hash of the block — only supply this if not supplying the block
1732
1734
hash in the params, and not reusing the block hash
1733
1735
reuse_block_hash: whether to reuse the block hash in the params — only mark as True
@@ -1746,7 +1748,7 @@ def rpc_request(
1746
1748
params + [block_hash ] if block_hash else params ,
1747
1749
)
1748
1750
]
1749
- result = self ._make_rpc_request (payloads )
1751
+ result = self ._make_rpc_request (payloads , result_handler = result_handler )
1750
1752
if "error" in result [payload_id ][0 ]:
1751
1753
if (
1752
1754
"Failed to get runtime version"
@@ -1756,7 +1758,9 @@ def rpc_request(
1756
1758
"Failed to get runtime. Re-fetching from chain, and retrying."
1757
1759
)
1758
1760
self .init_runtime ()
1759
- return self .rpc_request (method , params , block_hash , reuse_block_hash )
1761
+ return self .rpc_request (
1762
+ method , params , result_handler , block_hash , reuse_block_hash
1763
+ )
1760
1764
raise SubstrateRequestException (result [payload_id ][0 ]["error" ]["message" ])
1761
1765
if "result" in result [payload_id ][0 ]:
1762
1766
return result [payload_id ][0 ]
@@ -1776,7 +1780,6 @@ def get_chain_head(self) -> str:
1776
1780
)
1777
1781
]
1778
1782
)
1779
- print (1779 , result )
1780
1783
self .last_block_hash = result ["rpc_request" ][0 ]["result" ]
1781
1784
return result ["rpc_request" ][0 ]["result" ]
1782
1785
@@ -2577,12 +2580,12 @@ def query_map(
2577
2580
```
2578
2581
result = substrate.query_map('System', 'Account', max_results=100)
2579
2582
2580
- async for account, account_info in result:
2583
+ for account, account_info in result:
2581
2584
print(f"Free balance of account '{account.value}': {account_info.value['data']['free']}")
2582
2585
```
2583
2586
2584
2587
Note: it is important that you do not use `for x in result.records`, as this will sidestep possible
2585
- pagination. You must do `async for x in result`.
2588
+ pagination. You must do `for x in result`.
2586
2589
2587
2590
Args:
2588
2591
module: The module name in the metadata, e.g. System or Balances.
0 commit comments