From ceb4ce45d0a0ed08b9bda741c2bd89444df9dea6 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 8 Aug 2026 11:57:15 -0700 Subject: [PATCH] Set account data from account info refresh. --- src/lib/wallet/refresh.ts | 58 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/lib/wallet/refresh.ts b/src/lib/wallet/refresh.ts index 5b15b77..25c1f32 100644 --- a/src/lib/wallet/refresh.ts +++ b/src/lib/wallet/refresh.ts @@ -3,8 +3,8 @@ import { Account } from '../account' import { Block } from '../block' -import { BURN_PUBLIC_KEY } from '../constants' import { Rpc } from '../rpc' +import { AccountInfoRequest, AccountInfoResponse } from '../rpc/account_info' import { Wallet } from '../wallet' export async function _refresh (wallet: Wallet, rpc: Rpc | string | URL, from: number, to: number): Promise> @@ -29,38 +29,42 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to: json_block: true, accounts: addresses } - const { balances } = await rpc.post('accounts_balances', data) const { frontiers } = await rpc.post('accounts_frontiers', data) const { blocks } = await rpc.post('blocks_info', { json_block: true, include_not_found: true, hashes: Object.values(frontiers ?? {}) }) + for (const account of accounts.values()) { - const reqAccountInfo: AccountInfoRequest = { - account: account.address, - include_confirmed: true, - receivable: true, - representative: true, - weight: true - } - const accountInfo = await rpc.post('account_info', reqAccountInfo) - for (const [k, v] of Object.entries(accountInfo)) { - account[k] = v - } - account.balance = balances?.[account.address]?.balance ?? 0 - account.receivable = balances?.[account.address]?.receivable ?? 0 - if (frontiers?.[account.address] != null) { - account.frontier = frontiers[account.address] - if (blocks?.[account.frontier] != null) { - const { subtype, contents: { balance, link, previous, representative, signature } } = blocks[account.frontier] - account.representative = representative - const frontierBlock = new Block(account, balance, previous, representative) - if (typeof frontierBlock[subtype] !== 'function') { - throw new TypeError('Unknown frontier block subtype', { cause: subtype }) - } - const arg = subtype === 'epoch' ? account.version : subtype === 'change' ? representative : link - frontierBlock[subtype](arg, 0).signature = signature - account.frontier_block = frontierBlock + const reqAccountInfo: AccountInfoRequest = { + account: account.address, + include_confirmed: true, + receivable: true, + representative: true, + weight: true + } + let resAccountInfo: AccountInfoResponse + try { + resAccountInfo = await rpc.post('account_info', reqAccountInfo) + } catch (err) { + console.error(err) + continue + } + const { account_version, balance, frontier, pending, receivable } = resAccountInfo + account.balance = balance ?? 0 + account.frontier = frontier + account.receivable = receivable ?? pending ?? 0 + account.version = account_version + if (frontier != null && blocks?.[frontier] != null) { + const { subtype, contents: { balance, link, previous, representative, signature } } = blocks[account.frontier] + account.representative = representative + const frontierBlock = new Block(account, balance, previous, representative) + if (typeof frontierBlock[subtype] !== 'function') { + throw new TypeError('Unknown frontier block subtype', { cause: subtype }) } + const arg = subtype === 'epoch' ? account.version : subtype === 'change' ? representative : link + frontierBlock[subtype](arg, 0).signature = signature + account.frontier_block = frontierBlock } } + return accounts } catch (err) { console.error(err) -- 2.52.0