]> git.codecow.com Git - libnemo.git/commitdiff
Revert private account properties to match RPC data so that assignment from a refresh...
authorChris Duncan <chris@zoso.dev>
Thu, 21 Aug 2025 21:43:42 +0000 (14:43 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 21 Aug 2025 21:43:42 +0000 (14:43 -0700)
src/lib/account.ts

index bdb98ebeb58f506a33190800b84c3d081e3c808a..fec5f962637a25ae0543370629d6c7f9bb22618c 100644 (file)
@@ -25,14 +25,14 @@ export class Account {
        #publicKey: Uint8Array<ArrayBuffer>\r
 \r
        #confirmed_balance?: bigint\r
-       #confirmed_block_height?: number\r
+       #confirmed_height?: number\r
        #confirmed_frontier?: string\r
        #confirmed_frontier_block?: Block\r
        #confirmed_receivable?: bigint\r
        #confirmed_representative?: Account\r
 \r
        #balance?: bigint\r
-       #block_height?: number\r
+       #block_count?: number\r
        #frontier?: string\r
        #frontier_block?: Block\r
        #open_block?: string\r
@@ -46,14 +46,14 @@ export class Account {
        get publicKey (): string { return bytes.toHex(this.#publicKey) }\r
 \r
        get confirmed_balance (): bigint | undefined { return this.#confirmed_balance }\r
-       get confirmed_block_height (): number | undefined { return this.#confirmed_block_height }\r
+       get confirmed_height (): number | undefined { return this.#confirmed_height }\r
        get confirmed_frontier (): string | undefined { return this.#confirmed_frontier }\r
        get confirmed_frontier_block (): Block | undefined { return this.#confirmed_frontier_block }\r
        get confirmed_receivable (): bigint | undefined { return this.#confirmed_receivable }\r
        get confirmed_representative (): Account | undefined { return this.#confirmed_representative }\r
 \r
        get balance (): bigint | undefined { return this.#balance }\r
-       get block_height (): number | undefined { return this.#block_height }\r
+       get block_count (): number | undefined { return this.#block_count }\r
        get frontier (): string | undefined { return this.#frontier }\r
        get frontier_block (): Block | undefined { return this.#frontier_block }\r
        get open_block (): string | undefined { return this.#open_block }\r
@@ -63,7 +63,7 @@ export class Account {
        get weight (): bigint | undefined { return this.#weight }\r
 \r
        set confirmed_balance (v: bigint | number | string) { this.#confirmed_balance = BigInt(v) }\r
-       set confirmed_block_height (v: number | undefined) { if (v !== undefined) this.#confirmed_block_height = v | 0 }\r
+       set confirmed_height (v: number | undefined) { if (v !== undefined) this.#confirmed_height = v | 0 }\r
        set confirmed_frontier (v: string | undefined) { this.#confirmed_frontier = v }\r
        set confirmed_frontier_block (v: Block | undefined) { this.#confirmed_frontier_block = v }\r
        set confirmed_receivable (v: bigint | number | string) { this.#confirmed_receivable = BigInt(v) }\r
@@ -78,7 +78,7 @@ export class Account {
        }\r
 \r
        set balance (v: bigint | number | string) { this.#balance = BigInt(v) }\r
-       set block_height (v: number | undefined) { if (v !== undefined) this.#block_height = v | 0 }\r
+       set block_count (v: number | undefined) { if (v !== undefined) this.#block_count = v | 0 }\r
        set frontier (v: string | undefined) { this.#frontier = v }\r
        set frontier_block (v: Block | undefined) { this.#frontier_block = v }\r
        set open_block (v: string | undefined) { this.#open_block = v }\r
@@ -110,14 +110,28 @@ export class Account {
        }\r
 \r
        /**\r
-       * Removes encrypted secrets in storage and releases variable references to\r
-       * allow garbage collection.\r
+       * Releases variable references to allow garbage collection.\r
        */\r
        async destroy (): Promise<void> {\r
-               this.#frontier_block = undefined\r
+               this.#address = ''\r
+               this.#index = undefined\r
+               this.#publicKey.fill(0)\r
+\r
+               this.#confirmed_balance = undefined\r
+               this.#confirmed_height = undefined\r
+               this.#confirmed_frontier = undefined\r
+               this.#confirmed_frontier_block = undefined\r
+               this.#confirmed_receivable = undefined\r
+               this.#confirmed_representative = undefined\r
+\r
                this.#balance = undefined\r
+               this.#block_count = undefined\r
+               this.#frontier = undefined\r
+               this.#frontier_block = undefined\r
+               this.#open_block = undefined\r
                this.#receivable = undefined\r
                this.#representative = undefined\r
+               this.#representative_block = undefined\r
                this.#weight = undefined\r
        }\r
 \r
@@ -222,29 +236,14 @@ export class Account {
                        weight: true\r
                }\r
                const resAccountInfo = await rpc.call('account_info', reqAccountInfo)\r
-               const { confirmed_balance, confirmed_frontier, confirmed_height, confirmed_receivable, confirmed_representative,\r
-                       balance, block_count, frontier, open_block, receivable, representative, representative_block, weight,\r
-               } = resAccountInfo\r
-               if (frontier == null) {\r
+               if (resAccountInfo.frontier == null) {\r
                        throw new Error('Account not found')\r
                }\r
-               this.confirmed_balance = confirmed_balance\r
-               this.confirmed_block_height = confirmed_height\r
-               this.confirmed_frontier = confirmed_frontier\r
-               this.confirmed_representative = confirmed_representative\r
-               this.confirmed_receivable = confirmed_receivable\r
-               this.balance = balance\r
-               this.block_height = block_count\r
-               this.frontier = frontier\r
-               this.open_block = open_block\r
-               this.receivable = receivable\r
-               this.representative = representative\r
-               this.representative_block = representative_block\r
-               this.weight = weight\r
+               Object.assign(this, resAccountInfo)\r
 \r
                const reqConfirmedFrontier = {\r
                        json_block: true,\r
-                       hash: confirmed_frontier\r
+                       hash: this.confirmed_frontier\r
                }\r
                const { contents: confirmedFrontierContents, subtype: confirmedFrontierSubtype } = await rpc.call('block_info', reqConfirmedFrontier)\r
                const confirmedFrontierBlock = new Block(confirmedFrontierContents.account, confirmedFrontierContents.balance, confirmedFrontierContents.previous, confirmedFrontierContents.representative)\r
@@ -256,7 +255,7 @@ export class Account {
 \r
                const reqFrontier = {\r
                        json_block: true,\r
-                       hash: confirmed_frontier\r
+                       hash: this.frontier\r
                }\r
                const { contents: frontierContents, subtype: frontierSubtype } = await rpc.call('block_info', reqFrontier)\r
                const frontierBlock = new Block(frontierContents.account, frontierContents.balance, frontierContents.previous, frontierContents.representative)\r