diff --git a/lib/bcoin/blockdb.js b/lib/bcoin/blockdb.js index 1d837832..471d348c 100644 --- a/lib/bcoin/blockdb.js +++ b/lib/bcoin/blockdb.js @@ -736,6 +736,7 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback) if (err) return callback(err); + tx.network = true; tx.height = record.height; if (entry) { @@ -810,6 +811,7 @@ BlockDB.prototype.getTX = function getTX(hash, callback) { if (err) return callback(err); + tx.network = true; tx.height = record.height; if (entry) { @@ -861,8 +863,10 @@ BlockDB.prototype.getBlock = function getBlock(hash, callback) { return callback(e); } block._fileOffset = record.offset; + block.network = true; block.height = record.height; block.txs.forEach(function(tx) { + tx.network = true; tx.height = block.height; }); if (self.options.paranoid) { diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index a5821d09..985fdbbf 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -75,7 +75,7 @@ function TX(data, block) { } TX.prototype.setBlock = function setBlock(block) { - this.network = true; + this.network = block.network; this.relayedBy = block.relayedBy; this.ts = block.ts; this.block = block.hash('hex'); @@ -1802,10 +1802,10 @@ TX.prototype.inspect = function inspect() { TX.prototype.toJSON = function toJSON(coins) { return { type: 'tx', - ts: this.ts, - ps: this.ps, block: this.block, height: this.height, + ts: this.ts, + ps: this.ps, network: this.network, relayedBy: this.relayedBy, changeIndex: this.changeIndex, @@ -1824,19 +1824,15 @@ TX.fromJSON = function fromJSON(json) { raw = new Buffer(json.tx, 'hex'); data = new bcoin.protocol.parser().parseTX(raw); + data.height = json.height; + data.block = json.block; + data.ts = json.ts; + data.ps = json.ps; data.network = json.network; data.relayedBy = json.relayedBy; - data.changeIndex = json.changeIndex; - data._raw = raw; - data._size = raw.length; - tx = new TX(data); - tx.height = json.height; - tx.ts = json.ts; - tx.block = json.block || null; - tx.ps = json.ps; if (json.coins) { json.coins.forEach(function(output, i) { @@ -1853,14 +1849,14 @@ TX.fromJSON = function fromJSON(json) { TX.prototype.toFullJSON = function toFullJSON() { return { type: 'tx', + hash: utils.revHex(this.hash('hex')), + height: this.height, + block: this.block ? utils.revHex(this.block) : null, ts: this.ts, ps: this.ps, - block: this.block ? utils.revHex(this.block) : null, - height: this.height, network: this.network, relayedBy: this.relayedBy, changeIndex: this.changeIndex, - hash: utils.revHex(this.hash('hex')), version: this.version, inputs: this.inputs.map(function(input) { return input.toFullJSON(); @@ -1874,10 +1870,10 @@ TX.prototype.toFullJSON = function toFullJSON() { TX.fromFullJSON = function fromFullJSON(json) { return new TX({ - ts: json.ts, - ps: json.ps, block: json.block ? utils.revHex(json.block) : null, height: json.height, + ts: json.ts, + ps: json.ps, network: json.network, relayedBy: json.relayedBy, changeIndex: json.changeIndex,