more json improvements.
This commit is contained in:
parent
ac9dfca3d3
commit
003330e678
@ -736,6 +736,7 @@ BlockDB.prototype._getTXByAddress = function _getTXByAddress(address, callback)
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
tx.network = true;
|
||||||
tx.height = record.height;
|
tx.height = record.height;
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
@ -810,6 +811,7 @@ BlockDB.prototype.getTX = function getTX(hash, callback) {
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
tx.network = true;
|
||||||
tx.height = record.height;
|
tx.height = record.height;
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
@ -861,8 +863,10 @@ BlockDB.prototype.getBlock = function getBlock(hash, callback) {
|
|||||||
return callback(e);
|
return callback(e);
|
||||||
}
|
}
|
||||||
block._fileOffset = record.offset;
|
block._fileOffset = record.offset;
|
||||||
|
block.network = true;
|
||||||
block.height = record.height;
|
block.height = record.height;
|
||||||
block.txs.forEach(function(tx) {
|
block.txs.forEach(function(tx) {
|
||||||
|
tx.network = true;
|
||||||
tx.height = block.height;
|
tx.height = block.height;
|
||||||
});
|
});
|
||||||
if (self.options.paranoid) {
|
if (self.options.paranoid) {
|
||||||
|
|||||||
@ -75,7 +75,7 @@ function TX(data, block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TX.prototype.setBlock = function setBlock(block) {
|
TX.prototype.setBlock = function setBlock(block) {
|
||||||
this.network = true;
|
this.network = block.network;
|
||||||
this.relayedBy = block.relayedBy;
|
this.relayedBy = block.relayedBy;
|
||||||
this.ts = block.ts;
|
this.ts = block.ts;
|
||||||
this.block = block.hash('hex');
|
this.block = block.hash('hex');
|
||||||
@ -1802,10 +1802,10 @@ TX.prototype.inspect = function inspect() {
|
|||||||
TX.prototype.toJSON = function toJSON(coins) {
|
TX.prototype.toJSON = function toJSON(coins) {
|
||||||
return {
|
return {
|
||||||
type: 'tx',
|
type: 'tx',
|
||||||
ts: this.ts,
|
|
||||||
ps: this.ps,
|
|
||||||
block: this.block,
|
block: this.block,
|
||||||
height: this.height,
|
height: this.height,
|
||||||
|
ts: this.ts,
|
||||||
|
ps: this.ps,
|
||||||
network: this.network,
|
network: this.network,
|
||||||
relayedBy: this.relayedBy,
|
relayedBy: this.relayedBy,
|
||||||
changeIndex: this.changeIndex,
|
changeIndex: this.changeIndex,
|
||||||
@ -1824,19 +1824,15 @@ TX.fromJSON = function fromJSON(json) {
|
|||||||
raw = new Buffer(json.tx, 'hex');
|
raw = new Buffer(json.tx, 'hex');
|
||||||
data = new bcoin.protocol.parser().parseTX(raw);
|
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.network = json.network;
|
||||||
data.relayedBy = json.relayedBy;
|
data.relayedBy = json.relayedBy;
|
||||||
|
|
||||||
data.changeIndex = json.changeIndex;
|
data.changeIndex = json.changeIndex;
|
||||||
|
|
||||||
data._raw = raw;
|
|
||||||
data._size = raw.length;
|
|
||||||
|
|
||||||
tx = new TX(data);
|
tx = new TX(data);
|
||||||
tx.height = json.height;
|
|
||||||
tx.ts = json.ts;
|
|
||||||
tx.block = json.block || null;
|
|
||||||
tx.ps = json.ps;
|
|
||||||
|
|
||||||
if (json.coins) {
|
if (json.coins) {
|
||||||
json.coins.forEach(function(output, i) {
|
json.coins.forEach(function(output, i) {
|
||||||
@ -1853,14 +1849,14 @@ TX.fromJSON = function fromJSON(json) {
|
|||||||
TX.prototype.toFullJSON = function toFullJSON() {
|
TX.prototype.toFullJSON = function toFullJSON() {
|
||||||
return {
|
return {
|
||||||
type: 'tx',
|
type: 'tx',
|
||||||
|
hash: utils.revHex(this.hash('hex')),
|
||||||
|
height: this.height,
|
||||||
|
block: this.block ? utils.revHex(this.block) : null,
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
ps: this.ps,
|
ps: this.ps,
|
||||||
block: this.block ? utils.revHex(this.block) : null,
|
|
||||||
height: this.height,
|
|
||||||
network: this.network,
|
network: this.network,
|
||||||
relayedBy: this.relayedBy,
|
relayedBy: this.relayedBy,
|
||||||
changeIndex: this.changeIndex,
|
changeIndex: this.changeIndex,
|
||||||
hash: utils.revHex(this.hash('hex')),
|
|
||||||
version: this.version,
|
version: this.version,
|
||||||
inputs: this.inputs.map(function(input) {
|
inputs: this.inputs.map(function(input) {
|
||||||
return input.toFullJSON();
|
return input.toFullJSON();
|
||||||
@ -1874,10 +1870,10 @@ TX.prototype.toFullJSON = function toFullJSON() {
|
|||||||
|
|
||||||
TX.fromFullJSON = function fromFullJSON(json) {
|
TX.fromFullJSON = function fromFullJSON(json) {
|
||||||
return new TX({
|
return new TX({
|
||||||
ts: json.ts,
|
|
||||||
ps: json.ps,
|
|
||||||
block: json.block ? utils.revHex(json.block) : null,
|
block: json.block ? utils.revHex(json.block) : null,
|
||||||
height: json.height,
|
height: json.height,
|
||||||
|
ts: json.ts,
|
||||||
|
ps: json.ps,
|
||||||
network: json.network,
|
network: json.network,
|
||||||
relayedBy: json.relayedBy,
|
relayedBy: json.relayedBy,
|
||||||
changeIndex: json.changeIndex,
|
changeIndex: json.changeIndex,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user