bcoin: lint.

This commit is contained in:
Christopher Jeffrey 2017-11-16 20:40:01 -08:00
parent 73664efcd0
commit 163e89fc29
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
14 changed files with 38 additions and 27 deletions

View File

@ -716,7 +716,7 @@ class CLI {
this.log(' $ resend: Resend pending transactions.'); this.log(' $ resend: Resend pending transactions.');
this.log(' $ rescan [height]: Rescan for transactions.'); this.log(' $ rescan [height]: Rescan for transactions.');
this.log('Other Options:'); this.log('Other Options:');
this.log(' --passphrase [passphrase]: For signing & account creation.'); this.log(' --passphrase [passphrase]: For signing/account-creation.');
this.log(' --account [account-name]: Account name.'); this.log(' --account [account-name]: Account name.');
break; break;
} }

View File

@ -363,7 +363,7 @@ class ConfirmStats {
throw new Error('Mismatch in tx count bucket count.'); throw new Error('Mismatch in tx count bucket count.');
if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7)
throw new Error('Must maintain estimates for between 1 and 1008 confirms.'); throw new Error('Must maintain estimates for between 1-1008 confirms.');
for (let i = 0; i < maxConfirms; i++) { for (let i = 0; i < maxConfirms; i++) {
if (confAvg[i].length !== buckets.length) if (confAvg[i].length !== buckets.length)

View File

@ -155,7 +155,7 @@ class Miner extends EventEmitter {
this.assemble(attempt); this.assemble(attempt);
this.logger.debug( this.logger.debug(
'Created block template (height=%d, weight=%d, fees=%d, txs=%s, diff=%d).', 'Created block tmpl (height=%d, weight=%d, fees=%d, txs=%s, diff=%d).',
attempt.height, attempt.height,
attempt.weight, attempt.weight,
Amount.btc(attempt.fees), Amount.btc(attempt.fees),

View File

@ -2322,16 +2322,6 @@ class SendCmpctPacket extends Packet {
return new this().fromReader(br); return new this().fromReader(br);
} }
/**
* Instantiate sendcmpct packet from buffer reader.
* @param {BufferReader} br
* @returns {SendCmpctPacket}
*/
static fromReader(br) {
return new this().fromReader(br);
}
/** /**
* Instantiate sendcmpct packet from serialized data. * Instantiate sendcmpct packet from serialized data.
* @param {Buffer} data * @param {Buffer} data

View File

@ -88,8 +88,10 @@ class Pool extends EventEmitter {
this.hosts = new HostList(this.options); this.hosts = new HostList(this.options);
this.id = 0; this.id = 0;
if (this.options.spv) if (this.options.spv) {
this.spvFilter = BloomFilter.fromRate(20000, 0.001, BloomFilter.flags.ALL); this.spvFilter = BloomFilter.fromRate(
20000, 0.001, BloomFilter.flags.ALL);
}
if (!this.options.mempool) if (!this.options.mempool)
this.txFilter = new RollingFilter(50000, 0.000001); this.txFilter = new RollingFilter(50000, 0.000001);
@ -1737,7 +1739,9 @@ class Pool extends EventEmitter {
const items = packet.items; const items = packet.items;
if (items.length > 50000) { if (items.length > 50000) {
this.logger.warning('Peer sent inv with >50k items (%s).', peer.hostname()); this.logger.warning(
'Peer sent inv with >50k items (%s).',
peer.hostname());
peer.increaseBan(100); peer.increaseBan(100);
peer.destroy(); peer.destroy();
return; return;
@ -1827,12 +1831,16 @@ class Pool extends EventEmitter {
// Fallback to full block. // Fallback to full block.
if (height < this.chain.tip.height - 10) { if (height < this.chain.tip.height - 10) {
const result = await this.sendBlock(peer, item, peer.compactWitness); const result = await this.sendBlock(
peer, item, peer.compactWitness);
if (!result) { if (!result) {
notFound.push(item); notFound.push(item);
continue; continue;
} }
blocks += 1; blocks += 1;
break; break;
} }
@ -4163,6 +4171,7 @@ class PeerList {
* Broadcast Item * Broadcast Item
* Represents an item that is broadcasted via an inv/getdata cycle. * Represents an item that is broadcasted via an inv/getdata cycle.
* @alias module:net.BroadcastItem * @alias module:net.BroadcastItem
* @extends EventEmitter
* @private * @private
* @emits BroadcastItem#ack * @emits BroadcastItem#ack
* @emits BroadcastItem#reject * @emits BroadcastItem#reject
@ -4178,6 +4187,8 @@ class BroadcastItem extends EventEmitter {
*/ */
constructor(pool, msg) { constructor(pool, msg) {
super();
assert(!msg.mutable, 'Cannot broadcast mutable item.'); assert(!msg.mutable, 'Cannot broadcast mutable item.');
const item = msg.toInv(); const item = msg.toInv();

View File

@ -154,7 +154,9 @@ class Node extends EventEmitter {
await this.workers.open(); await this.workers.open();
this._bind(this.network.time, 'offset', (offset) => { this._bind(this.network.time, 'offset', (offset) => {
this.logger.info('Time offset: %d (%d minutes).', offset, offset / 60 | 0); this.logger.info(
'Time offset: %d (%d minutes).',
offset, offset / 60 | 0);
}); });
this._bind(this.network.time, 'sample', (sample, total) => { this._bind(this.network.time, 'sample', (sample, total) => {

View File

@ -11,7 +11,6 @@ const assert = require('assert');
const bio = require('bufio'); const bio = require('bufio');
const Amount = require('../btc/amount'); const Amount = require('../btc/amount');
const Output = require('./output'); const Output = require('./output');
const Script = require('../script/script');
const Network = require('../protocol/network'); const Network = require('../protocol/network');
const {encoding} = bio; const {encoding} = bio;

View File

@ -13,7 +13,6 @@ const Network = require('../protocol/network');
const Script = require('../script/script'); const Script = require('../script/script');
const Witness = require('../script/witness'); const Witness = require('../script/witness');
const Outpoint = require('./outpoint'); const Outpoint = require('./outpoint');
const {encoding} = bio;
/** /**
* Input * Input

View File

@ -88,7 +88,8 @@ class Output {
script = Script.fromAddress(script); script = Script.fromAddress(script);
assert(script instanceof Script, 'Script must be a Script.'); assert(script instanceof Script, 'Script must be a Script.');
assert(Number.isSafeInteger(value) && value >= 0, 'Value must be a uint64.'); assert(Number.isSafeInteger(value) && value >= 0,
'Value must be a uint64.');
this.script = script; this.script = script;
this.value = value; this.value = value;

View File

@ -2199,7 +2199,8 @@ class TX {
assert((json.version >>> 0) === json.version, 'Version must be a uint32.'); assert((json.version >>> 0) === json.version, 'Version must be a uint32.');
assert(Array.isArray(json.inputs), 'Inputs must be an array.'); assert(Array.isArray(json.inputs), 'Inputs must be an array.');
assert(Array.isArray(json.outputs), 'Outputs must be an array.'); assert(Array.isArray(json.outputs), 'Outputs must be an array.');
assert((json.locktime >>> 0) === json.locktime, 'Locktime must be a uint32.'); assert((json.locktime >>> 0) === json.locktime,
'Locktime must be a uint32.');
this.version = json.version; this.version = json.version;

View File

@ -513,7 +513,7 @@ class Script {
* @param {Number?} index - Index of input being verified. * @param {Number?} index - Index of input being verified.
* @param {Amount?} value - Previous output value. * @param {Amount?} value - Previous output value.
* @param {Number?} version - Signature hash version (0=legacy, 1=segwit). * @param {Number?} version - Signature hash version (0=legacy, 1=segwit).
* @throws {ScriptError} Will be thrown on VERIFY failures, among other things. * @throws {ScriptError} Will be thrown on VERIFY failures.
*/ */
execute(stack, flags, tx, index, value, version) { execute(stack, flags, tx, index, value, version) {
@ -1133,7 +1133,13 @@ class Script {
if (sig.length > 0) { if (sig.length > 0) {
const type = sig[sig.length - 1]; const type = sig[sig.length - 1];
const hash = tx.signatureHash(index, subscript, value, type, version); const hash = tx.signatureHash(
index,
subscript,
value,
type,
version
);
res = checksig(hash, sig, key); res = checksig(hash, sig, key);
} }

View File

@ -2053,7 +2053,7 @@ class TXDB {
/** /**
* Zap pending transactions older than `age`. * Zap pending transactions older than `age`.
* @param {Number} acct * @param {Number} acct
* @param {Number} age - Age delta (delete transactions older than `now - age`). * @param {Number} age - Age delta.
* @returns {Promise} * @returns {Promise}
*/ */

View File

@ -69,13 +69,15 @@ async function checkTipIndex() {
console.log('No tip index found.'); console.log('No tip index found.');
console.log('Please run migrate/ensure-tip-index.js first!'); console.log('Please run migrate/ensure-tip-index.js first!');
process.exit(1); process.exit(1);
return; return undefined;
} }
if (keys.length < 3) { if (keys.length < 3) {
console.log('Note: please run ensure-tip-index.js if you haven\'t yet.'); console.log('Note: please run ensure-tip-index.js if you haven\'t yet.');
return new Promise(r => setTimeout(r, 2000)); return new Promise(r => setTimeout(r, 2000));
} }
return undefined;
} }
async function updateOptions() { async function updateOptions() {

View File

@ -91,7 +91,7 @@ async function updateTXDB() {
function fromExtended(data, saveCoins) { function fromExtended(data, saveCoins) {
const tx = new TX(); const tx = new TX();
const p = BufferReader(data); const p = bio.read(data);
tx.fromRaw(p); tx.fromRaw(p);