From e54d1cb3d208a042a4561fcaaad2121eb18afc76 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 7 Sep 2025 12:42:30 -0700 Subject: [PATCH] Enable proper JSON.stringify for accounts. --- src/lib/account/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib/account/index.ts b/src/lib/account/index.ts index cc513e8..7ecdc74 100644 --- a/src/lib/account/index.ts +++ b/src/lib/account/index.ts @@ -139,6 +139,31 @@ export class Account { this.#weight = undefined } + /** + * Stringifies public properties into a JSON object so it can be further + * stringified by JSON.stringify() + */ + toJSON () { + return { + address: this.address, + index: this.index, + publicKey: this.publicKey, + confirmed_balance: this.confirmed_balance?.toString(), + confirmed_height: this.confirmed_height?.toString(), + confirmed_frontier: this.confirmed_frontier, + confirmed_receivable: this.confirmed_receivable?.toString(), + confirmed_representative: this.confirmed_representative?.address, + balance: this.balance?.toString(), + block_count: this.block_count, + frontier: this.frontier, + open_block: this.open_block, + receivable: this.receivable?.toString(), + representative: this.representative?.address, + representative_block: this.representative_block, + weight: this.weight?.toString(), + } + } + /** * Instantiates an Account object from its Nano address. * -- 2.47.3