Skip to content

Commit

Permalink
Partially load accounts. (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev authored and sinev-valentine committed Jul 19, 2022
1 parent 43ea49a commit ea25fd2
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions proxy/common_neon/solana_interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def get_account_info(self, pubkey: PublicKey, length=256, commitment='confirmed'

return AccountInfo(account_tag, lamports, owner, data)

def get_account_info_list(self, accounts: [PublicKey], length=256, commitment='confirmed') -> [AccountInfo]:
def get_account_info_list(self, src_account_list: List[PublicKey], length=256, commitment='confirmed') -> List[AccountInfo]:
opts = {
"encoding": "base64",
"commitment": commitment,
Expand All @@ -193,23 +193,25 @@ def get_account_info_list(self, accounts: [PublicKey], length=256, commitment='c
'length': length
}

result = self._send_rpc_request("getMultipleAccounts", [str(a) for a in accounts], opts)
# self.debug(f"{json.dumps(result, sort_keys=True)}")
account_info_list = []
while len(src_account_list) > 0:
account_list = [str(a) for a in src_account_list[:50]]
src_account_list = src_account_list[50:]
result = self._send_rpc_request("getMultipleAccounts", account_list, opts)

if result['result']['value'] is None:
self.debug(f"Can't get information about {accounts}")
return []
error = result.get('error', None)
if error:
self.debug(f"Can't get information about accounts {account_list}: {error}")
return account_info_list

accounts_info = []
for pubkey, info in zip(accounts, result['result']['value']):
if info is None:
accounts_info.append(None)
else:
data = base64.b64decode(info['data'][0])
account = AccountInfo(tag=data[0], lamports=info['lamports'], owner=info['owner'], data=data)
accounts_info.append(account)

return accounts_info
for pubkey, info in zip(account_list, result['result']['value']):
if info is None:
account_info_list.append(None)
else:
data = base64.b64decode(info['data'][0])
account = AccountInfo(tag=data[0], lamports=info['lamports'], owner=info['owner'], data=data)
account_info_list.append(account)
return account_info_list

def get_sol_balance(self, account, commitment='confirmed'):
opts = {
Expand Down

0 comments on commit ea25fd2

Please sign in to comment.