From 163e89fc29a0972b7bb6b342d7865d9829754d7a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 16 Nov 2017 20:40:01 -0800 Subject: [PATCH] bcoin: lint. --- bin/cli | 2 +- lib/mempool/fees.js | 2 +- lib/mining/miner.js | 2 +- lib/net/packets.js | 10 ---------- lib/net/pool.js | 19 +++++++++++++++---- lib/node/node.js | 4 +++- lib/primitives/coin.js | 1 - lib/primitives/input.js | 1 - lib/primitives/output.js | 3 ++- lib/primitives/tx.js | 3 ++- lib/script/script.js | 10 ++++++++-- lib/wallet/txdb.js | 2 +- migrate/chaindb1to2.js | 4 +++- migrate/walletdb3to4.js | 2 +- 14 files changed, 38 insertions(+), 27 deletions(-) diff --git a/bin/cli b/bin/cli index d99f8e52..7407aeb3 100755 --- a/bin/cli +++ b/bin/cli @@ -716,7 +716,7 @@ class CLI { this.log(' $ resend: Resend pending transactions.'); this.log(' $ rescan [height]: Rescan for transactions.'); 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.'); break; } diff --git a/lib/mempool/fees.js b/lib/mempool/fees.js index 51ab5f25..22d888d3 100644 --- a/lib/mempool/fees.js +++ b/lib/mempool/fees.js @@ -363,7 +363,7 @@ class ConfirmStats { throw new Error('Mismatch in tx count bucket count.'); 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++) { if (confAvg[i].length !== buckets.length) diff --git a/lib/mining/miner.js b/lib/mining/miner.js index a5412a3c..813d2b46 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -155,7 +155,7 @@ class Miner extends EventEmitter { this.assemble(attempt); 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.weight, Amount.btc(attempt.fees), diff --git a/lib/net/packets.js b/lib/net/packets.js index d31f09af..e14b1a34 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -2322,16 +2322,6 @@ class SendCmpctPacket extends Packet { 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. * @param {Buffer} data diff --git a/lib/net/pool.js b/lib/net/pool.js index fc72043a..d658fda2 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -88,8 +88,10 @@ class Pool extends EventEmitter { this.hosts = new HostList(this.options); this.id = 0; - if (this.options.spv) - this.spvFilter = BloomFilter.fromRate(20000, 0.001, BloomFilter.flags.ALL); + if (this.options.spv) { + this.spvFilter = BloomFilter.fromRate( + 20000, 0.001, BloomFilter.flags.ALL); + } if (!this.options.mempool) this.txFilter = new RollingFilter(50000, 0.000001); @@ -1737,7 +1739,9 @@ class Pool extends EventEmitter { const items = packet.items; 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.destroy(); return; @@ -1827,12 +1831,16 @@ class Pool extends EventEmitter { // Fallback to full block. 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) { notFound.push(item); continue; } + blocks += 1; + break; } @@ -4163,6 +4171,7 @@ class PeerList { * Broadcast Item * Represents an item that is broadcasted via an inv/getdata cycle. * @alias module:net.BroadcastItem + * @extends EventEmitter * @private * @emits BroadcastItem#ack * @emits BroadcastItem#reject @@ -4178,6 +4187,8 @@ class BroadcastItem extends EventEmitter { */ constructor(pool, msg) { + super(); + assert(!msg.mutable, 'Cannot broadcast mutable item.'); const item = msg.toInv(); diff --git a/lib/node/node.js b/lib/node/node.js index 3bb82029..2adc456d 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -154,7 +154,9 @@ class Node extends EventEmitter { await this.workers.open(); 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) => { diff --git a/lib/primitives/coin.js b/lib/primitives/coin.js index 9bfb1843..9c4b2462 100644 --- a/lib/primitives/coin.js +++ b/lib/primitives/coin.js @@ -11,7 +11,6 @@ const assert = require('assert'); const bio = require('bufio'); const Amount = require('../btc/amount'); const Output = require('./output'); -const Script = require('../script/script'); const Network = require('../protocol/network'); const {encoding} = bio; diff --git a/lib/primitives/input.js b/lib/primitives/input.js index c9de8d78..1ab11cb4 100644 --- a/lib/primitives/input.js +++ b/lib/primitives/input.js @@ -13,7 +13,6 @@ const Network = require('../protocol/network'); const Script = require('../script/script'); const Witness = require('../script/witness'); const Outpoint = require('./outpoint'); -const {encoding} = bio; /** * Input diff --git a/lib/primitives/output.js b/lib/primitives/output.js index 0051a0a9..0d285266 100644 --- a/lib/primitives/output.js +++ b/lib/primitives/output.js @@ -88,7 +88,8 @@ class Output { script = Script.fromAddress(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.value = value; diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index cce911f2..52325cc4 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -2199,7 +2199,8 @@ class TX { 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.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; diff --git a/lib/script/script.js b/lib/script/script.js index 5fee5ab6..6ff0dd43 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -513,7 +513,7 @@ class Script { * @param {Number?} index - Index of input being verified. * @param {Amount?} value - Previous output value. * @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) { @@ -1133,7 +1133,13 @@ class Script { if (sig.length > 0) { 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); } diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index f25c6f19..9671d425 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -2053,7 +2053,7 @@ class TXDB { /** * Zap pending transactions older than `age`. * @param {Number} acct - * @param {Number} age - Age delta (delete transactions older than `now - age`). + * @param {Number} age - Age delta. * @returns {Promise} */ diff --git a/migrate/chaindb1to2.js b/migrate/chaindb1to2.js index c1e80a5c..1d71e424 100644 --- a/migrate/chaindb1to2.js +++ b/migrate/chaindb1to2.js @@ -69,13 +69,15 @@ async function checkTipIndex() { console.log('No tip index found.'); console.log('Please run migrate/ensure-tip-index.js first!'); process.exit(1); - return; + return undefined; } if (keys.length < 3) { console.log('Note: please run ensure-tip-index.js if you haven\'t yet.'); return new Promise(r => setTimeout(r, 2000)); } + + return undefined; } async function updateOptions() { diff --git a/migrate/walletdb3to4.js b/migrate/walletdb3to4.js index 6b00fe1f..feba9e34 100644 --- a/migrate/walletdb3to4.js +++ b/migrate/walletdb3to4.js @@ -91,7 +91,7 @@ async function updateTXDB() { function fromExtended(data, saveCoins) { const tx = new TX(); - const p = BufferReader(data); + const p = bio.read(data); tx.fromRaw(p);