From f389a5bf52c9f7a22a187151e621fb5a4bcd84f5 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 21 Aug 2025 14:43:42 -0700 Subject: [PATCH] Revert private account properties to match RPC data so that assignment from a refresh call can be greatly simplified. --- src/lib/account.ts | 55 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index bdb98eb..fec5f96 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -25,14 +25,14 @@ export class Account { #publicKey: Uint8Array #confirmed_balance?: bigint - #confirmed_block_height?: number + #confirmed_height?: number #confirmed_frontier?: string #confirmed_frontier_block?: Block #confirmed_receivable?: bigint #confirmed_representative?: Account #balance?: bigint - #block_height?: number + #block_count?: number #frontier?: string #frontier_block?: Block #open_block?: string @@ -46,14 +46,14 @@ export class Account { get publicKey (): string { return bytes.toHex(this.#publicKey) } get confirmed_balance (): bigint | undefined { return this.#confirmed_balance } - get confirmed_block_height (): number | undefined { return this.#confirmed_block_height } + get confirmed_height (): number | undefined { return this.#confirmed_height } get confirmed_frontier (): string | 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 } get balance (): bigint | undefined { return this.#balance } - get block_height (): number | undefined { return this.#block_height } + get block_count (): number | undefined { return this.#block_count } get frontier (): string | undefined { return this.#frontier } get frontier_block (): Block | undefined { return this.#frontier_block } get open_block (): string | undefined { return this.#open_block } @@ -63,7 +63,7 @@ export class Account { get weight (): bigint | undefined { return this.#weight } set confirmed_balance (v: bigint | number | string) { this.#confirmed_balance = BigInt(v) } - set confirmed_block_height (v: number | undefined) { if (v !== undefined) this.#confirmed_block_height = v | 0 } + 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_block (v: Block | undefined) { this.#confirmed_frontier_block = v } set confirmed_receivable (v: bigint | number | string) { this.#confirmed_receivable = BigInt(v) } @@ -78,7 +78,7 @@ export class Account { } set balance (v: bigint | number | string) { this.#balance = BigInt(v) } - set block_height (v: number | undefined) { if (v !== undefined) this.#block_height = v | 0 } + set block_count (v: number | undefined) { if (v !== undefined) this.#block_count = v | 0 } set frontier (v: string | undefined) { this.#frontier = v } set frontier_block (v: Block | undefined) { this.#frontier_block = v } set open_block (v: string | undefined) { this.#open_block = v } @@ -110,14 +110,28 @@ export class Account { } /** - * Removes encrypted secrets in storage and releases variable references to - * allow garbage collection. + * Releases variable references to allow garbage collection. */ async destroy (): Promise { - this.#frontier_block = undefined + this.#address = '' + this.#index = undefined + this.#publicKey.fill(0) + + this.#confirmed_balance = undefined + this.#confirmed_height = undefined + this.#confirmed_frontier = undefined + this.#confirmed_frontier_block = undefined + this.#confirmed_receivable = undefined + this.#confirmed_representative = undefined + this.#balance = undefined + this.#block_count = undefined + this.#frontier = undefined + this.#frontier_block = undefined + this.#open_block = undefined this.#receivable = undefined this.#representative = undefined + this.#representative_block = undefined this.#weight = undefined } @@ -222,29 +236,14 @@ export class Account { weight: true } const resAccountInfo = await rpc.call('account_info', reqAccountInfo) - const { confirmed_balance, confirmed_frontier, confirmed_height, confirmed_receivable, confirmed_representative, - balance, block_count, frontier, open_block, receivable, representative, representative_block, weight, - } = resAccountInfo - if (frontier == null) { + if (resAccountInfo.frontier == null) { throw new Error('Account not found') } - this.confirmed_balance = confirmed_balance - this.confirmed_block_height = confirmed_height - this.confirmed_frontier = confirmed_frontier - this.confirmed_representative = confirmed_representative - this.confirmed_receivable = confirmed_receivable - this.balance = balance - this.block_height = block_count - this.frontier = frontier - this.open_block = open_block - this.receivable = receivable - this.representative = representative - this.representative_block = representative_block - this.weight = weight + Object.assign(this, resAccountInfo) const reqConfirmedFrontier = { json_block: true, - hash: confirmed_frontier + hash: this.confirmed_frontier } const { contents: confirmedFrontierContents, subtype: confirmedFrontierSubtype } = await rpc.call('block_info', reqConfirmedFrontier) const confirmedFrontierBlock = new Block(confirmedFrontierContents.account, confirmedFrontierContents.balance, confirmedFrontierContents.previous, confirmedFrontierContents.representative) @@ -256,7 +255,7 @@ export class Account { const reqFrontier = { json_block: true, - hash: confirmed_frontier + hash: this.frontier } const { contents: frontierContents, subtype: frontierSubtype } = await rpc.call('block_info', reqFrontier) const frontierBlock = new Block(frontierContents.account, frontierContents.balance, frontierContents.previous, frontierContents.representative) -- 2.47.3