full json
This commit is contained in:
parent
9c7ca8501f
commit
ab3fb2e550
@ -530,10 +530,10 @@ Block.prototype.toFullJSON = function toFullJSON() {
|
|||||||
height: this.height,
|
height: this.height,
|
||||||
network: this.network,
|
network: this.network,
|
||||||
relayedBy: this.relayedBy,
|
relayedBy: this.relayedBy,
|
||||||
hash: this.hash('hex'),
|
hash: utils.revHex(this.hash('hex')),
|
||||||
version: this.version,
|
version: this.version,
|
||||||
prevBlock: this.prevBlock,
|
prevBlock: utils.revHex(this.prevBlock),
|
||||||
merkleRoot: this.merkleRoot,
|
merkleRoot: utils.revHex(this.merkleRoot),
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
bits: this.bits,
|
bits: this.bits,
|
||||||
nonce: this.nonce,
|
nonce: this.nonce,
|
||||||
@ -544,6 +544,15 @@ Block.prototype.toFullJSON = function toFullJSON() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Block.fromFullJSON = function fromFullJSON(json) {
|
Block.fromFullJSON = function fromFullJSON(json) {
|
||||||
|
json.prevBlock = utils.revHex(json.prevBlock);
|
||||||
|
json.merkleRoot = utils.revHex(json.merkleRoot);
|
||||||
|
json.txs = json.txs.map(function(tx) {
|
||||||
|
tx = bcoin.tx.fromFullJSON(tx);
|
||||||
|
tx.ts = block.ts;
|
||||||
|
tx.block = block.hash('hex');
|
||||||
|
tx.height = block.height;
|
||||||
|
return tx;
|
||||||
|
});
|
||||||
return new Block(json, json.subtype);
|
return new Block(json, json.subtype);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -144,6 +144,32 @@ Coin.fromJSON = function fromJSON(json) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Coin.prototype.toFullJSON = function toFullJSON() {
|
||||||
|
return {
|
||||||
|
version: this.version,
|
||||||
|
height: this.height,
|
||||||
|
value: utils.btc(this.value),
|
||||||
|
script: utils.toHex(bcoin.script.encode(this.script)),
|
||||||
|
hash: utils.revHex(this.hash),
|
||||||
|
index: this.index,
|
||||||
|
spent: this.spent,
|
||||||
|
address: this.getAddress()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Coin.fromFullJSON = function fromFullJSON(json) {
|
||||||
|
return new Coin({
|
||||||
|
version: json.version,
|
||||||
|
height: json.height,
|
||||||
|
value: utils.satoshi(json.value),
|
||||||
|
script: bcoin.script.decode(utils.toArray(json.script, 'hex')),
|
||||||
|
hash: utils.revHex(json.hash),
|
||||||
|
index: json.index,
|
||||||
|
spent: json.spent,
|
||||||
|
address: json.address
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// This is basically BIP64 with some
|
// This is basically BIP64 with some
|
||||||
// extra fields tacked on the end.
|
// extra fields tacked on the end.
|
||||||
Coin.prototype.toRaw = function toRaw(enc, strict) {
|
Coin.prototype.toRaw = function toRaw(enc, strict) {
|
||||||
|
|||||||
@ -77,6 +77,7 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
|
|
||||||
// UTXO by id
|
// UTXO by id
|
||||||
this.get('/utxo/:hash/:index', function(req, res, next, send) {
|
this.get('/utxo/:hash/:index', function(req, res, next, send) {
|
||||||
|
req.params.hash = utils.revHex(req.params.hash);
|
||||||
self.node.getCoin(req.params.hash, +req.params.index, function(err, coin) {
|
self.node.getCoin(req.params.hash, +req.params.index, function(err, coin) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
@ -99,6 +100,7 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
|
|
||||||
// TX by hash
|
// TX by hash
|
||||||
this.get('/tx/:hash', function(req, res, next, send) {
|
this.get('/tx/:hash', function(req, res, next, send) {
|
||||||
|
req.params.hash = utils.revHex(req.params.hash);
|
||||||
self.node.getTX(req.params.hash, function(err, tx) {
|
self.node.getTX(req.params.hash, function(err, tx) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
@ -137,6 +139,8 @@ HTTPServer.prototype._init = function _init() {
|
|||||||
|
|
||||||
if (utils.isInt(hash))
|
if (utils.isInt(hash))
|
||||||
hash = +hash;
|
hash = +hash;
|
||||||
|
else
|
||||||
|
hash = utils.revHex(hash);
|
||||||
|
|
||||||
self.node.getBlock(hash, function(err, block) {
|
self.node.getBlock(hash, function(err, block) {
|
||||||
if (err)
|
if (err)
|
||||||
|
|||||||
@ -365,22 +365,25 @@ Input.prototype.inspect = function inspect() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input.prototype.toJSON = function toJSON() {
|
Input.prototype.toFullJSON = function toFullJSON() {
|
||||||
return {
|
return {
|
||||||
prevout: {
|
prevout: {
|
||||||
hash: this.prevout.hash,
|
hash: utils.revHex(this.prevout.hash),
|
||||||
index: this.prevout.index
|
index: this.prevout.index
|
||||||
},
|
},
|
||||||
output: this.output ? this.output.toJSON() : null,
|
output: this.output ? this.output.toFullJSON() : null,
|
||||||
script: utils.toHex(bcoin.script.encode(this.script)),
|
script: utils.toHex(bcoin.script.encode(this.script)),
|
||||||
sequence: this.sequence
|
sequence: this.sequence
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input.fromJSON = function fromJSON(json) {
|
Input.fromFullJSON = function fromFullJSON(json) {
|
||||||
return new Input({
|
return new Input({
|
||||||
prevout: json.prevout,
|
prevout: {
|
||||||
output: json.output,
|
hash: utils.revHex(json.prevout.hash),
|
||||||
|
index: json.prevout.index
|
||||||
|
},
|
||||||
|
output: json.output ? bcoin.coin.fromFullJSON(json.output) : null,
|
||||||
script: bcoin.script.decode(utils.toArray(json.script, 'hex')),
|
script: bcoin.script.decode(utils.toArray(json.script, 'hex')),
|
||||||
sequence: json.sequence
|
sequence: json.sequence
|
||||||
});
|
});
|
||||||
|
|||||||
@ -259,14 +259,14 @@ Output.prototype.inspect = function inspect() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Output.prototype.toJSON = function toJSON() {
|
Output.prototype.toFullJSON = function toFullJSON() {
|
||||||
return {
|
return {
|
||||||
value: utils.btc(this.value),
|
value: utils.btc(this.value),
|
||||||
script: utils.toHex(bcoin.script.encode(this.script))
|
script: utils.toHex(bcoin.script.encode(this.script))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Output.fromJSON = function fromJSON(json) {
|
Output.fromFullJSON = function fromFullJSON(json) {
|
||||||
return new Output({
|
return new Output({
|
||||||
value: utils.satoshi(json.value),
|
value: utils.satoshi(json.value),
|
||||||
script: bcoin.script.decode(utils.toArray(json.script, 'hex'))
|
script: bcoin.script.decode(utils.toArray(json.script, 'hex'))
|
||||||
|
|||||||
@ -1828,17 +1828,18 @@ TX.prototype.toFullJSON = function toFullJSON() {
|
|||||||
type: 'tx',
|
type: 'tx',
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
ps: this.ps,
|
ps: this.ps,
|
||||||
block: this.block,
|
block: this.block ? utils.revHex(this.block) : null,
|
||||||
height: this.height,
|
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.toJSON();
|
return input.toFullJSON();
|
||||||
}),
|
}),
|
||||||
outputs: this.outputs.map(function(output) {
|
outputs: this.outputs.map(function(output) {
|
||||||
return output.toJSON();
|
return output.toFullJSON();
|
||||||
}),
|
}),
|
||||||
locktime: this.locktime
|
locktime: this.locktime
|
||||||
};
|
};
|
||||||
@ -1848,23 +1849,22 @@ TX.fromFullJSON = function fromFullJSON(json) {
|
|||||||
return new TX({
|
return new TX({
|
||||||
ts: json.ts,
|
ts: json.ts,
|
||||||
ps: json.ps,
|
ps: json.ps,
|
||||||
block: json.block,
|
block: json.block ? utils.revHex(json.block) : null,
|
||||||
height: json.height,
|
height: json.height,
|
||||||
network: json.network,
|
network: json.network,
|
||||||
relayedBy: json.relayedBy,
|
relayedBy: json.relayedBy,
|
||||||
changeIndex: json.changeIndex,
|
changeIndex: json.changeIndex,
|
||||||
version: json.version,
|
version: json.version,
|
||||||
inputs: json.inputs.map(function(input) {
|
inputs: json.inputs.map(function(input) {
|
||||||
return bcoin.input.fromJSON(input);
|
return bcoin.input.fromFullJSON(input);
|
||||||
}),
|
}),
|
||||||
outputs: json.outputs.map(function(output) {
|
outputs: json.outputs.map(function(output) {
|
||||||
return bcoin.output.fromJSON(output);
|
return bcoin.output.fromFullJSON(output);
|
||||||
}),
|
}),
|
||||||
locktime: json.locktime
|
locktime: json.locktime
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TX.fromJSON = function fromJSON(json) {
|
TX.fromJSON = function fromJSON(json) {
|
||||||
var raw, data, tx;
|
var raw, data, tx;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user