From d5d3dd69e2833344d47078b7fe7b6b43414b6f8e Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 20 Jan 2016 20:06:43 -0800 Subject: [PATCH] chaindb: minor improvements. --- lib/bcoin/chain.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index ca11ae2d..e42fb406 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -693,7 +693,6 @@ Chain.prototype.fromJSON = function fromJSON(json) { * ChainDB */ -// var BLOCK_SIZE = 80; var BLOCK_SIZE = 112; function ChainDB(chain) { @@ -789,7 +788,7 @@ ChainDB.prototype.save = function save(entry, callback) { this._queue[entry.height] = entry; // Write asynchronously to the db. - raw = new Buffer(entry.toRaw()); + raw = entry.toRaw(); offset = entry.height * BLOCK_SIZE; return this._write(raw, offset, function(err, success) { @@ -801,7 +800,7 @@ ChainDB.prototype.save = function save(entry, callback) { // Synchronously write it and get it over with. try { if (item !== entry) - success = self._writeSync(new Buffer(item.toRaw()), offset); + success = self._writeSync(item.toRaw(), offset); } catch (e) { err = e; } @@ -838,7 +837,7 @@ ChainDB.prototype.del = function del(height) { }; ChainDB.prototype.isNull = function isNull(height) { - var data = this._read(1, height * BLOCK_SIZE); + var data = this._read(4, height * BLOCK_SIZE); if (!data) return false; return utils.read32(data, 0) === 0; @@ -928,7 +927,6 @@ function ChainBlock(chain, data) { this.bits = data.bits; this.nonce = data.nonce; this.height = data.height; - // this.chainwork = data.chainwork || new bn(0); this.chainwork = data.chainwork || this.getChainwork(); } @@ -1009,7 +1007,7 @@ ChainBlock.fromJSON = function(chain, json) { }; ChainBlock.prototype.toRaw = function toRaw() { - var res = new Array(BLOCK_SIZE); + var res = new Buffer(BLOCK_SIZE); utils.writeU32(res, this.version, 0); utils.copy(utils.toArray(this.prevBlock, 'hex'), res, 4); @@ -1032,7 +1030,7 @@ ChainBlock.fromRaw = function fromRaw(chain, height, p) { bits: utils.readU32(p, 72), nonce: utils.readU32(p, 76), height: height, - chainwork: new bn(p.slice(80, 112)) + chainwork: new bn(p.slice(80, 112), 'be') }); };