minor refactor

This commit is contained in:
Christopher Jeffrey 2016-02-24 07:32:05 -08:00
parent 42818c0646
commit c7ae1f3d6b
5 changed files with 14 additions and 7 deletions

View File

@ -17,7 +17,6 @@ var network = bcoin.protocol.network;
function Block(data) {
var self = this;
var tx, height;
if (!(this instanceof Block))
return new Block(data);

View File

@ -26,14 +26,14 @@ function MerkleBlock(data) {
this.hashes = (data.hashes || []).map(function(hash) {
return utils.toHex(hash);
});
this.flags = data.flags || [];
this.txs = data.txs || [];
// List of matched TXs
this.tx = [];
// TXs that will be pushed on
this.txs = data.txs || [];
this.txs = [];
if (!this._raw)
this._raw = this.render();
@ -116,7 +116,7 @@ MerkleBlock.prototype._verify = function _verify() {
// Verify the partial merkle tree if we are a merkleblock.
if (!this._verifyPartial()) {
utils.debug('MerkleBlock failed merkle test: %s', this.rhash);
utils.debug('Block failed merkle test: %s', this.rhash);
return false;
}

View File

@ -62,6 +62,10 @@ function MTX(options) {
utils.inherits(MTX, bcoin.tx);
MTX.prototype._init = function _init() {
;
};
MTX.prototype.clone = function clone() {
var tx = new MTX(this);

View File

@ -67,7 +67,7 @@ TXPool.prototype.add = function add(tx, noWrite) {
if (!this._wallet.ownInput(tx) && !this._wallet.ownOutput(tx))
return false;
if (tx instanceof bcoin.tx)
if (tx.type === 'tx')
tx = bcoin.mtx.fromTX(tx);
// Ignore stale pending transactions

View File

@ -54,7 +54,11 @@ function TX(data, block) {
}, this);
}
if (block && !data.ts) {
this._init(block);
}
TX.prototype._init = function _init(block) {
if (block && this.ts === 0) {
if (block.type === 'merkleblock') {
if (block.hasTX(this.hash('hex')))
this.setBlock(block);
@ -68,7 +72,7 @@ function TX(data, block) {
if (!this._size)
this._size = this._raw.length;
}
};
TX.prototype.setBlock = function setBlock(block) {
this.relayedBy = block.relayedBy;