set frontier (v) { this.#frontier = v }\r
set receivable (v) { this.#receivable = v ? BigInt(v) : undefined }\r
set representative (v) {\r
- if (v?.constructor === Account) {\r
+ if (v instanceof Account) {\r
this.#representative = v\r
} else if (typeof v === 'string') {\r
this.#representative = Account.fromAddress(v)\r
* @param {Rpc|string|URL} rpc - RPC node information required to call `account_info`\r
*/\r
async refresh (rpc: Rpc | string | URL): Promise<void> {\r
- if (typeof rpc === 'string' || rpc.constructor === URL) {\r
+ if (typeof rpc === 'string' || rpc instanceof URL) {\r
rpc = new Rpc(rpc)\r
}\r
- if (rpc.constructor !== Rpc) {\r
+ if (!(rpc instanceof Rpc)) {\r
throw new TypeError('RPC must be a valid node')\r
}\r
const data = {\r
if (rpc == null || wallet == null || recipient == null) {
throw new ReferenceError('Missing required sweep arguments')
}
- if (typeof rpc === 'string' || rpc.constructor === URL) {
+ if (typeof rpc === 'string' || rpc instanceof URL) {
rpc = new Rpc(rpc)
}
- if (rpc.constructor !== Rpc) {
+ if (!(rpc instanceof Rpc)) {
throw new TypeError('RPC must be a valid node')
}
const blockQueue: Promise<void>[] = []
if (typeof password === 'string') {\r
password = utf8.toBytes(password)\r
}\r
- if (password == null || password.constructor.name !== 'Uint8Array') {\r
+ if (password == null || !(password instanceof Uint8Array)) {\r
throw new Error('Failed to unlock wallet')\r
}\r
try {\r
* @returns {Promise<Account[]>} Accounts with updated balances, frontiers, and representatives\r
*/\r
async refresh (rpc: Rpc | string | URL, from: number = 0, to: number = from): Promise<AccountList> {\r
- if (typeof rpc === 'string' || rpc.constructor === URL) {\r
+ if (typeof rpc === 'string' || rpc instanceof URL) {\r
rpc = new Rpc(rpc)\r
}\r
- if (rpc.constructor !== Rpc) {\r
+ if (!(rpc instanceof Rpc)) {\r
throw new TypeError('RPC must be a valid node')\r
}\r
const accounts = await this.accounts(from, to)\r
if (typeof password === 'string') {\r
password = utf8.toBytes(password)\r
}\r
- if (password == null || password.constructor.name !== 'Uint8Array') {\r
+ if (password == null || !(password instanceof Uint8Array)) {\r
throw new Error('Failed to unlock wallet')\r
}\r
try {\r
}
static ser256 (integer: DataView): Uint8Array {
- if (integer.constructor !== DataView) {
+ if (!(integer instanceof DataView)) {
throw new TypeError(`Expected DataView, received ${typeof integer}`)
}
if (integer.byteLength > 32) {
const account = await wallet.account()
await account.refresh(rpc)
- assert.equals(typeof account.balance, 'bigint')
assert.exists(account.balance)
assert.notEqual(account.balance, '')
- assert.notEqual(account.balance && account.balance < 0, true)
+ assert.equals(typeof account.balance, 'bigint')
+ assert.ok(account.balance >= 0)
assert.exists(account.frontier)
assert.equals(typeof account.frontier, 'string')
assert.notEqual(account.frontier, '')
assert.ok(/^[A-Fa-f0-9]{64}$/.test(account.frontier))
- assert.equals(account.representative && account.representative.constructor, Account)
assert.exists(account.representative)
assert.notEqual(account.representative, '')
+ assert.equals(account.representative.constructor, Account)
assert.exists(account.representative?.address)
assert.notEqual(account.representative?.address, '')