From 0decfb68e82ac82f852066212eae903fec4a154e Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 7 Aug 2026 13:51:39 -0700 Subject: [PATCH] Fix response fields excluded without flags in request. --- src/lib/account/index.ts | 6 +++--- src/lib/account/refresh.ts | 11 +++++++---- src/lib/rpc/account_info.ts | 9 +++++---- src/lib/rpc/block_info.ts | 6 ++++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/lib/account/index.ts b/src/lib/account/index.ts index 05d2e68..72c90ea 100644 --- a/src/lib/account/index.ts +++ b/src/lib/account/index.ts @@ -27,7 +27,7 @@ export class Account { #confirmed_balance?: bigint #confirmed_height?: number - #confirmed_frontier?: string + #confirmed_frontier?: Hex #confirmed_frontier_block?: Block #confirmed_receivable?: bigint #confirmed_representative?: Account @@ -52,7 +52,7 @@ export class Account { get confirmed_balance (): bigint | undefined { return this.#confirmed_balance } get confirmed_height (): number | undefined { return this.#confirmed_height } - get confirmed_frontier (): string | undefined { return this.#confirmed_frontier } + get confirmed_frontier (): Hex | undefined { return this.#confirmed_frontier } get confirmed_frontier_block (): Block | undefined { return this.#confirmed_frontier_block } get confirmed_receivable (): bigint | undefined { return this.#confirmed_receivable } get confirmed_representative (): Account | undefined { return this.#confirmed_representative } @@ -69,7 +69,7 @@ export class Account { set confirmed_balance (v: bigint | number | string) { this.#confirmed_balance = BigInt(v) } set confirmed_height (v: number | undefined) { if (v !== undefined) this.#confirmed_height = v | 0 } - set confirmed_frontier (v: string | undefined) { this.#confirmed_frontier = v } + set confirmed_frontier (v: Hex | undefined) { this.#confirmed_frontier = v } set confirmed_frontier_block (v: Block | undefined) { this.#confirmed_frontier_block = v } set confirmed_receivable (v: bigint | number | string) { this.#confirmed_receivable = BigInt(v) } set confirmed_representative (v: unknown) { diff --git a/src/lib/account/refresh.ts b/src/lib/account/refresh.ts index 09dbc2a..34e8074 100644 --- a/src/lib/account/refresh.ts +++ b/src/lib/account/refresh.ts @@ -5,6 +5,7 @@ import { Account } from '.' import { Block } from '../block' import { Rpc } from '../rpc' import { AccountInfoRequest } from '../rpc/account_info' +import { BlockInfoRequest } from '../rpc/block_info' export async function _refresh (account: Account, rpc: Rpc | string | URL): Promise export async function _refresh (account: Account, rpc: unknown): Promise { @@ -26,9 +27,10 @@ export async function _refresh (account: Account, rpc: unknown): Promise { account[k] = v } - const reqConfirmedFrontierBlockInfo = { + const reqConfirmedFrontierBlockInfo: BlockInfoRequest = { + hash: accountInfo.confirmed_frontier, + include_linked_account: true, json_block: true, - hash: account.confirmed_frontier } const resConfirmedFrontierBlockInfo = await rpc.post('block_info', reqConfirmedFrontierBlockInfo) if (resConfirmedFrontierBlockInfo == null || typeof resConfirmedFrontierBlockInfo !== 'object') { @@ -55,9 +57,10 @@ export async function _refresh (account: Account, rpc: unknown): Promise { confirmedFrontierBlock[confirmedFrontierSubtype](confirmedFrontierContents.link, 0).signature = confirmedFrontierContents.signature account.confirmed_frontier_block = confirmedFrontierBlock - const reqFrontierBlockInfo = { + const reqFrontierBlockInfo: BlockInfoRequest = { + hash: accountInfo.frontier, + include_linked_account: true, json_block: true, - hash: account.frontier } const resFrontierBlockInfo = await rpc.post('block_info', reqFrontierBlockInfo) if (resFrontierBlockInfo == null || typeof resFrontierBlockInfo !== 'object') { diff --git a/src/lib/rpc/account_info.ts b/src/lib/rpc/account_info.ts index bff8461..8631100 100644 --- a/src/lib/rpc/account_info.ts +++ b/src/lib/rpc/account_info.ts @@ -1,6 +1,7 @@ //! SPDX-FileCopyrightText: 2026 Chris Duncan //! SPDX-License-Identifier: GPL-3.0-or-later +import { hex } from '../convert' import { RpcError } from '../errors' export type AccountInfoRequest = { @@ -18,12 +19,12 @@ export type AccountInfoResponse = { confirmation_height?: string confirmation_height_frontier?: string confirmed_balance: string - confirmed_frontier: string + confirmed_frontier: Hex confirmed_height: string confirmed_pending?: string confirmed_receivable: string confirmed_representative: string - frontier: string + frontier: Hex modified_timestamp: string open_block: string pending?: string @@ -39,11 +40,11 @@ export function account_info (body: unknown): AccountInfoResponse { && 'balance' in body && typeof body.balance === 'string' && 'block_count' in body && typeof body.block_count === 'string' && 'confirmed_balance' in body && typeof body.confirmed_balance === 'string' - && 'confirmed_frontier' in body && typeof body.confirmed_frontier === 'string' + && 'confirmed_frontier' in body && hex.is(body.confirmed_frontier) && 'confirmed_height' in body && typeof body.confirmed_height === 'string' && 'confirmed_receivable' in body && typeof body.confirmed_receivable === 'string' && 'confirmed_representative' in body && typeof body.confirmed_representative === 'string' - && 'frontier' in body && typeof body.frontier === 'string' + && 'frontier' in body && hex.is(body.frontier) && 'modified_timestamp' in body && typeof body.modified_timestamp === 'string' && 'open_block' in body && typeof body.open_block === 'string' && 'receivable' in body && typeof body.receivable === 'string' diff --git a/src/lib/rpc/block_info.ts b/src/lib/rpc/block_info.ts index e4b98f0..19320ba 100644 --- a/src/lib/rpc/block_info.ts +++ b/src/lib/rpc/block_info.ts @@ -3,6 +3,12 @@ import { RpcError } from '../errors' +export type BlockInfoRequest = { + hash: Hex + include_linked_account: true + json_block: true +} + export type BlockInfoContents = { account: string balance: string -- 2.52.0