Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially load accounts. #834

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions proxy/common_neon/solana_interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,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 @@ -306,23 +306,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)}")

if result['result']['value'] is None:
self.debug(f"Can't get information about {accounts}")
return []
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)

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)
error = result.get('error', None)
if error:
self.debug(f"Can't get information about accounts {account_list}: {error}")
return account_info_list

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') -> int:
opts = {
Expand Down