Skip to content

Commit d512122

Browse files
committed
Backwards compatibility.
1 parent 1a093aa commit d512122

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,16 +1971,18 @@ async def rpc_request(
19711971
self,
19721972
method: str,
19731973
params: Optional[list],
1974+
result_handler: Optional[ResultHandler] = None,
19741975
block_hash: Optional[str] = None,
19751976
reuse_block_hash: bool = False,
19761977
) -> Any:
19771978
"""
1978-
Makes an RPC request to the subtensor. Use this only if `self.query`` and `self.query_multiple` and
1979+
Makes an RPC request to the subtensor. Use this only if `self.query` and `self.query_multiple` and
19791980
`self.query_map` do not meet your needs.
19801981
19811982
Args:
19821983
method: str the method in the RPC request
19831984
params: list of the params in the RPC request
1985+
result_handler: ResultHandler
19841986
block_hash: the hash of the block — only supply this if not supplying the block
19851987
hash in the params, and not reusing the block hash
19861988
reuse_block_hash: whether to reuse the block hash in the params — only mark as True
@@ -1999,7 +2001,7 @@ async def rpc_request(
19992001
params + [block_hash] if block_hash else params,
20002002
)
20012003
]
2002-
result = await self._make_rpc_request(payloads)
2004+
result = await self._make_rpc_request(payloads, result_handler=result_handler)
20032005
if "error" in result[payload_id][0]:
20042006
if (
20052007
"Failed to get runtime version"
@@ -2010,7 +2012,7 @@ async def rpc_request(
20102012
)
20112013
await self.init_runtime()
20122014
return await self.rpc_request(
2013-
method, params, block_hash, reuse_block_hash
2015+
method, params, result_handler, block_hash, reuse_block_hash
20142016
)
20152017
raise SubstrateRequestException(result[payload_id][0]["error"]["message"])
20162018
if "result" in result[payload_id][0]:

async_substrate_interface/sync_substrate.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,16 +1718,18 @@ def rpc_request(
17181718
self,
17191719
method: str,
17201720
params: Optional[list],
1721+
result_handler: Optional[Callable] = None,
17211722
block_hash: Optional[str] = None,
17221723
reuse_block_hash: bool = False,
17231724
) -> Any:
17241725
"""
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
17261727
`self.query_map` do not meet your needs.
17271728
17281729
Args:
17291730
method: str the method in the RPC request
17301731
params: list of the params in the RPC request
1732+
result_handler: Callback function that processes the result received from the node
17311733
block_hash: the hash of the block — only supply this if not supplying the block
17321734
hash in the params, and not reusing the block hash
17331735
reuse_block_hash: whether to reuse the block hash in the params — only mark as True
@@ -1746,7 +1748,7 @@ def rpc_request(
17461748
params + [block_hash] if block_hash else params,
17471749
)
17481750
]
1749-
result = self._make_rpc_request(payloads)
1751+
result = self._make_rpc_request(payloads, result_handler=result_handler)
17501752
if "error" in result[payload_id][0]:
17511753
if (
17521754
"Failed to get runtime version"
@@ -1756,7 +1758,9 @@ def rpc_request(
17561758
"Failed to get runtime. Re-fetching from chain, and retrying."
17571759
)
17581760
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+
)
17601764
raise SubstrateRequestException(result[payload_id][0]["error"]["message"])
17611765
if "result" in result[payload_id][0]:
17621766
return result[payload_id][0]
@@ -1776,7 +1780,6 @@ def get_chain_head(self) -> str:
17761780
)
17771781
]
17781782
)
1779-
print(1779, result)
17801783
self.last_block_hash = result["rpc_request"][0]["result"]
17811784
return result["rpc_request"][0]["result"]
17821785

@@ -2577,12 +2580,12 @@ def query_map(
25772580
```
25782581
result = substrate.query_map('System', 'Account', max_results=100)
25792582
2580-
async for account, account_info in result:
2583+
for account, account_info in result:
25812584
print(f"Free balance of account '{account.value}': {account_info.value['data']['free']}")
25822585
```
25832586
25842587
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`.
25862589
25872590
Args:
25882591
module: The module name in the metadata, e.g. System or Balances.

0 commit comments

Comments
 (0)