]> git.codecow.com Git - libnemo.git/commitdiff
Enable proper JSON.stringify for accounts.
authorChris Duncan <chris@zoso.dev>
Sun, 7 Sep 2025 19:42:30 +0000 (12:42 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 7 Sep 2025 19:42:30 +0000 (12:42 -0700)
src/lib/account/index.ts

index cc513e88357665c931067f9d9cad79723f661e4b..7ecdc748f85a870d724c43968d048a17a4a4757a 100644 (file)
@@ -139,6 +139,31 @@ export class Account {
                this.#weight = undefined\r
        }\r
 \r
+       /**\r
+        * Stringifies public properties into a JSON object so it can be further\r
+        * stringified by JSON.stringify()\r
+        */\r
+       toJSON () {\r
+               return {\r
+                       address: this.address,\r
+                       index: this.index,\r
+                       publicKey: this.publicKey,\r
+                       confirmed_balance: this.confirmed_balance?.toString(),\r
+                       confirmed_height: this.confirmed_height?.toString(),\r
+                       confirmed_frontier: this.confirmed_frontier,\r
+                       confirmed_receivable: this.confirmed_receivable?.toString(),\r
+                       confirmed_representative: this.confirmed_representative?.address,\r
+                       balance: this.balance?.toString(),\r
+                       block_count: this.block_count,\r
+                       frontier: this.frontier,\r
+                       open_block: this.open_block,\r
+                       receivable: this.receivable?.toString(),\r
+                       representative: this.representative?.address,\r
+                       representative_block: this.representative_block,\r
+                       weight: this.weight?.toString(),\r
+               }\r
+       }\r
+\r
        /**\r
        * Instantiates an Account object from its Nano address.\r
        *\r