cleanup parser calls.

This commit is contained in:
Christopher Jeffrey 2016-02-24 20:59:30 -08:00
parent 27ecf6dde3
commit 2c2fa3913b
9 changed files with 15 additions and 35 deletions

View File

@ -264,15 +264,13 @@ Block.prototype.toCompact = function toCompact() {
};
Block._fromCompact = function _fromCompact(json) {
var raw, parser, data;
var raw, data;
assert.equal(json.type, 'block');
raw = new Buffer(json.block, 'hex');
parser = bcoin.protocol.parser;
data = parser.parseBlock(raw);
data = bcoin.protocol.parser.parseBlock(raw);
data.height = json.height;
@ -295,8 +293,6 @@ Block.prototype.toRaw = function toRaw(enc) {
};
Block._fromRaw = function _fromRaw(data, enc, type) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
@ -306,7 +302,7 @@ Block._fromRaw = function _fromRaw(data, enc, type) {
if (type === 'headers')
return bcoin.headers._fromRaw(data);
return parser.parseBlock(data);
return bcoin.protocol.parser.parseBlock(data);
};
Block.fromRaw = function fromRaw(data, enc, type) {

View File

@ -39,8 +39,6 @@ function BlockDB(options) {
this.options = options;
this.parser = bcoin.protocol.parser;
this.data = new BlockData(options);
this.cache = {
@ -548,7 +546,7 @@ BlockDB.prototype.getCoinsByAddress = function getCoinsByAddress(addresses, opti
return done();
try {
data = self.parser.parseOutput(data);
data = bcoin.protocol.parser.parseOutput(data);
} catch (e) {
return iter.end(function() {
done(e);
@ -604,7 +602,7 @@ BlockDB.prototype.getCoin = function getCoin(hash, index, callback) {
return callback();
try {
data = self.parser.parseOutput(data);
data = bcoin.protocol.parser.parseOutput(data);
} catch (e) {
return callback(e);
}
@ -696,7 +694,7 @@ BlockDB.prototype.getTXByAddress = function getTXByAddress(addresses, options, c
return next();
try {
tx = self.parser.parseTX(data);
tx = bcoin.protocol.parser.parseTX(data);
tx = new bcoin.tx(tx);
} catch (e) {
return iter.end(function() {
@ -759,7 +757,7 @@ BlockDB.prototype.getTX = function getTX(hash, callback) {
if (data) {
try {
tx = self.parser.parseTX(data);
tx = bcoin.protocol.parser.parseTX(data);
tx = new bcoin.tx(tx);
} catch (e) {
return callback(e);
@ -813,7 +811,7 @@ BlockDB.prototype.getBlock = function getBlock(hash, callback) {
if (data) {
try {
block = self.parser.parseBlock(data);
block = bcoin.protocol.parser.parseBlock(data);
block = new bcoin.block(block, 'block');
} catch (e) {
return callback(e);

View File

@ -170,12 +170,10 @@ Coin.prototype.toRaw = function toRaw(enc) {
};
Coin._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
data = parser.parseCoin(data, true);
data = bcoin.protocol.parser.parseCoin(data, true);
return data;
};

View File

@ -67,12 +67,10 @@ Headers.prototype.toRaw = function toRaw(enc) {
};
Headers._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
return parser.parseHeaders(data);
return bcoin.protocol.parser.parseHeaders(data);
};
Headers.fromRaw = function fromRaw(data, enc) {

View File

@ -396,12 +396,10 @@ Input.prototype.toRaw = function toRaw(enc) {
};
Input._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
data = parser.parseInput(data);
data = bcoin.protocol.parser.parseInput(data);
return data;
};

View File

@ -146,12 +146,10 @@ MerkleBlock.prototype.toRaw = function toRaw(enc) {
};
MerkleBlock._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
return parser.parseMerkleBlock(data);
return bcoin.protocol.parser.parseMerkleBlock(data);
};
MerkleBlock.fromRaw = function fromRaw(data, enc) {

View File

@ -1134,12 +1134,10 @@ MTX.prototype.toRaw = function toRaw(enc) {
};
MTX._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
return parser.parseTX(data);
return bcoin.protocol.parser.parseTX(data);
};
MTX.fromRaw = function fromRaw(data, enc) {

View File

@ -307,12 +307,10 @@ Output.prototype.toRaw = function toRaw(enc) {
};
Output._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
data = parser.parseOutput(data);
data = bcoin.protocol.parser.parseOutput(data);
return data;
};

View File

@ -844,12 +844,10 @@ TX.prototype.toRaw = function toRaw(enc) {
};
TX._fromRaw = function _fromRaw(data, enc) {
var parser = bcoin.protocol.parser;
if (enc === 'hex')
data = new Buffer(data, 'hex');
return parser.parseTX(data);
return bcoin.protocol.parser.parseTX(data);
};
TX.fromRaw = function fromRaw(data, enc) {