"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",
*/\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
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
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
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
*
* @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')
}
* @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.')
}
}
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')
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)