Skip to content

Commit 18dc31b

Browse files
authored
support updating > 100 products (#26)
* enable update_accounts to support > 100 accounts * bump version to 0.1.1
1 parent 3aa39d2 commit 18dc31b

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

pythclient/solana.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,21 @@ async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any):
195195
await self.close()
196196

197197
async def update_accounts(self, accounts: Sequence[SolanaAccount]) -> None:
198-
resp = await self.get_account_info([account.key for account in accounts])
199-
slot = resp["context"]["slot"]
200-
values = resp["value"]
201-
for account, value in zip(accounts, values):
202-
if value is None:
203-
logger.warning("got null value from Solana getMultipleAccounts for {}; non-existent account?", account.key)
204-
continue
205-
try:
206-
account.update_with_rpc_response(slot, value)
207-
except Exception as ex:
208-
logger.exception("error while updating account {}", account.key, exception=ex)
198+
# Solana's getMultipleAccounts RPC is limited to 100 accounts
199+
# Hence we have to split them into groups of 100
200+
# https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts
201+
for grouped_accounts in [accounts[i:i+100] for i in range(0, len(accounts), 100)]:
202+
resp = await self.get_account_info([account.key for account in grouped_accounts])
203+
slot = resp["context"]["slot"]
204+
values = resp["value"]
205+
for account, value in zip(grouped_accounts, values):
206+
if value is None:
207+
logger.warning("got null value from Solana getMultipleAccounts for {}; non-existent account?", account.key)
208+
continue
209+
try:
210+
account.update_with_rpc_response(slot, value)
211+
except Exception as ex:
212+
logger.exception("error while updating account {}", account.key, exception=ex)
209213

210214
async def http_send(self, method: str, params: Optional[List[Any]] = None, *, return_error: bool = False) -> Any:
211215
if self.ratelimit:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='pythclient',
10-
version='0.1.0',
10+
version='0.1.1',
1111
packages=['pythclient'],
1212
author='Pyth Developers',
1313
author_email='[email protected]',

0 commit comments

Comments
 (0)