]> git.codecow.com Git - libnemo.git/commitdiff
Update account internal flag to enable removing self references.
authorChris Duncan <chris@zoso.dev>
Sun, 21 Sep 2025 21:33:34 +0000 (14:33 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 21 Sep 2025 21:33:34 +0000 (14:33 -0700)
src/lib/account/index.ts

index f6b70b3f58edde14a23c4304144ee195d3356afe..850307bd863f9b17985ba725884a69177d960ab7 100644 (file)
@@ -25,13 +25,13 @@ type KeyPair = {
 export class Account {\r
        [key: string]: any\r
 \r
+       static #isInternal: boolean = false\r
+       static get isInternal (): boolean { return this.#isInternal }\r
        /**\r
-        * @returns\r
-        */\r
+       * @returns {'Account'}\r
+       */\r
        static get DB_NAME (): 'Account' { return 'Account' }\r
 \r
-       static #isInternal: boolean = false\r
-\r
        #address?: Address\r
        #index?: number\r
        #publicKey: Uint8Array<ArrayBuffer>\r
@@ -113,10 +113,9 @@ export class Account {
        set weight (v: bigint | number | string) { this.#weight = BigInt(v) }\r
 \r
        private constructor (address: Address, publicKey: Uint8Array<ArrayBuffer>, index?: number) {\r
-               if (!Account.#isInternal) {\r
+               if (!(this.constructor as typeof Account).isInternal) {\r
                        throw new Error('Account cannot be instantiated directly. Use `load()` instead.')\r
                }\r
-               Account.#isInternal = false\r
                this.#address = address\r
                this.#publicKey = publicKey\r
                this.#index = index\r
@@ -301,7 +300,9 @@ export class Account {
                                const publicKey = await NanoNaCl.convert(privateKey)\r
                                const address = new Address(publicKey)\r
                                this.#isInternal = true\r
-                               accounts.push(new this(address, publicKey, index))\r
+                               const account = new this(address, publicKey, index)\r
+                               this.#isInternal = false\r
+                               accounts.push(account)\r
                        }\r
                        return accounts\r
                } catch (err) {\r
@@ -336,7 +337,9 @@ export class Account {
                                const address = new Address(keypair.publicKey)\r
                                const publicKey = address.toPublicKey()\r
                                this.#isInternal = true\r
-                               accounts.push(new this(address, publicKey, index))\r
+                               const account = new this(address, publicKey, index)\r
+                               this.#isInternal = false\r
+                               accounts.push(account)\r
                        }\r
                        return accounts\r
                } catch (err) {\r