lint. optimize.
This commit is contained in:
parent
e8130bd04c
commit
becbba4aba
@ -10,7 +10,6 @@ var EventEmitter = require('events').EventEmitter;
|
||||
var constants = bcoin.protocol.constants;
|
||||
var utils = require('./utils');
|
||||
var assert = utils.assert;
|
||||
var pad32 = utils.pad32;
|
||||
var DUMMY = new Buffer([0]);
|
||||
var BufferWriter = require('./writer');
|
||||
var BufferReader = require('./reader');
|
||||
@ -36,14 +35,9 @@ var Parser = bcoin.protocol.parser;
|
||||
*/
|
||||
|
||||
var layout = {
|
||||
R: function R() {
|
||||
var key = new BufferWriter();
|
||||
key.writeU8(0x52); // R
|
||||
key = key.render();
|
||||
if (utils.isBrowser)
|
||||
key = key.toString('hex');
|
||||
return key;
|
||||
},
|
||||
R: !utils.isBrowser
|
||||
? new Buffer([0x52]) // R
|
||||
: '52',
|
||||
e: function e(hash) {
|
||||
var key = new BufferWriter();
|
||||
key.writeU8(0x65); // e
|
||||
@ -592,7 +586,7 @@ ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
|
||||
|
||||
batch.put(layout.n(entry.prevBlock), hash);
|
||||
batch.put(layout.H(entry.height), hash);
|
||||
batch.put(layout.R(), hash);
|
||||
batch.put(layout.R, hash);
|
||||
|
||||
this.emit('add entry', entry);
|
||||
|
||||
@ -610,7 +604,7 @@ ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
|
||||
|
||||
ChainDB.prototype.getTip = function getTip(callback) {
|
||||
var self = this;
|
||||
return this.db.fetch(layout.R(), function(data) {
|
||||
return this.db.fetch(layout.R, function(data) {
|
||||
assert(data.length === 32, 'Database corruption.');
|
||||
return data.toString('hex');
|
||||
}, function(err, hash) {
|
||||
@ -636,7 +630,7 @@ ChainDB.prototype.connect = function connect(entry, block, view, callback) {
|
||||
|
||||
batch.put(layout.n(entry.prevBlock), hash);
|
||||
batch.put(layout.H(entry.height), hash);
|
||||
batch.put(layout.R(), hash);
|
||||
batch.put(layout.R, hash);
|
||||
|
||||
this.cacheHash.set(entry.hash, entry);
|
||||
this.cacheHeight.set(entry.height, entry);
|
||||
@ -667,7 +661,7 @@ ChainDB.prototype.disconnect = function disconnect(entry, callback) {
|
||||
|
||||
batch.del(layout.n(entry.prevBlock));
|
||||
batch.del(layout.H(entry.height));
|
||||
batch.put(layout.R(), new Buffer(entry.prevBlock, 'hex'));
|
||||
batch.put(layout.R, new Buffer(entry.prevBlock, 'hex'));
|
||||
|
||||
this.cacheHeight.remove(entry.height);
|
||||
|
||||
@ -777,7 +771,7 @@ ChainDB.prototype.reset = function reset(block, callback) {
|
||||
batch = self.db.batch();
|
||||
|
||||
if (tip.hash === entry.hash) {
|
||||
batch.put(layout.R(), new Buffer(tip.hash, 'hex'));
|
||||
batch.put(layout.R, new Buffer(tip.hash, 'hex'));
|
||||
return batch.write(callback);
|
||||
}
|
||||
|
||||
@ -878,7 +872,6 @@ ChainDB.prototype.removeBlock = function removeBlock(hash, batch, callback) {
|
||||
*/
|
||||
|
||||
ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callback) {
|
||||
var self = this;
|
||||
var undo = new BufferWriter();
|
||||
var i, j, tx, input, output, key, addresses, address, hash, coins, raw;
|
||||
|
||||
@ -973,7 +966,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, batch, callb
|
||||
|
||||
ChainDB.prototype.disconnectBlock = function disconnectBlock(block, batch, callback) {
|
||||
var self = this;
|
||||
var i, j, tx, input, output, key, addresses, address, hash, view, coins, raw;
|
||||
var i, j, tx, input, output, key, addresses, address, hash, coins, raw;
|
||||
|
||||
if (this.options.spv)
|
||||
return utils.nextTick(callback);
|
||||
@ -1132,9 +1125,6 @@ ChainDB.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||
if (coins) {
|
||||
callback = utils.asyncify(callback);
|
||||
|
||||
if (raw)
|
||||
return callback(null, coins);
|
||||
|
||||
try {
|
||||
coins = bcoin.coins.parseCoin(coins, hash, index);
|
||||
} catch (e) {
|
||||
|
||||
@ -186,7 +186,7 @@ Coins.prototype.toRaw = function toRaw(writer) {
|
||||
Coins.parseRaw = function parseRaw(data, hash, index) {
|
||||
var p = new BufferReader(data);
|
||||
var i = 0;
|
||||
var version, height, coins, mask, prefix, offset, size;
|
||||
var version, height, coin, coins, mask, prefix, offset, size;
|
||||
|
||||
version = p.readVarint();
|
||||
height = p.readU32();
|
||||
@ -236,10 +236,12 @@ Coins.parseRaw = function parseRaw(data, hash, index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
coins.outputs.push(new DeferredCoin(offset, size, data));
|
||||
coin = new DeferredCoin(offset, size, data);
|
||||
|
||||
if (index != null)
|
||||
return coins.outputs[0].toCoin(coins, i);
|
||||
return coin.toCoin(coins, i);
|
||||
|
||||
coins.outputs.push(coin);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -1195,7 +1195,7 @@ Framer.alert = function alert(data, key, writer) {
|
||||
var network = bcoin.network.get(data.network);
|
||||
var p, i, payload, hash, time;
|
||||
var version, relayUntil, expiration, id, cancel;
|
||||
var cancels, count, i, minVer, maxVer, subVers;
|
||||
var cancels, minVer, maxVer, subVers;
|
||||
var priority, comment, statusBar, reserved;
|
||||
|
||||
if (!key && network.alertPrivateKey)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user