]> git.codecow.com Git - libnemo.git/commitdiff
Remove class self-references.
authorChris Duncan <chris@zoso.dev>
Sat, 20 Sep 2025 21:24:53 +0000 (14:24 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 20 Sep 2025 21:24:53 +0000 (14:24 -0700)
package.json
src/lib/account/index.ts
src/lib/block.ts

index e5f99fe6cfdf938baf01f03e838e03096b4c435d..9dd775f319059d15ce24257b6510396dc72c3a6a 100644 (file)
@@ -45,7 +45,7 @@
        "scripts": {
                "clean": "rm -rf dist types && tsc",
                "build": "npm run clean && node esbuild/dev.mjs && cp -r types dist",
-               "build:prod": "npm run clean && node esbuild/prod.mjs",
+               "build:prod": "npm run clean && node esbuild/prod.mjs && cp -r types dist",
                "prepublishOnly": "npm run test:prod",
                "reinstall": "rm -rf node_modules package-lock.json && npm cache clean --force && npm i",
                "test": "npm run build && npm run test:node",
index 4717317d4ca9358660d5b4912b12c2b3320bcd2c..2bfb6fc4b4a72f803f42ca55e225d2b11f7cc30b 100644 (file)
@@ -24,6 +24,10 @@ type KeyPair = {
 */\r
 export class Account {\r
        [key: string]: any\r
+\r
+       /**\r
+        * @returns\r
+        */\r
        static get DB_NAME (): 'Account' { return 'Account' }\r
 \r
        static #isInternal: boolean = false\r
@@ -81,10 +85,10 @@ export class Account {
        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
        set confirmed_representative (v: unknown) {\r
-               if (v instanceof Account) {\r
+               if (v instanceof (this.constructor as typeof Account)) {\r
                        this.#confirmed_representative = v\r
                } else if (typeof v === 'string') {\r
-                       this.#confirmed_representative = Account.load(v)\r
+                       this.#confirmed_representative = (this.constructor as typeof Account).load(v)\r
                } else {\r
                        throw new TypeError(`Invalid argument for account confirmed representative: ${v}`)\r
                }\r
@@ -97,10 +101,10 @@ export class Account {
        set open_block (v: string | undefined) { this.#open_block = v }\r
        set receivable (v: bigint | number | string) { this.#receivable = BigInt(v) }\r
        set representative (v: unknown) {\r
-               if (v instanceof Account || v === undefined) {\r
+               if (v instanceof (this.constructor as typeof Account) || v === undefined) {\r
                        this.#representative = v\r
                } else if (typeof v === 'string') {\r
-                       this.#representative = Account.load(v)\r
+                       this.#representative = (this.constructor as typeof Account).load(v)\r
                } else {\r
                        throw new TypeError(`Invalid argument for account representative: ${v}`)\r
                }\r
@@ -109,10 +113,10 @@ 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.prototype.#isInternal) {\r
                        throw new Error('Account cannot be instantiated directly. Use `load()` instead.')\r
                }\r
-               Account.#isInternal = false\r
+               this.constructor.prototype.#isInternal = false\r
                this.#address = address\r
                this.#publicKey = publicKey\r
                this.#index = index\r
index 00609075ef19449da2d29ee8325edbe4d522b3b5..16bafc72e4c3d397dc048db9a1dfbb58c0b0991b 100644 (file)
@@ -20,7 +20,7 @@ export class Block {
         *
         * @param {Block} block - SendBlock, ReceiveBlock, or ChangeBlock to validate
         */
-       static #validate (block: unknown): asserts block is Block {
+       static validate (block: unknown): asserts block is Block {
                if (typeof block !== 'object') {
                        throw new TypeError('Invalid block')
                }
@@ -266,7 +266,8 @@ export class Block {
        * @returns {Promise<string>} Hash of the processed block
        */
        async process (rpc: Rpc): Promise<string> {
-               Block.#validate(this)
+               const b: typeof Block = this.constructor as typeof Block
+               b.validate(this)
                if (this.signature == null) {
                        throw new Error('Block is missing signature. Use sign() and try again.')
                }
@@ -313,7 +314,7 @@ export class Block {
                        }
                        this.balance += Tools.convert(amount, unit, 'raw', 'bigint')
 
-                       if (typeof sendBlock !== 'string' && !(sendBlock instanceof Block)) {
+                       if (typeof sendBlock !== 'string' && !(sendBlock instanceof (this.constructor as typeof Block))) {
                                throw new TypeError('Invalid send block')
                        }
                        this.link = (typeof sendBlock === 'string')
@@ -423,7 +424,7 @@ export class Block {
                                        const signature = await NanoNaCl.detached(this.#hash(), hex.toBytes(input))
                                        this.signature = bytes.toHex(signature)
                                } else if (input instanceof Wallet && typeof index === 'number'
-                                       && (frontier === undefined || frontier instanceof Block)
+                                       && (frontier === undefined || frontier instanceof (this.constructor as typeof Block))
                                ) {
                                        const wallet = input
                                        await wallet.sign(index, this, frontier)