From: Chris Duncan Date: Sun, 7 Sep 2025 19:42:30 +0000 (-0700) Subject: Enable proper JSON.stringify for accounts. X-Git-Tag: v0.10.5~24^2~8 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=e54d1cb3d208a042a4561fcaaad2121eb18afc76;p=libnemo.git Enable proper JSON.stringify for accounts. --- 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. *