lint: consistent return values.
This commit is contained in:
parent
5e73e51177
commit
5eb6620431
@ -8,7 +8,7 @@
|
||||
"ecmaVersion": 8
|
||||
},
|
||||
"rules": {
|
||||
"consistent-return": "off",
|
||||
"consistent-return": "error",
|
||||
"func-name-matching": "off",
|
||||
"indent": ["error", 2, {
|
||||
"SwitchCase": 1,
|
||||
|
||||
163
bin/cli
163
bin/cli
@ -25,7 +25,7 @@ function CLI() {
|
||||
CLI.prototype.log = function log(json) {
|
||||
if (typeof json === 'string')
|
||||
return console.log.apply(console, arguments);
|
||||
console.log(JSON.stringify(json, null, 2));
|
||||
return console.log(JSON.stringify(json, null, 2));
|
||||
};
|
||||
|
||||
CLI.prototype.getInfo = async function getInfo() {
|
||||
@ -491,81 +491,113 @@ CLI.prototype.handleWallet = async function handleWallet() {
|
||||
|
||||
switch (this.argv.shift()) {
|
||||
case 'listen':
|
||||
return await this.listenWallet();
|
||||
await this.listenWallet();
|
||||
break;
|
||||
case 'get':
|
||||
return await this.getWallet();
|
||||
await this.getWallet();
|
||||
break;
|
||||
case 'master':
|
||||
return await this.getMaster();
|
||||
await this.getMaster();
|
||||
break;
|
||||
case 'shared':
|
||||
if (this.argv[0] === 'add') {
|
||||
this.argv.shift();
|
||||
return await this.addSharedKey();
|
||||
await this.addSharedKey();
|
||||
break;
|
||||
}
|
||||
if (this.argv[0] === 'remove') {
|
||||
this.argv.shift();
|
||||
return await this.removeSharedKey();
|
||||
await this.removeSharedKey();
|
||||
break;
|
||||
}
|
||||
if (this.argv[0] === 'list')
|
||||
this.argv.shift();
|
||||
return await this.getSharedKeys();
|
||||
await this.getSharedKeys();
|
||||
break;
|
||||
case 'balance':
|
||||
return await this.getBalance();
|
||||
await this.getBalance();
|
||||
break;
|
||||
case 'history':
|
||||
return await this.getWalletHistory();
|
||||
await this.getWalletHistory();
|
||||
break;
|
||||
case 'pending':
|
||||
return await this.getWalletPending();
|
||||
await this.getWalletPending();
|
||||
break;
|
||||
case 'coins':
|
||||
return await this.getWalletCoins();
|
||||
await this.getWalletCoins();
|
||||
break;
|
||||
case 'account':
|
||||
if (this.argv[0] === 'list') {
|
||||
this.argv.shift();
|
||||
return await this.getAccounts();
|
||||
await this.getAccounts();
|
||||
break;
|
||||
}
|
||||
if (this.argv[0] === 'create') {
|
||||
this.argv.shift();
|
||||
return await this.createAccount();
|
||||
await this.createAccount();
|
||||
break;
|
||||
}
|
||||
if (this.argv[0] === 'get')
|
||||
this.argv.shift();
|
||||
return await this.getAccount();
|
||||
await this.getAccount();
|
||||
break;
|
||||
case 'address':
|
||||
return await this.createAddress();
|
||||
await this.createAddress();
|
||||
break;
|
||||
case 'change':
|
||||
return await this.createChange();
|
||||
await this.createChange();
|
||||
break;
|
||||
case 'nested':
|
||||
return await this.createNested();
|
||||
await this.createNested();
|
||||
break;
|
||||
case 'retoken':
|
||||
return await this.retoken();
|
||||
await this.retoken();
|
||||
break;
|
||||
case 'sign':
|
||||
return await this.signTX();
|
||||
await this.signTX();
|
||||
break;
|
||||
case 'mktx':
|
||||
return await this.createTX();
|
||||
await this.createTX();
|
||||
break;
|
||||
case 'send':
|
||||
return await this.sendTX();
|
||||
await this.sendTX();
|
||||
break;
|
||||
case 'zap':
|
||||
return await this.zapWallet();
|
||||
await this.zapWallet();
|
||||
break;
|
||||
case 'tx':
|
||||
return await this.getDetails();
|
||||
await this.getDetails();
|
||||
break;
|
||||
case 'blocks':
|
||||
return await this.getWalletBlocks();
|
||||
await this.getWalletBlocks();
|
||||
break;
|
||||
case 'block':
|
||||
return await this.getWalletBlock();
|
||||
await this.getWalletBlock();
|
||||
break;
|
||||
case 'view':
|
||||
return await this.viewTX();
|
||||
await this.viewTX();
|
||||
break;
|
||||
case 'import':
|
||||
return await this.importKey();
|
||||
await this.importKey();
|
||||
break;
|
||||
case 'watch':
|
||||
return await this.importAddress();
|
||||
await this.importAddress();
|
||||
break;
|
||||
case 'key':
|
||||
return await this.getKey();
|
||||
await this.getKey();
|
||||
break;
|
||||
case 'dump':
|
||||
return await this.getWIF();
|
||||
await this.getWIF();
|
||||
break;
|
||||
case 'lock':
|
||||
return await this.lock();
|
||||
await this.lock();
|
||||
break;
|
||||
case 'unlock':
|
||||
return await this.unlock();
|
||||
await this.unlock();
|
||||
break;
|
||||
case 'resend':
|
||||
return await this.resendWallet();
|
||||
await this.resendWallet();
|
||||
break;
|
||||
default:
|
||||
this.log('Unrecognized command.');
|
||||
this.log('Commands:');
|
||||
@ -603,7 +635,7 @@ CLI.prototype.handleWallet = async function handleWallet() {
|
||||
this.log('Other Options:');
|
||||
this.log(' --passphrase [passphrase]: For signing and account creation.');
|
||||
this.log(' --account [account-name]: Account name.');
|
||||
return;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@ -616,31 +648,44 @@ CLI.prototype.handleNode = async function handleNode() {
|
||||
|
||||
switch (this.argv.shift()) {
|
||||
case 'info':
|
||||
return await this.getInfo();
|
||||
await this.getInfo();
|
||||
break;
|
||||
case 'wallets':
|
||||
return await this.getWallets();
|
||||
await this.getWallets();
|
||||
break;
|
||||
case 'mkwallet':
|
||||
return await this.createWallet();
|
||||
await this.createWallet();
|
||||
break;
|
||||
case 'broadcast':
|
||||
return await this.broadcast();
|
||||
await this.broadcast();
|
||||
break;
|
||||
case 'mempool':
|
||||
return await this.getMempool();
|
||||
await this.getMempool();
|
||||
break;
|
||||
case 'tx':
|
||||
return await this.getTX();
|
||||
await this.getTX();
|
||||
break;
|
||||
case 'coin':
|
||||
return await this.getCoin();
|
||||
await this.getCoin();
|
||||
break;
|
||||
case 'block':
|
||||
return await this.getBlock();
|
||||
await this.getBlock();
|
||||
break;
|
||||
case 'rescan':
|
||||
return await this.rescan();
|
||||
await this.rescan();
|
||||
break;
|
||||
case 'reset':
|
||||
return await this.reset();
|
||||
await this.reset();
|
||||
break;
|
||||
case 'resend':
|
||||
return await this.resend();
|
||||
await this.resend();
|
||||
break;
|
||||
case 'backup':
|
||||
return await this.backup();
|
||||
await this.backup();
|
||||
break;
|
||||
case 'rpc':
|
||||
return await this.rpc();
|
||||
await this.rpc();
|
||||
break;
|
||||
default:
|
||||
this.log('Unrecognized command.');
|
||||
this.log('Commands:');
|
||||
@ -657,7 +702,7 @@ CLI.prototype.handleNode = async function handleNode() {
|
||||
this.log(' $ resend: Resend pending transactions.');
|
||||
this.log(' $ backup [path]: Backup the wallet db.');
|
||||
this.log(' $ rpc [command] [args]: Execute RPC command.');
|
||||
return;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@ -668,29 +713,33 @@ CLI.prototype.open = async function open() {
|
||||
this.argv.shift();
|
||||
if (this.argv[0] === 'create') {
|
||||
this.argv[0] = 'mkwallet';
|
||||
return await this.handleNode();
|
||||
await this.handleNode();
|
||||
break;
|
||||
}
|
||||
return await this.handleWallet();
|
||||
await this.handleWallet();
|
||||
break;
|
||||
default:
|
||||
return await this.handleNode();
|
||||
await this.handleNode();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
CLI.prototype.destroy = function destroy() {
|
||||
if (this.wallet)
|
||||
this.wallet.client.destroy();
|
||||
|
||||
if (this.client)
|
||||
this.client.destroy();
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
async function main() {
|
||||
(async () => {
|
||||
const cli = new CLI();
|
||||
await cli.open();
|
||||
await cli.destroy();
|
||||
}
|
||||
|
||||
main().then(process.exit).catch((err) => {
|
||||
console.error(err.stack + '');
|
||||
return process.exit(1);
|
||||
process.exit(0);
|
||||
})().catch((err) => {
|
||||
console.error(err.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@ -151,7 +151,7 @@ PaymentDetails.prototype.getData = function getData(enc) {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (e) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -953,8 +953,10 @@ Chain.prototype.setBestChain = async function setBestChain(entry, block, prev, f
|
||||
|
||||
// In spv-mode, we reset the
|
||||
// chain and redownload the blocks.
|
||||
if (this.options.spv)
|
||||
return await this.reorganizeSPV(entry);
|
||||
if (this.options.spv) {
|
||||
await this.reorganizeSPV(entry);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.reorganize(entry);
|
||||
}
|
||||
@ -1138,8 +1140,10 @@ Chain.prototype._replay = async function _replay(block, silent) {
|
||||
if (!(await entry.isMainChain()))
|
||||
throw new Error('Cannot reset on alternate chain.');
|
||||
|
||||
if (entry.isGenesis())
|
||||
return await this._reset(entry.hash, silent);
|
||||
if (entry.isGenesis()) {
|
||||
await this._reset(entry.hash, silent);
|
||||
return;
|
||||
}
|
||||
|
||||
await this._reset(entry.prevBlock, silent);
|
||||
};
|
||||
|
||||
@ -523,10 +523,8 @@ function pow10(exp) {
|
||||
return 10000000;
|
||||
case 8:
|
||||
return 100000000;
|
||||
default:
|
||||
assert(false, 'Exponent is too large.');
|
||||
break;
|
||||
}
|
||||
throw new Error('Exponent is too large.');
|
||||
}
|
||||
|
||||
function modSafe(mod) {
|
||||
@ -549,10 +547,8 @@ function modSafe(mod) {
|
||||
return 4740991;
|
||||
case 100000000:
|
||||
return 54740991;
|
||||
default:
|
||||
assert(false, 'Exponent is too large.');
|
||||
break;
|
||||
}
|
||||
throw new Error('Exponent is too large.');
|
||||
}
|
||||
|
||||
function divSafe(div) {
|
||||
@ -575,10 +571,8 @@ function divSafe(div) {
|
||||
return 900719925;
|
||||
case 100000000:
|
||||
return 90071992;
|
||||
default:
|
||||
assert(false, 'Exponent is too large.');
|
||||
break;
|
||||
}
|
||||
throw new Error('Exponent is too large.');
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -46,6 +46,8 @@ DB.prototype.batch = function batch(ops, options, callback) {
|
||||
}
|
||||
|
||||
this.level.batch(ops, options, callback);
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
DB.prototype.iterator = function iterator(options) {
|
||||
@ -142,8 +144,10 @@ Iterator.prototype.seek = function seek(key) {
|
||||
};
|
||||
|
||||
Iterator.prototype.end = function end(callback) {
|
||||
if (this._end)
|
||||
return callback(new Error('end() already called on iterator.'));
|
||||
if (this._end) {
|
||||
callback(new Error('end() already called on iterator.'));
|
||||
return;
|
||||
}
|
||||
this._end = true;
|
||||
this.iter.end(callback);
|
||||
};
|
||||
|
||||
@ -227,7 +227,7 @@ MemDB.prototype.batch = function _batch(ops, options, callback) {
|
||||
if (ops) {
|
||||
batch.ops = ops;
|
||||
batch.write(callback);
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return batch;
|
||||
@ -339,7 +339,7 @@ Batch.prototype.del = function del(key) {
|
||||
Batch.prototype.write = function write(callback) {
|
||||
if (this.written) {
|
||||
setImmediate(() => callback(new Error('Already written.')));
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
|
||||
for (const op of this.ops) {
|
||||
@ -352,7 +352,7 @@ Batch.prototype.write = function write(callback) {
|
||||
break;
|
||||
default:
|
||||
setImmediate(() => callback(new Error('Bad op.')));
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -218,19 +218,27 @@ HTTPBase.prototype.basicAuth = function basicAuth(options) {
|
||||
return async (req, res) => {
|
||||
const hdr = req.headers['authorization'];
|
||||
|
||||
if (!hdr)
|
||||
return fail(res);
|
||||
if (!hdr) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hdr.length > 1000)
|
||||
return fail(res);
|
||||
if (hdr.length > 1000) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
const parts = hdr.split(' ');
|
||||
|
||||
if (parts.length !== 2)
|
||||
return fail(res);
|
||||
if (parts.length !== 2) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (parts[0] !== 'Basic')
|
||||
return fail(res);
|
||||
if (parts[0] !== 'Basic') {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
const auth = Buffer.from(parts[1], 'base64').toString('utf8');
|
||||
const items = auth.split(':');
|
||||
@ -239,24 +247,32 @@ HTTPBase.prototype.basicAuth = function basicAuth(options) {
|
||||
const password = items.join(':');
|
||||
|
||||
if (user) {
|
||||
if (username.length > 255)
|
||||
return fail(res);
|
||||
if (username.length > 255) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
const raw = Buffer.from(username, 'utf8');
|
||||
const hash = digest.hash256(raw);
|
||||
|
||||
if (!ccmp(hash, user))
|
||||
return fail(res);
|
||||
if (!ccmp(hash, user)) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (password.length > 255)
|
||||
return fail(res);
|
||||
if (password.length > 255) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
const raw = Buffer.from(password, 'utf8');
|
||||
const hash = digest.hash256(raw);
|
||||
|
||||
if (!ccmp(hash, pass))
|
||||
return fail(res);
|
||||
if (!ccmp(hash, pass)) {
|
||||
fail(res);
|
||||
return;
|
||||
}
|
||||
|
||||
req.username = username;
|
||||
};
|
||||
|
||||
@ -2213,7 +2213,7 @@ Pool.prototype.handleBlock = async function handleBlock(peer, packet) {
|
||||
return;
|
||||
}
|
||||
|
||||
return await this.addBlock(peer, packet.block, flags);
|
||||
await this.addBlock(peer, packet.block, flags);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -662,7 +662,7 @@ Proxy.prototype.resume = function resume() {
|
||||
Proxy.prototype.destroy = function destroy() {
|
||||
if (!this.socket)
|
||||
return;
|
||||
return this.socket.destroy();
|
||||
this.socket.destroy();
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@ -394,8 +394,10 @@ Logger.prototype.error = function error(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.ERROR, null, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.ERROR, null, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.ERROR, null, args);
|
||||
};
|
||||
@ -412,8 +414,10 @@ Logger.prototype.warning = function warning(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.WARNING, null, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.WARNING, null, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.WARNING, null, args);
|
||||
};
|
||||
@ -430,8 +434,10 @@ Logger.prototype.info = function info(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.INFO, null, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.INFO, null, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.INFO, null, args);
|
||||
};
|
||||
@ -448,8 +454,10 @@ Logger.prototype.debug = function debug(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.DEBUG, null, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.DEBUG, null, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.DEBUG, null, args);
|
||||
};
|
||||
@ -466,8 +474,10 @@ Logger.prototype.spam = function spam(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.SPAM, null, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.SPAM, null, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.SPAM, null, args);
|
||||
};
|
||||
@ -521,7 +531,7 @@ Logger.prototype.writeConsole = function writeConsole(level, module, args) {
|
||||
assert(name, 'Invalid log level.');
|
||||
|
||||
if (!this.console)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (!process.stdout) {
|
||||
let msg = `[${name}] `;
|
||||
@ -537,13 +547,17 @@ Logger.prototype.writeConsole = function writeConsole(level, module, args) {
|
||||
|
||||
msg += util.format(args, false);
|
||||
|
||||
return level === Logger.levels.ERROR
|
||||
? console.error(msg)
|
||||
: console.log(msg);
|
||||
if (level === Logger.levels.ERROR) {
|
||||
console.error(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let msg;
|
||||
|
||||
if (this.colors) {
|
||||
const color = Logger.styles[level];
|
||||
assert(color);
|
||||
@ -707,8 +721,10 @@ LoggerContext.prototype.error = function error(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.ERROR, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.ERROR, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.ERROR, args);
|
||||
};
|
||||
@ -725,8 +741,10 @@ LoggerContext.prototype.warning = function warning(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.WARNING, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.WARNING, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.WARNING, args);
|
||||
};
|
||||
@ -743,8 +761,10 @@ LoggerContext.prototype.info = function info(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.INFO, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.INFO, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.INFO, args);
|
||||
};
|
||||
@ -761,8 +781,10 @@ LoggerContext.prototype.debug = function debug(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.DEBUG, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.DEBUG, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.DEBUG, args);
|
||||
};
|
||||
@ -779,8 +801,10 @@ LoggerContext.prototype.spam = function spam(...args) {
|
||||
|
||||
const err = args[0];
|
||||
|
||||
if (err instanceof Error)
|
||||
return this.logError(Logger.levels.SPAM, err);
|
||||
if (err instanceof Error) {
|
||||
this.logError(Logger.levels.SPAM, err);
|
||||
return;
|
||||
}
|
||||
|
||||
this.log(Logger.levels.SPAM, args);
|
||||
};
|
||||
|
||||
@ -431,7 +431,7 @@ TX.prototype.signatureHash = function signatureHash(index, prev, value, type, ve
|
||||
if (version === 1)
|
||||
return this.signatureHashV1(index, prev, value, type);
|
||||
|
||||
assert(false, 'Unknown sighash version.');
|
||||
throw new Error('Unknown sighash version.');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -811,10 +811,12 @@ TX.prototype.checkAsync = async function checkAsync(view, flags, pool) {
|
||||
if (this.isCoinbase())
|
||||
return;
|
||||
|
||||
if (!pool)
|
||||
return this.check(view, flags);
|
||||
if (!pool) {
|
||||
this.check(view, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
return await pool.check(this, view, flags);
|
||||
await pool.check(this, view, flags);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -833,10 +835,12 @@ TX.prototype.checkInputAsync = async function checkInputAsync(index, coin, flags
|
||||
assert(input, 'Input does not exist.');
|
||||
assert(coin, 'No coin passed.');
|
||||
|
||||
if (!pool)
|
||||
return this.checkInput(index, coin, flags);
|
||||
if (!pool) {
|
||||
this.checkInput(index, coin, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
return await pool.checkInput(this, index, coin, flags);
|
||||
await pool.checkInput(this, index, coin, flags);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -199,7 +199,7 @@ Network.get = function get(type) {
|
||||
if (typeof type === 'string')
|
||||
return Network.create(type);
|
||||
|
||||
assert(false, 'Unknown network.');
|
||||
throw new Error('Unknown network.');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -396,7 +396,7 @@ Opcode.from = function from(data) {
|
||||
if (BN.isBN(data))
|
||||
return Opcode.fromNumber(data);
|
||||
|
||||
assert(false, 'Bad data for opcode.');
|
||||
throw new Error('Bad data for opcode.');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -154,7 +154,7 @@ ScriptNum.prototype.toString = function toString(base) {
|
||||
return str;
|
||||
}
|
||||
|
||||
assert(false, `Base ${base} not supported.`);
|
||||
throw new Error(`Base ${base} not supported.`);
|
||||
};
|
||||
|
||||
ScriptNum.prototype.toJSON = function toJSON() {
|
||||
@ -237,7 +237,7 @@ ScriptNum.prototype.fromString = function fromString(str, base) {
|
||||
return this;
|
||||
}
|
||||
|
||||
assert(false, `Base ${base} not supported.`);
|
||||
throw new Error(`Base ${base} not supported.`);
|
||||
};
|
||||
|
||||
ScriptNum.fromString = function fromString(str, base) {
|
||||
|
||||
@ -484,7 +484,7 @@ IP.getType = function getType(raw) {
|
||||
if (IP.isOnion(raw))
|
||||
return IP.types.ONION;
|
||||
|
||||
assert(false, 'Unknown type.');
|
||||
throw new Error('Unknown type.');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -369,7 +369,8 @@ StaticWriter.prototype.writeString = function writeString(value, enc) {
|
||||
StaticWriter.prototype.writeHash = function writeHash(value) {
|
||||
if (typeof value !== 'string') {
|
||||
assert(value.length === 32);
|
||||
return this.writeBytes(value);
|
||||
this.writeBytes(value);
|
||||
return;
|
||||
}
|
||||
assert(value.length === 64);
|
||||
this.data.write(value, this.written, 'hex');
|
||||
|
||||
@ -551,7 +551,7 @@ util.pad8 = function pad8(num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw new Error('Number too big.');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -590,7 +590,7 @@ util.pad32 = function pad32(num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw new Error('Number too big.');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -613,7 +613,7 @@ util.hex8 = function hex8(num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw new Error('Number too big.');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -648,7 +648,7 @@ util.hex32 = function hex32(num) {
|
||||
return num;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw new Error('Number too big.');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -466,7 +466,8 @@ BufferWriter.prototype.writeString = function writeString(value, enc) {
|
||||
BufferWriter.prototype.writeHash = function writeHash(value) {
|
||||
if (typeof value !== 'string') {
|
||||
assert(value.length === 32);
|
||||
return this.writeBytes(value);
|
||||
this.writeBytes(value);
|
||||
return;
|
||||
}
|
||||
assert(value.length === 64);
|
||||
this.writeString(value, 'hex');
|
||||
|
||||
@ -519,7 +519,7 @@ Account.prototype.derivePath = function derivePath(path, master) {
|
||||
return null;
|
||||
}
|
||||
default: {
|
||||
assert(false, 'Bad key type.');
|
||||
throw new Error('Bad key type.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -100,7 +100,8 @@ WalletClient.prototype._open = async function _open() {
|
||||
block = parseBlock(entry, txs);
|
||||
} catch (e) {
|
||||
this.emit('error', e);
|
||||
return cb();
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
|
||||
this.fire('block rescan', block.entry, block.txs).then(cb, cb);
|
||||
|
||||
@ -197,7 +197,7 @@ async function reserializeUndo() {
|
||||
function write(data, str, off) {
|
||||
if (Buffer.isBuffer(str))
|
||||
return str.copy(data, off);
|
||||
data.write(str, off, 'hex');
|
||||
return data.write(str, off, 'hex');
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
|
||||
@ -541,7 +541,7 @@ function entryToRaw(entry, main) {
|
||||
function write(data, str, off) {
|
||||
if (Buffer.isBuffer(str))
|
||||
return str.copy(data, off);
|
||||
data.write(str, off, 'hex');
|
||||
return data.write(str, off, 'hex');
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -121,7 +121,7 @@ async function indexTips() {
|
||||
function write(data, str, off) {
|
||||
if (Buffer.isBuffer(str))
|
||||
return str.copy(data, off);
|
||||
data.write(str, off, 'hex');
|
||||
return data.write(str, off, 'hex');
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const util = require('../lib/utils/util');
|
||||
const Script = require('../lib/script/script');
|
||||
const Stack = require('../lib/script/stack');
|
||||
@ -173,7 +172,7 @@ function randomRedeem() {
|
||||
case 4:
|
||||
return randomProgram();
|
||||
}
|
||||
assert(false);
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
function randomScript() {
|
||||
@ -193,7 +192,7 @@ function randomScript() {
|
||||
case 6:
|
||||
return randomProgram();
|
||||
}
|
||||
assert(false);
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
function randomPubkeyContext() {
|
||||
@ -269,7 +268,7 @@ function randomContext() {
|
||||
case 5:
|
||||
return randomWitnessNestedContext();
|
||||
}
|
||||
assert(false);
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
function fuzzSimple(flags) {
|
||||
@ -434,11 +433,14 @@ function main() {
|
||||
|
||||
switch (process.argv[2]) {
|
||||
case 'simple':
|
||||
return fuzzSimple(flags);
|
||||
fuzzSimple(flags);
|
||||
break;
|
||||
case 'verify':
|
||||
return fuzzVerify(flags);
|
||||
fuzzVerify(flags);
|
||||
break;
|
||||
case 'less':
|
||||
return fuzzLess(flags);
|
||||
fuzzLess(flags);
|
||||
break;
|
||||
default:
|
||||
util.log('Please select a mode:');
|
||||
util.log('simple, verify, less');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user