diff --git a/bin/cli b/bin/cli index 247e72bf..77abe537 100755 --- a/bin/cli +++ b/bin/cli @@ -48,8 +48,8 @@ CLI.prototype.createWallet = async function createWallet() { type: this.config.str('type'), master: this.config.str('master'), mnemonic: this.config.str('mnemonic'), - m: this.config.num('m'), - n: this.config.num('n'), + m: this.config.uint('m'), + n: this.config.uint('n'), witness: this.config.bool('witness'), passphrase: this.config.str('passphrase'), watchOnly: false, @@ -123,8 +123,8 @@ CLI.prototype.createAccount = async function createAccount() { const options = { type: this.config.str('type'), - m: this.config.num('m'), - n: this.config.num('n'), + m: this.config.uint('m'), + n: this.config.uint('n'), witness: this.config.bool('witness'), accountKey: this.config.str('watch') }; @@ -199,7 +199,7 @@ CLI.prototype.getBlock = async function getBlock() { CLI.prototype.getCoin = async function getCoin() { const hash = this.config.str(0); - const index = this.config.num(1); + const index = this.config.uint(1); if (util.isBase58(hash)) { const coins = await this.client.getCoinsByAddress(hash); @@ -288,12 +288,12 @@ CLI.prototype.sendTX = async function sendTX() { if (this.config.has('script')) { outputs.push({ script: this.config.str('script'), - value: this.config.amt([0, 'value']) + value: this.config.ufixed([0, 'value'], 8) }); } else { outputs.push({ address: this.config.str([0, 'address']), - value: this.config.amt([1, 'value']) + value: this.config.ufixed([1, 'value'], 8) }); } @@ -309,7 +309,7 @@ CLI.prototype.sendTX = async function sendTX() { passphrase: this.config.str('passphrase'), outputs: outputs, smart: this.config.bool('smart'), - rate: this.config.amt('rate'), + rate: this.config.ufixed('rate', 8), subtractFee: this.config.bool('subtract-fee') }; @@ -324,12 +324,12 @@ CLI.prototype.createTX = async function createTX() { if (this.config.has('script')) { output = { script: this.config.str('script'), - value: this.config.amt([0, 'value']) + value: this.config.ufixed([0, 'value'], 8) }; } else { output = { address: this.config.str([0, 'address']), - value: this.config.amt([1, 'value']) + value: this.config.ufixed([1, 'value'], 8) }; } @@ -338,7 +338,7 @@ CLI.prototype.createTX = async function createTX() { passphrase: this.config.str('passphrase'), outputs: [output], smart: this.config.bool('smart'), - rate: this.config.amt('rate'), + rate: this.config.ufixed('rate', 8), subtractFee: this.config.bool('subtract-fee') }; @@ -356,7 +356,7 @@ CLI.prototype.signTX = async function signTX() { }; CLI.prototype.zapWallet = async function zapWallet() { - const age = this.config.num([0, 'age'], 72 * 60 * 60); + const age = this.config.uint([0, 'age'], 72 * 60 * 60); await this.wallet.zap(this.config.str('account'), age); this.log('Zapped!'); }; @@ -386,7 +386,7 @@ CLI.prototype.getWalletBlocks = async function getWalletBlocks() { }; CLI.prototype.getWalletBlock = async function getWalletBlock() { - const height = this.config.num(0); + const height = this.config.uint(0); const block = await this.wallet.getBlock(height); this.log(block); }; @@ -397,7 +397,7 @@ CLI.prototype.retoken = async function retoken() { }; CLI.prototype.rescan = async function rescan() { - const height = this.config.num(0); + const height = this.config.uint(0); await this.client.rescan(height); this.log('Rescanning...'); }; @@ -467,7 +467,7 @@ CLI.prototype.lock = async function lock() { CLI.prototype.unlock = async function unlock() { const passphrase = this.config.str(0); - const timeout = this.config.num(1); + const timeout = this.config.uint(1); await this.wallet.unlock(passphrase, timeout); this.log('Unlocked.'); }; diff --git a/lib/blockchain/chainentry.js b/lib/blockchain/chainentry.js index 949a70bc..c95dad82 100644 --- a/lib/blockchain/chainentry.js +++ b/lib/blockchain/chainentry.js @@ -469,12 +469,12 @@ ChainEntry.prototype.toJSON = function toJSON() { ChainEntry.prototype.fromJSON = function fromJSON(json) { assert(json, 'Block data is required.'); assert(typeof json.hash === 'string'); - assert(util.isUInt32(json.version)); + assert(util.isU32(json.version)); assert(typeof json.prevBlock === 'string'); assert(typeof json.merkleRoot === 'string'); - assert(util.isUInt32(json.time)); - assert(util.isUInt32(json.bits)); - assert(util.isUInt32(json.nonce)); + assert(util.isU32(json.time)); + assert(util.isU32(json.bits)); + assert(util.isU32(json.nonce)); assert(typeof json.chainwork === 'string'); this.hash = util.revHex(json.hash); diff --git a/lib/btc/amount.js b/lib/btc/amount.js index f5f6c20a..82033d32 100644 --- a/lib/btc/amount.js +++ b/lib/btc/amount.js @@ -140,7 +140,7 @@ Amount.prototype.toString = function toString() { */ Amount.prototype.fromValue = function fromValue(value) { - assert(util.isInt53(value), 'Value must be an int64.'); + assert(util.isI64(value), 'Value must be an int64.'); this.value = value; return this; }; diff --git a/lib/btc/uri.js b/lib/btc/uri.js index aff5695a..fa44142d 100644 --- a/lib/btc/uri.js +++ b/lib/btc/uri.js @@ -52,7 +52,7 @@ URI.prototype.fromOptions = function fromOptions(options) { this.address.fromOptions(options.address); if (options.amount != null) { - assert(util.isUInt53(options.amount), 'Amount must be a uint53.'); + assert(util.isU64(options.amount), 'Amount must be a uint64.'); this.amount = options.amount; } diff --git a/lib/http/rpc.js b/lib/http/rpc.js index fc0c74c8..e133c5cd 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1497,7 +1497,7 @@ RPC.prototype.prioritiseTransaction = async function prioritiseTransaction(args, const valid = new Validator([args]); const hash = valid.hash(0); - const pri = valid.num(1); + const pri = valid.i64(1); const fee = valid.i64(2); if (!this.mempool) @@ -1687,7 +1687,7 @@ RPC.prototype.createRawTransaction = async function createRawTransaction(args, h uniq.add(b58); - const value = sends.btc(key); + const value = sends.ufixed(key, 8); if (value == null) throw new RPCError(errs.TYPE_ERROR, 'Invalid output value.'); @@ -1832,7 +1832,7 @@ RPC.prototype.signRawTransaction = async function signRawTransaction(args, help) const hash = valid.hash('txid'); const index = valid.u32('index'); const scriptRaw = valid.buf('scriptPubKey'); - const value = valid.btc('amount'); + const value = valid.ufixed('amount', 8); const redeemRaw = valid.buf('redeemScript'); if (!hash || index == null || !scriptRaw || value == null) @@ -2186,7 +2186,7 @@ RPC.prototype.handleLongpoll = async function handleLongpoll(lpid) { const watched = lpid.slice(0, 64); const lastTX = parseInt(lpid.slice(64, 74), 10); - if (!util.isHex(watched) || !util.isUInt32(lastTX)) + if (!util.isHex(watched) || !util.isU32(lastTX)) throw new RPCError(errs.INVALID_PARAMETER, 'Invalid longpoll ID.'); const hash = util.revHex(watched); diff --git a/lib/mempool/fees.js b/lib/mempool/fees.js index 1598c34e..2519f4ce 100644 --- a/lib/mempool/fees.js +++ b/lib/mempool/fees.js @@ -691,7 +691,7 @@ PolicyEstimator.prototype.estimateFee = function estimateFee(target, smart) { if (smart == null) smart = true; - assert(util.isUInt32(target), 'Target must be a number.'); + assert(util.isU32(target), 'Target must be a number.'); assert(target <= this.feeStats.maxConfirms, 'Too many confirmations for estimate.'); @@ -735,7 +735,7 @@ PolicyEstimator.prototype.estimatePriority = function estimatePriority(target, s if (smart == null) smart = true; - assert(util.isUInt32(target), 'Target must be a number.'); + assert(util.isU32(target), 'Target must be a number.'); assert(target <= this.priStats.maxConfirms, 'Too many confirmations for estimate.'); diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 4f91c4bf..7c7c9ff2 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -1980,7 +1980,7 @@ MempoolOptions.prototype.fromOptions = function fromOptions(options) { } if (options.limitFreeRelay != null) { - assert(util.isUInt32(options.limitFreeRelay)); + assert(util.isU32(options.limitFreeRelay)); this.limitFreeRelay = options.limitFreeRelay; } @@ -2015,27 +2015,27 @@ MempoolOptions.prototype.fromOptions = function fromOptions(options) { } if (options.maxSize != null) { - assert(util.isUInt53(options.maxSize)); + assert(util.isU64(options.maxSize)); this.maxSize = options.maxSize; } if (options.maxOrphans != null) { - assert(util.isUInt32(options.maxOrphans)); + assert(util.isU32(options.maxOrphans)); this.maxOrphans = options.maxOrphans; } if (options.maxAncestors != null) { - assert(util.isUInt32(options.maxAncestors)); + assert(util.isU32(options.maxAncestors)); this.maxAncestors = options.maxAncestors; } if (options.expiryTime != null) { - assert(util.isUInt32(options.expiryTime)); + assert(util.isU32(options.expiryTime)); this.expiryTime = options.expiryTime; } if (options.minRelay != null) { - assert(util.isUint53(options.minRelay)); + assert(util.isU64(options.minRelay)); this.minRelay = options.minRelay; } @@ -2056,12 +2056,12 @@ MempoolOptions.prototype.fromOptions = function fromOptions(options) { } if (options.maxFiles != null) { - assert(util.isUInt32(options.maxFiles)); + assert(util.isU32(options.maxFiles)); this.maxFiles = options.maxFiles; } if (options.cacheSize != null) { - assert(util.isUInt53(options.cacheSize)); + assert(util.isU64(options.cacheSize)); this.cacheSize = options.cacheSize; } diff --git a/lib/net/hostlist.js b/lib/net/hostlist.js index d7d1029b..e1369864 100644 --- a/lib/net/hostlist.js +++ b/lib/net/hostlist.js @@ -1375,7 +1375,7 @@ HostEntry.prototype.fromJSON = function fromJSON(json, network) { assert(json.services.length > 0); assert(json.services.length <= 32); this.addr.services = parseInt(json.services, 2); - assert(util.isUInt32(this.addr.services)); + assert(util.isU32(this.addr.services)); } if (json.time != null) { diff --git a/lib/net/pool.js b/lib/net/pool.js index ef2f3d16..7859a55c 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -3900,12 +3900,12 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) { this.listen = false; if (options.services != null) { - assert(util.isUInt32(options.services)); + assert(util.isU32(options.services)); this.services = options.services; } if (options.requiredServices != null) { - assert(util.isUInt32(options.requiredServices)); + assert(util.isU32(options.requiredServices)); this.requiredServices = options.requiredServices; } diff --git a/lib/node/config.js b/lib/node/config.js index cc115d2f..bf016b92 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -255,13 +255,13 @@ Config.prototype.str = function str(key, fallback) { }; /** - * Get a config option (as a number). + * Get a config option (as an integer). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Config.prototype.num = function num(key, fallback) { +Config.prototype.int = function int(key, fallback) { let value = this.get(key); if (fallback === undefined) @@ -272,17 +272,46 @@ Config.prototype.num = function num(key, fallback) { if (typeof value !== 'string') { if (typeof value !== 'number') - throw new Error(`${fmt(key)} must be a positive integer.`); + throw new Error(`${fmt(key)} must be an int.`); + + if (!Number.isSafeInteger(value)) + throw new Error(`${fmt(key)} must be an int (53 bit max).`); + + if (value % 1 !== 0) + throw new Error(`${fmt(key)} must be an int (float).`); + return value; } - if (!/^\d+$/.test(value)) - throw new Error(`${fmt(key)} must be a positive integer.`); + if (!/^\-?\d+$/.test(value)) + throw new Error(`${fmt(key)} must be an int.`); value = parseInt(value, 10); - if (!isFinite(value)) - throw new Error(`${fmt(key)} must be a positive integer.`); + if (!Number.isSafeInteger(value)) + throw new Error(`${fmt(key)} must be an int (53 bit max).`); + + return value; +}; + +/** + * Get a config option (as a unsigned integer). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Config.prototype.uint = function uint(key, fallback) { + const value = this.int(key); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < 0) + throw new Error(`${fmt(key)} must be a uint.`); return value; }; @@ -294,7 +323,7 @@ Config.prototype.num = function num(key, fallback) { * @returns {Number|null} */ -Config.prototype.flt = function flt(key, fallback) { +Config.prototype.float = function float(key, fallback) { let value = this.get(key); if (fallback === undefined) @@ -306,10 +335,17 @@ Config.prototype.flt = function flt(key, fallback) { if (typeof value !== 'string') { if (typeof value !== 'number') throw new Error(`${fmt(key)} must be a float.`); + + if (!isFinite(value)) + throw new Error(`${fmt(key)} must be a float.`); + return value; } - if (!/^\d*(?:\.\d*)?$/.test(value)) + if (!/^\-?\d*(?:\.\d*)?$/.test(value)) + throw new Error(`${fmt(key)} must be a float.`); + + if (!/\d/.test(value)) throw new Error(`${fmt(key)} must be a float.`); value = parseFloat(value); @@ -321,14 +357,14 @@ Config.prototype.flt = function flt(key, fallback) { }; /** - * Get a value (as a satoshi number or btc string). + * Get a config option (as a positive float). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Config.prototype.amt = function amt(key, fallback) { - const value = this.get(key); +Config.prototype.ufloat = function ufloat(key, fallback) { + const value = this.float(key); if (fallback === undefined) fallback = null; @@ -336,21 +372,59 @@ Config.prototype.amt = function amt(key, fallback) { if (value === null) return fallback; - if (typeof value !== 'string') { - if (typeof value !== 'number') - throw new Error(`${fmt(key)} must be an amount.`); - if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff) - throw new Error(`${fmt(key)} must be an amount (u64).`); - return value; - } + if (value < 0) + throw new Error(`${fmt(key)} must be a positive float.`); + + return value; +}; + +/** + * Get a value (as a fixed number). + * @param {String} key + * @param {Number?} exp + * @param {Object?} fallback + * @returns {Number|null} + */ + +Config.prototype.fixed = function fixed(key, exp, fallback) { + const value = this.float(key); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; try { - return util.fromFixed(value, 8); + return util.fromFixed(value.toString(10), exp || 0); } catch (e) { - throw new Error(`${fmt(key)} must be an amount (parse).`); + throw new Error(`${fmt(key)} must be a fixed number.`); } }; +/** + * Get a value (as a positive fixed number). + * @param {String} key + * @param {Number?} exp + * @param {Object?} fallback + * @returns {Number|null} + */ + +Config.prototype.ufixed = function ufixed(key, exp, fallback) { + const value = this.fixed(key, exp); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < 0) + throw new Error(`${fmt(key)} must be a positive fixed number.`); + + return value; +}; + /** * Get a config option (as a boolean). * @param {String} key @@ -529,7 +603,7 @@ Config.prototype.path = function _path(key, fallback) { */ Config.prototype.mb = function mb(key, fallback) { - const value = this.num(key); + const value = this.uint(key); if (fallback === undefined) fallback = null; diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 68b66dc0..0ad663a1 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -54,7 +54,7 @@ function FullNode(options) { workers: this.workers, db: this.config.str('db'), prefix: this.config.prefix, - maxFiles: this.config.num('max-files'), + maxFiles: this.config.uint('max-files'), cacheSize: this.config.mb('cache-size'), forceFlags: this.config.bool('force-flags'), bip91: this.config.bool('bip91'), @@ -62,7 +62,7 @@ function FullNode(options) { prune: this.config.bool('prune'), checkpoints: this.config.bool('checkpoints'), coinCache: this.config.mb('coin-cache'), - entryCache: this.config.num('entry-cache'), + entryCache: this.config.uint('entry-cache'), indexTX: this.config.bool('index-tx'), indexAddress: this.config.bool('index-address') }); @@ -83,7 +83,7 @@ function FullNode(options) { persistent: this.config.bool('persistent-mempool'), maxSize: this.config.mb('mempool-size'), limitFree: this.config.bool('limit-free'), - limitFreeRelay: this.config.num('limit-free-relay'), + limitFreeRelay: this.config.uint('limit-free-relay'), requireStandard: this.config.bool('require-standard'), rejectAbsurdFees: this.config.bool('reject-absurd-fees'), replaceByFee: this.config.bool('replace-by-fee'), @@ -103,8 +103,8 @@ function FullNode(options) { bip151: this.config.bool('bip151'), bip150: this.config.bool('bip150'), identityKey: this.config.buf('identity-key'), - maxOutbound: this.config.num('max-outbound'), - maxInbound: this.config.num('max-inbound'), + maxOutbound: this.config.uint('max-outbound'), + maxInbound: this.config.uint('max-inbound'), proxy: this.config.str('proxy'), onion: this.config.bool('onion'), upnp: this.config.bool('upnp'), @@ -112,9 +112,9 @@ function FullNode(options) { nodes: this.config.array('nodes'), only: this.config.array('only'), publicHost: this.config.str('public-host'), - publicPort: this.config.num('public-port'), + publicPort: this.config.uint('public-port'), host: this.config.str('host'), - port: this.config.num('port'), + port: this.config.uint('port'), listen: this.config.bool('listen'), persistent: this.config.bool('persistent') }); @@ -129,9 +129,9 @@ function FullNode(options) { address: this.config.array('coinbase-address'), coinbaseFlags: this.config.str('coinbase-flags'), preverify: this.config.bool('preverify'), - maxWeight: this.config.num('max-weight'), - reservedWeight: this.config.num('reserved-weight'), - reservedSigops: this.config.num('reserved-sigops') + maxWeight: this.config.uint('max-weight'), + reservedWeight: this.config.uint('reserved-weight'), + reservedSigops: this.config.uint('reserved-sigops') }); // RPC needs access to the node. @@ -148,7 +148,7 @@ function FullNode(options) { keyFile: this.config.path('ssl-key'), certFile: this.config.path('ssl-cert'), host: this.config.str('http-host'), - port: this.config.num('http-port'), + port: this.config.uint('http-port'), apiKey: this.config.str('api-key'), noAuth: this.config.bool('no-auth') }); diff --git a/lib/node/node.js b/lib/node/node.js index d27615cb..9e9d7f86 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -87,8 +87,8 @@ Node.prototype.initOptions = function initOptions() { this.workers = new WorkerPool({ enabled: config.bool('workers'), - size: config.num('workers-size'), - timeout: config.num('workers-timeout'), + size: config.uint('workers-size'), + timeout: config.uint('workers-timeout'), file: config.str('worker-file') }); }; diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index 966dce16..ab852fba 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -49,9 +49,9 @@ function SPVNode(options) { logger: this.logger, db: this.config.str('db'), prefix: this.config.prefix, - maxFiles: this.config.num('max-files'), + maxFiles: this.config.uint('max-files'), cacheSize: this.config.mb('cache-size'), - entryCache: this.config.num('entry-cache'), + entryCache: this.config.uint('entry-cache'), forceFlags: this.config.bool('force-flags'), checkpoints: this.config.bool('checkpoints'), bip91: this.config.bool('bip91'), @@ -73,7 +73,7 @@ function SPVNode(options) { bip151: this.config.bool('bip151'), bip150: this.config.bool('bip150'), identityKey: this.config.buf('identity-key'), - maxOutbound: this.config.num('max-outbound'), + maxOutbound: this.config.uint('max-outbound'), persistent: this.config.bool('persistent'), selfish: true, listen: false @@ -91,7 +91,7 @@ function SPVNode(options) { keyFile: this.config.path('ssl-key'), certFile: this.config.path('ssl-cert'), host: this.config.str('http-host'), - port: this.config.num('http-port'), + port: this.config.uint('http-port'), apiKey: this.config.str('api-key'), noAuth: this.config.bool('no-auth') }); diff --git a/lib/primitives/coin.js b/lib/primitives/coin.js index b5e73221..9fcbe91b 100644 --- a/lib/primitives/coin.js +++ b/lib/primitives/coin.js @@ -61,13 +61,13 @@ Coin.prototype.fromOptions = function fromOptions(options) { assert(options, 'Coin data is required.'); if (options.version != null) { - assert(util.isUInt32(options.version), 'Version must be a uint32.'); + assert(util.isU32(options.version), 'Version must be a uint32.'); this.version = options.version; } if (options.height != null) { if (options.height !== -1) { - assert(util.isUInt32(options.height), 'Height must be a uint32.'); + assert(util.isU32(options.height), 'Height must be a uint32.'); this.height = options.height; } else { this.height = -1; @@ -75,7 +75,7 @@ Coin.prototype.fromOptions = function fromOptions(options) { } if (options.value != null) { - assert(util.isUInt53(options.value), 'Value must be a uint53.'); + assert(util.isU64(options.value), 'Value must be a uint64.'); this.value = options.value; } @@ -94,7 +94,7 @@ Coin.prototype.fromOptions = function fromOptions(options) { } if (options.index != null) { - assert(util.isUInt32(options.index), 'Index must be a uint32.'); + assert(util.isU32(options.index), 'Index must be a uint32.'); this.index = options.index; } @@ -262,10 +262,10 @@ Coin.prototype.getJSON = function getJSON(network, minimal) { Coin.prototype.fromJSON = function fromJSON(json) { assert(json, 'Coin data required.'); - assert(util.isUInt32(json.version), 'Version must be a uint32.'); - assert(json.height === -1 || util.isUInt32(json.height), + assert(util.isU32(json.version), 'Version must be a uint32.'); + assert(json.height === -1 || util.isU32(json.height), 'Height must be a uint32.'); - assert(util.isUInt53(json.value), 'Value must be a uint53.'); + assert(util.isU64(json.value), 'Value must be a uint64.'); assert(typeof json.coinbase === 'boolean', 'Coinbase must be a boolean.'); this.version = json.version; @@ -277,7 +277,7 @@ Coin.prototype.fromJSON = function fromJSON(json) { if (json.hash != null) { assert(typeof json.hash === 'string', 'Hash must be a string.'); assert(json.hash.length === 64, 'Hash must be a string.'); - assert(util.isUInt32(json.index), 'Index must be a uint32.'); + assert(util.isU32(json.index), 'Index must be a uint32.'); this.hash = util.revHex(json.hash); this.index = json.index; } diff --git a/lib/primitives/input.js b/lib/primitives/input.js index 5178bcd7..a4dc2b64 100644 --- a/lib/primitives/input.js +++ b/lib/primitives/input.js @@ -55,7 +55,7 @@ Input.prototype.fromOptions = function fromOptions(options) { this.script.fromOptions(options.script); if (options.sequence != null) { - assert(util.isUInt32(options.sequence), 'Sequence must be a uint32.'); + assert(util.isU32(options.sequence), 'Sequence must be a uint32.'); this.sequence = options.sequence; } @@ -311,7 +311,7 @@ Input.prototype.getJSON = function getJSON(network, coin) { Input.prototype.fromJSON = function fromJSON(json) { assert(json, 'Input data is required.'); - assert(util.isUInt32(json.sequence), 'Sequence must be a uint32.'); + assert(util.isU32(json.sequence), 'Sequence must be a uint32.'); this.prevout.fromJSON(json.prevout); this.script.fromJSON(json.script); this.witness.fromJSON(json.witness); diff --git a/lib/primitives/merkleblock.js b/lib/primitives/merkleblock.js index 07fcca76..8800e115 100644 --- a/lib/primitives/merkleblock.js +++ b/lib/primitives/merkleblock.js @@ -57,7 +57,7 @@ MerkleBlock.prototype.fromOptions = function fromOptions(options) { assert(options, 'MerkleBlock data is required.'); assert(Array.isArray(options.hashes)); assert(Buffer.isBuffer(options.flags)); - assert(util.isUInt32(options.totalTX)); + assert(util.isU32(options.totalTX)); if (options.hashes) { for (let hash of options.hashes) { @@ -74,7 +74,7 @@ MerkleBlock.prototype.fromOptions = function fromOptions(options) { } if (options.totalTX != null) { - assert(util.isUInt32(options.totalTX)); + assert(util.isU32(options.totalTX)); this.totalTX = options.totalTX; } @@ -468,7 +468,7 @@ MerkleBlock.prototype.fromJSON = function fromJSON(json) { assert(json, 'MerkleBlock data is required.'); assert(Array.isArray(json.hashes)); assert(typeof json.flags === 'string'); - assert(util.isUInt32(json.totalTX)); + assert(util.isU32(json.totalTX)); this.parseJSON(json); diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index c145215e..e0940fa5 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -66,12 +66,12 @@ util.inherits(MTX, TX); MTX.prototype.fromOptions = function fromOptions(options) { if (options.version != null) { - assert(util.isUInt32(options.version), 'Version must a be uint32.'); + assert(util.isU32(options.version), 'Version must a be uint32.'); this.version = options.version; } if (options.flag != null) { - assert(util.isUInt8(options.flag), 'Flag must be a uint8.'); + assert(util.isU8(options.flag), 'Flag must be a uint8.'); this.flag = options.flag; } @@ -88,13 +88,13 @@ MTX.prototype.fromOptions = function fromOptions(options) { } if (options.locktime != null) { - assert(util.isUInt32(options.locktime), 'Locktime must be a uint32.'); + assert(util.isU32(options.locktime), 'Locktime must be a uint32.'); this.locktime = options.locktime; } if (options.changeIndex != null) { if (options.changeIndex !== -1) { - assert(util.isUInt32(options.changeIndex), + assert(util.isU32(options.changeIndex), 'Change index must be a uint32.'); this.changeIndex = options.changeIndex; } else { @@ -227,7 +227,7 @@ MTX.prototype.addOutput = function addOutput(script, value) { let output; if (value != null) { - assert(util.isUInt53(value), 'Value must be a uint53.'); + assert(util.isU64(value), 'Value must be a uint64.'); output = Output.fromScript(script, value); } else { output = Output.fromOptions(script); @@ -1290,7 +1290,7 @@ MTX.prototype.avoidFeeSniping = function avoidFeeSniping(height) { */ MTX.prototype.setLocktime = function setLocktime(locktime) { - assert(util.isUInt32(locktime), 'Locktime must be a uint32.'); + assert(util.isU32(locktime), 'Locktime must be a uint32.'); assert(this.inputs.length > 0, 'Cannot set sequence with no inputs.'); for (const input of this.inputs) { @@ -1312,7 +1312,7 @@ MTX.prototype.setSequence = function setSequence(index, locktime, seconds) { const input = this.inputs[index]; assert(input, 'Input does not exist.'); - assert(util.isUInt32(locktime), 'Locktime must be a uint32.'); + assert(util.isU32(locktime), 'Locktime must be a uint32.'); this.version = 2; @@ -1508,7 +1508,7 @@ CoinSelector.prototype.fromOptions = function fromOptions(options) { if (options.subtractFee != null) { if (typeof options.subtractFee === 'number') { - assert(util.isUInt32(options.subtractFee)); + assert(util.isU32(options.subtractFee)); this.subtractFee = options.subtractFee; this.shouldSubtract = true; } else { diff --git a/lib/primitives/outpoint.js b/lib/primitives/outpoint.js index a23400ea..24720a9a 100644 --- a/lib/primitives/outpoint.js +++ b/lib/primitives/outpoint.js @@ -31,7 +31,7 @@ function Outpoint(hash, index) { if (hash != null) { assert(typeof hash === 'string', 'Hash must be a string.'); - assert(util.isUInt32(index), 'Index must be a uint32.'); + assert(util.isU32(index), 'Index must be a uint32.'); this.hash = hash; this.index = index; } @@ -46,7 +46,7 @@ function Outpoint(hash, index) { Outpoint.prototype.fromOptions = function fromOptions(options) { assert(options, 'Outpoint data is required.'); assert(typeof options.hash === 'string', 'Hash must be a string.'); - assert(util.isUInt32(options.index), 'Index must be a uint32.'); + assert(util.isU32(options.index), 'Index must be a uint32.'); this.hash = options.hash; this.index = options.index; return this; @@ -204,7 +204,7 @@ Outpoint.fromRaw = function fromRaw(data) { Outpoint.prototype.fromJSON = function fromJSON(json) { assert(json, 'Outpoint data is required.'); assert(typeof json.hash === 'string', 'Hash must be a string.'); - assert(util.isUInt32(json.index), 'Index must be a uint32.'); + assert(util.isU32(json.index), 'Index must be a uint32.'); this.hash = util.revHex(json.hash); this.index = json.index; return this; diff --git a/lib/primitives/output.js b/lib/primitives/output.js index 1c76949f..a1abf333 100644 --- a/lib/primitives/output.js +++ b/lib/primitives/output.js @@ -48,7 +48,7 @@ Output.prototype.fromOptions = function fromOptions(options) { assert(options, 'Output data is required.'); if (options.value) { - assert(util.isUInt53(options.value), 'Value must be a uint53.'); + assert(util.isU64(options.value), 'Value must be a uint64.'); this.value = options.value; } @@ -87,7 +87,7 @@ Output.prototype.fromScript = function fromScript(script, value) { script = Script.fromAddress(script); assert(script instanceof Script, 'Script must be a Script.'); - assert(util.isUInt53(value), 'Value must be a uint53.'); + assert(util.isU64(value), 'Value must be a uint64.'); this.script = script; this.value = value; @@ -249,7 +249,7 @@ Output.prototype.isDust = function isDust(rate) { Output.prototype.fromJSON = function fromJSON(json) { assert(json, 'Output data is required.'); - assert(util.isUInt53(json.value), 'Value must be a uint53.'); + assert(util.isU64(json.value), 'Value must be a uint64.'); this.value = json.value; this.script.fromJSON(json.script); return this; diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 39b5af2d..7c20d260 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -80,12 +80,12 @@ TX.prototype.fromOptions = function fromOptions(options) { assert(options, 'TX data is required.'); if (options.version != null) { - assert(util.isUInt32(options.version), 'Version must be a uint32.'); + assert(util.isU32(options.version), 'Version must be a uint32.'); this.version = options.version; } if (options.flag != null) { - assert(util.isUInt8(options.flag), 'Flag must be a uint8.'); + assert(util.isU8(options.flag), 'Flag must be a uint8.'); this.flag = options.flag; } @@ -102,7 +102,7 @@ TX.prototype.fromOptions = function fromOptions(options) { } if (options.locktime != null) { - assert(util.isUInt32(options.locktime), 'Locktime must be a uint32.'); + assert(util.isU32(options.locktime), 'Locktime must be a uint32.'); this.locktime = options.locktime; } @@ -2181,11 +2181,11 @@ TX.prototype.getJSON = function getJSON(network, view, entry, index) { TX.prototype.fromJSON = function fromJSON(json) { assert(json, 'TX data is required.'); - assert(util.isUInt32(json.version), 'Version must be a uint32.'); - assert(util.isUInt8(json.flag), 'Flag must be a uint8.'); + assert(util.isU32(json.version), 'Version must be a uint32.'); + assert(util.isU8(json.flag), 'Flag must be a uint8.'); assert(Array.isArray(json.inputs), 'Inputs must be an array.'); assert(Array.isArray(json.outputs), 'Outputs must be an array.'); - assert(util.isUInt32(json.locktime), 'Locktime must be a uint32.'); + assert(util.isU32(json.locktime), 'Locktime must be a uint32.'); this.version = json.version; this.flag = json.flag; diff --git a/lib/utils/util.js b/lib/utils/util.js index c51c9e2b..5e7e390b 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -158,7 +158,7 @@ util.isSafeAddition = function isSafeAddition(a, b) { */ util.isNumber = function isNumber(value) { - return typeof value === 'number' && Number.isSafeInteger(value); + return Number.isSafeInteger(value); }; /** @@ -171,24 +171,34 @@ util.isInt = function isInt(value) { return util.isNumber(value) && value % 1 === 0; }; +/** + * Test whether an object is an int. + * @param {Number?} value + * @returns {Boolean} + */ + +util.isUint = function isUint(value) { + return util.isInt(value) && value >= 0; +}; + /** * Test whether an object is an int8. * @param {Number?} value * @returns {Boolean} */ -util.isInt8 = function isInt8(value) { +util.isI8 = function isI8(value) { return (value | 0) === value && value >= -0x80 && value <= 0x7f; }; /** - * Test whether an object is a uint8. + * Test whether an object is an int16. * @param {Number?} value * @returns {Boolean} */ -util.isUInt8 = function isUInt8(value) { - return (value >>> 0) === value && value >= 0 && value <= 0xff; +util.isI16 = function isI16(value) { + return (value | 0) === value && value >= -0x8000 && value <= 0x7fff; }; /** @@ -197,38 +207,58 @@ util.isUInt8 = function isUInt8(value) { * @returns {Boolean} */ -util.isInt32 = function isInt32(value) { +util.isI32 = function isI32(value) { return (value | 0) === value; }; -/** - * Test whether an object is a uint32. - * @param {Number?} value - * @returns {Boolean} - */ - -util.isUInt32 = function isUInt32(value) { - return (value >>> 0) === value; -}; - /** * Test whether an object is a int53. * @param {Number?} value * @returns {Boolean} */ -util.isInt53 = function isInt53(value) { +util.isI64 = function isI64(value) { return util.isInt(value); }; +/** + * Test whether an object is a uint8. + * @param {Number?} value + * @returns {Boolean} + */ + +util.isU8 = function isU8(value) { + return (value & 0xff) === value; +}; + +/** + * Test whether an object is a uint16. + * @param {Number?} value + * @returns {Boolean} + */ + +util.isU16 = function isU16(value) { + return (value & 0xffff) === value; +}; + +/** + * Test whether an object is a uint32. + * @param {Number?} value + * @returns {Boolean} + */ + +util.isU32 = function isU32(value) { + return (value >>> 0) === value; +}; + /** * Test whether an object is a uint53. * @param {Number?} value * @returns {Boolean} */ -util.isUInt53 = function isUInt53(value) { - return util.isInt(value) && value >= 0; +util.isU64 = function isU64(value) { + return util.isUint(value); }; /** diff --git a/lib/utils/validator.js b/lib/utils/validator.js index 2f15ca9b..a9b5110a 100644 --- a/lib/utils/validator.js +++ b/lib/utils/validator.js @@ -120,13 +120,13 @@ Validator.prototype.str = function str(key, fallback) { }; /** - * Get a value (as a number). + * Get a value (as an integer). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.num = function num(key, fallback) { +Validator.prototype.int = function int(key, fallback) { let value = this.get(key); if (fallback === undefined) @@ -137,29 +137,58 @@ Validator.prototype.num = function num(key, fallback) { if (typeof value !== 'string') { if (typeof value !== 'number') - throw new ValidationError(key, 'number'); + throw new ValidationError(key, 'int'); + + if (!Number.isSafeInteger(value)) + throw new ValidationError(key, 'int (53 bit max)'); + + if (value % 1 !== 0) + throw new ValidationError(key, 'int (float)'); + return value; } - if (!/^\d+$/.test(value)) - throw new ValidationError(key, 'number'); + if (!/^\-?\d+$/.test(value)) + throw new ValidationError(key, 'int'); value = parseInt(value, 10); - if (!isFinite(value)) - throw new ValidationError(key, 'number'); + if (!Number.isSafeInteger(value)) + throw new ValidationError(key, 'int (53 bit max)'); return value; }; /** - * Get a value (as a number). + * Get a value (as a signed integer). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.flt = function flt(key, fallback) { +Validator.prototype.uint = function uint(key, fallback) { + const value = this.int(key); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < 0) + throw new ValidationError(key, 'uint'); + + return value; +}; + +/** + * Get a value (as a float). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.float = function float(key, fallback) { let value = this.get(key); if (fallback === undefined) @@ -171,10 +200,17 @@ Validator.prototype.flt = function flt(key, fallback) { if (typeof value !== 'string') { if (typeof value !== 'number') throw new ValidationError(key, 'float'); + + if (!isFinite(value)) + throw new ValidationError(key, 'float'); + return value; } - if (!/^\d*(?:\.\d*)?$/.test(value)) + if (!/^\-?\d*(?:\.\d*)?$/.test(value)) + throw new ValidationError(key, 'float'); + + if (!/\d/.test(value)) throw new ValidationError(key, 'float'); value = parseFloat(value); @@ -186,14 +222,14 @@ Validator.prototype.flt = function flt(key, fallback) { }; /** - * Get a value (as a uint32). + * Get a value (as a positive float). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.u32 = function u32(key, fallback) { - const value = this.num(key); +Validator.prototype.ufloat = function ufloat(key, fallback) { + const value = this.float(key); if (fallback === undefined) fallback = null; @@ -201,21 +237,22 @@ Validator.prototype.u32 = function u32(key, fallback) { if (value === null) return fallback; - if ((value >>> 0) !== value) - throw new ValidationError(key, 'uint32'); + if (value < 0) + throw new ValidationError(key, 'positive float'); return value; }; /** - * Get a value (as a uint64). + * Get a value (as a fixed number). * @param {String} key + * @param {Number?} exp * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.u64 = function u64(key, fallback) { - const value = this.num(key); +Validator.prototype.fixed = function fixed(key, exp, fallback) { + const value = this.float(key); if (fallback === undefined) fallback = null; @@ -223,8 +260,76 @@ Validator.prototype.u64 = function u64(key, fallback) { if (value === null) return fallback; - if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff) - throw new ValidationError(key, 'uint64'); + try { + return util.fromFixed(value.toString(10), exp || 0); + } catch (e) { + throw new ValidationError(key, 'fixed number'); + } +}; + +/** + * Get a value (as a positive fixed number). + * @param {String} key + * @param {Number?} exp + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.ufixed = function ufixed(key, exp, fallback) { + const value = this.fixed(key, exp); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < 0) + throw new ValidationError(key, 'positive fixed number'); + + return value; +}; + +/** + * Get a value (as an int32). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.i8 = function i8(key, fallback) { + const value = this.int(key); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < -0x80 || value > 0x7f) + throw new ValidationError(key, 'i8'); + + return value; +}; + +/** + * Get a value (as an int32). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.i16 = function i16(key, fallback) { + const value = this.int(key); + + if (fallback === undefined) + fallback = null; + + if (value === null) + return fallback; + + if (value < -0x8000 || value > 0x7fff) + throw new ValidationError(key, 'i16'); return value; }; @@ -237,7 +342,7 @@ Validator.prototype.u64 = function u64(key, fallback) { */ Validator.prototype.i32 = function i32(key, fallback) { - const value = this.num(key); + const value = this.int(key); if (fallback === undefined) fallback = null; @@ -259,7 +364,18 @@ Validator.prototype.i32 = function i32(key, fallback) { */ Validator.prototype.i64 = function i64(key, fallback) { - const value = this.num(key); + return this.int(key, fallback); +}; + +/** + * Get a value (as a uint32). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.u8 = function u8(key, fallback) { + const value = this.uint(key); if (fallback === undefined) fallback = null; @@ -267,21 +383,21 @@ Validator.prototype.i64 = function i64(key, fallback) { if (value === null) return fallback; - if (value % 1 !== 0 || Math.abs(value) > 0x1fffffffffffff) - throw new ValidationError(key, 'int64'); + if ((value & 0xff) !== value) + throw new ValidationError(key, 'uint8'); return value; }; /** - * Get a value (as a satoshi number or btc string). + * Get a value (as a uint16). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.amt = function amt(key, fallback) { - const value = this.get(key); +Validator.prototype.u16 = function u16(key, fallback) { + const value = this.uint(key); if (fallback === undefined) fallback = null; @@ -289,30 +405,21 @@ Validator.prototype.amt = function amt(key, fallback) { if (value === null) return fallback; - if (typeof value !== 'string') { - if (typeof value !== 'number') - throw new ValidationError(key, 'amount'); - if (value % 1 !== 0 || value < 0 || value > 0x1fffffffffffff) - throw new ValidationError(key, 'amount'); - return value; - } + if ((value & 0xffff) !== value) + throw new ValidationError(key, 'uint16'); - try { - return util.fromFixed(value, 8); - } catch (e) { - throw new ValidationError(key, 'amount'); - } + return value; }; /** - * Get a value (as a btc float). + * Get a value (as a uint32). * @param {String} key * @param {Object?} fallback * @returns {Number|null} */ -Validator.prototype.btc = function btc(key, fallback) { - const value = this.flt(key); +Validator.prototype.u32 = function u32(key, fallback) { + const value = this.uint(key); if (fallback === undefined) fallback = null; @@ -320,14 +427,21 @@ Validator.prototype.btc = function btc(key, fallback) { if (value === null) return fallback; - if (value < 0 || value > 0x1fffffffffffff) - throw new ValidationError(key, 'btc float (uint64)'); + if ((value >>> 0) !== value) + throw new ValidationError(key, 'uint32'); - try { - return util.fromFixed(value.toString(10), 8); - } catch (e) { - throw new ValidationError(key, 'btc float'); - } + return value; +}; + +/** + * Get a value (as a uint64). + * @param {String} key + * @param {Object?} fallback + * @returns {Number|null} + */ + +Validator.prototype.u64 = function u64(key, fallback) { + return this.uint(key, fallback); }; /** @@ -386,37 +500,7 @@ Validator.prototype.numhash = function numhash(key, fallback) { if (typeof value === 'string') return this.hash(key); - return this.num(key); -}; - -/** - * Get a value (as a number or string). - * @param {String} key - * @param {Object?} fallback - * @returns {Number|String|null} - */ - -Validator.prototype.numstr = function numstr(key, fallback) { - const value = this.get(key); - - if (fallback === undefined) - fallback = null; - - if (value === null) - return fallback; - - if (typeof value !== 'string') { - if (typeof value !== 'number') - throw new ValidationError(key, 'number or string'); - return value; - } - - const num = parseInt(value, 10); - - if (!isFinite(num)) - return value; - - return num; + return this.uint(key); }; /** diff --git a/lib/wallet/plugin.js b/lib/wallet/plugin.js index 8681e8ef..4334e6e3 100644 --- a/lib/wallet/plugin.js +++ b/lib/wallet/plugin.js @@ -39,18 +39,18 @@ plugin.init = function init(node) { client: client, prefix: config.prefix, db: config.str(['wallet-db', 'db']), - maxFiles: config.num('wallet-max-files'), + maxFiles: config.uint('wallet-max-files'), cacheSize: config.mb('wallet-cache-size'), witness: config.bool('wallet-witness'), checkpoints: config.bool('wallet-checkpoints'), - startHeight: config.num('wallet-start-height'), + startHeight: config.uint('wallet-start-height'), wipeNoReally: config.bool('wallet-wipe-no-really'), apiKey: config.str(['wallet-api-key', 'api-key']), walletAuth: config.bool('wallet-auth'), noAuth: config.bool(['wallet-no-auth', 'no-auth']), ssl: config.str('wallet-ssl'), host: config.str('wallet-host'), - port: config.num('wallet-port'), + port: config.uint('wallet-port'), spv: node.spv, verify: node.spv, listen: false diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js index 2399bcfd..8c5218ad 100644 --- a/lib/wallet/rpc.js +++ b/lib/wallet/rpc.js @@ -158,7 +158,7 @@ RPC.prototype.fundRawTransaction = async function fundRawTransaction(args, help) const valid = new Validator([options]); if (valid.has('feeRate')) - rate = valid.btc('feeRate'); + rate = valid.ufixed('feeRate', 8); if (valid.has('changeAddress')) change = valid.str('changeAddress'); @@ -1248,7 +1248,7 @@ RPC.prototype.sendFrom = async function sendFrom(args, help) { const valid = new Validator([args]); let name = valid.str(0); const str = valid.str(1); - const value = valid.btc(2); + const value = valid.ufixed(2, 8); const minconf = valid.u32(3, 0); const addr = parseAddress(str, this.network); @@ -1300,7 +1300,7 @@ RPC.prototype.sendMany = async function sendMany(args, help) { const outputs = []; for (const key of Object.keys(sendTo)) { - const value = to.btc(key); + const value = to.ufixed(key, 8); const addr = parseAddress(key, this.network); const hash = addr.getHash('hex'); @@ -1340,7 +1340,7 @@ RPC.prototype.sendToAddress = async function sendToAddress(args, help) { const wallet = this.wallet; const valid = new Validator([args]); const str = valid.str(0); - const value = valid.btc(1); + const value = valid.ufixed(1, 8); const subtractFee = valid.bool(4, false); const addr = parseAddress(str, this.network); @@ -1374,7 +1374,7 @@ RPC.prototype.setAccount = async function setAccount(args, help) { RPC.prototype.setTXFee = async function setTXFee(args, help) { const valid = new Validator([args]); - const rate = valid.btc(0); + const rate = valid.ufixed(0, 8); if (help || args.length < 1 || args.length > 1) throw new RPCError(errs.MISC_ERROR, 'settxfee amount'); diff --git a/lib/wallet/server.js b/lib/wallet/server.js index d8bd4001..e1610db1 100644 --- a/lib/wallet/server.js +++ b/lib/wallet/server.js @@ -54,8 +54,8 @@ server.create = function create(options) { const workers = new WorkerPool({ enabled: config.str('workers-enabled'), - size: config.num('workers-size'), - timeout: config.num('workers-timeout') + size: config.uint('workers-size'), + timeout: config.uint('workers-timeout') }); const wdb = new WalletDB({ @@ -65,18 +65,18 @@ server.create = function create(options) { client: client, prefix: config.prefix, db: config.str('db'), - maxFiles: config.num('max-files'), + maxFiles: config.uint('max-files'), cacheSize: config.mb('cache-size'), witness: config.bool('witness'), checkpoints: config.bool('checkpoints'), - startHeight: config.num('start-height'), + startHeight: config.uint('start-height'), wipeNoReally: config.bool('wipe-no-really'), apiKey: config.str('api-key'), walletAuth: config.bool('auth'), noAuth: config.bool('no-auth'), ssl: config.str('ssl'), host: config.str('host'), - port: config.num('port'), + port: config.uint('port'), spv: config.bool('spv'), verify: config.bool('spv'), listen: true diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index 28902bfc..bcc57cd6 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -2478,7 +2478,7 @@ TXDB.prototype.getAccountBalance = async function getAccountBalance(account) { */ TXDB.prototype.zap = async function zap(account, age) { - assert(util.isUInt32(age)); + assert(util.isU32(age)); const now = util.now(); diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index 7f62fe7e..ea1a1c16 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -1620,7 +1620,7 @@ Wallet.prototype._send = async function _send(options, passphrase) { */ Wallet.prototype.increaseFee = async function increaseFee(hash, rate, passphrase) { - assert(util.isUInt32(rate), 'Rate must be a number.'); + assert(util.isU32(rate), 'Rate must be a number.'); const wtx = await this.getTX(hash); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 4b585ea7..a741b229 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -447,7 +447,7 @@ WalletDB.prototype.scan = async function scan(height) { if (height == null) height = this.state.startHeight; - assert(util.isUInt32(height), 'WDB: Must pass in a height.'); + assert(util.isU32(height), 'WDB: Must pass in a height.'); await this.rollback(height); diff --git a/migrate/coins/coins.js b/migrate/coins/coins.js index edacce24..bed08958 100644 --- a/migrate/coins/coins.js +++ b/migrate/coins/coins.js @@ -54,7 +54,7 @@ function Coins(options) { Coins.prototype.fromOptions = function fromOptions(options) { if (options.version != null) { - assert(util.isUInt32(options.version)); + assert(util.isU32(options.version)); this.version = options.version; }