From: Chris Duncan Date: Sat, 20 Sep 2025 21:24:53 +0000 (-0700) Subject: Remove class self-references. X-Git-Tag: v0.10.5~12^2~32 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c5c2668435de7e93726cf25a013ab46db3b5cd05;p=libnemo.git Remove class self-references. --- diff --git a/package.json b/package.json index e5f99fe..9dd775f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/account/index.ts b/src/lib/account/index.ts index 4717317..2bfb6fc 100644 --- a/src/lib/account/index.ts +++ b/src/lib/account/index.ts @@ -24,6 +24,10 @@ type KeyPair = { */ export class Account { [key: string]: any + + /** + * @returns + */ static get DB_NAME (): 'Account' { return 'Account' } static #isInternal: boolean = false @@ -81,10 +85,10 @@ export class Account { set confirmed_frontier_block (v: Block | undefined) { this.#confirmed_frontier_block = v } set confirmed_receivable (v: bigint | number | string) { this.#confirmed_receivable = BigInt(v) } set confirmed_representative (v: unknown) { - if (v instanceof Account) { + if (v instanceof (this.constructor as typeof Account)) { this.#confirmed_representative = v } else if (typeof v === 'string') { - this.#confirmed_representative = Account.load(v) + this.#confirmed_representative = (this.constructor as typeof Account).load(v) } else { throw new TypeError(`Invalid argument for account confirmed representative: ${v}`) } @@ -97,10 +101,10 @@ export class Account { set open_block (v: string | undefined) { this.#open_block = v } set receivable (v: bigint | number | string) { this.#receivable = BigInt(v) } set representative (v: unknown) { - if (v instanceof Account || v === undefined) { + if (v instanceof (this.constructor as typeof Account) || v === undefined) { this.#representative = v } else if (typeof v === 'string') { - this.#representative = Account.load(v) + this.#representative = (this.constructor as typeof Account).load(v) } else { throw new TypeError(`Invalid argument for account representative: ${v}`) } @@ -109,10 +113,10 @@ export class Account { set weight (v: bigint | number | string) { this.#weight = BigInt(v) } private constructor (address: Address, publicKey: Uint8Array, index?: number) { - if (!Account.#isInternal) { + if (!this.constructor.prototype.#isInternal) { throw new Error('Account cannot be instantiated directly. Use `load()` instead.') } - Account.#isInternal = false + this.constructor.prototype.#isInternal = false this.#address = address this.#publicKey = publicKey this.#index = index diff --git a/src/lib/block.ts b/src/lib/block.ts index 0060907..16bafc7 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -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} Hash of the processed block */ async process (rpc: Rpc): Promise { - 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)