script json.
This commit is contained in:
parent
d158918a14
commit
a110ddab27
@ -117,7 +117,7 @@ Coin.prototype.toJSON = function toJSON() {
|
|||||||
version: this.version,
|
version: this.version,
|
||||||
height: this.height,
|
height: this.height,
|
||||||
value: utils.btc(this.value),
|
value: utils.btc(this.value),
|
||||||
script: utils.toHex(bcoin.protocol.framer.script(this.script)),
|
script: utils.toHex(this.script.encode()),
|
||||||
coinbase: this.coinbase,
|
coinbase: this.coinbase,
|
||||||
hash: this.hash ? utils.revHex(this.hash) : null,
|
hash: this.hash ? utils.revHex(this.hash) : null,
|
||||||
index: this.index
|
index: this.index
|
||||||
@ -129,7 +129,7 @@ Coin._fromJSON = function _fromJSON(json) {
|
|||||||
version: json.version,
|
version: json.version,
|
||||||
height: json.height,
|
height: json.height,
|
||||||
value: utils.satoshi(json.value),
|
value: utils.satoshi(json.value),
|
||||||
script: new bcoin.script(new Buffer(json.script, 'hex')),
|
script: bcoin.script.parseScript(new Buffer(json.script, 'hex')),
|
||||||
coinbase: json.coinbase,
|
coinbase: json.coinbase,
|
||||||
hash: json.hash ? utils.revHex(json.hash) : null,
|
hash: json.hash ? utils.revHex(json.hash) : null,
|
||||||
index: json.index
|
index: json.index
|
||||||
|
|||||||
@ -202,7 +202,7 @@ Input.prototype.toJSON = function toJSON() {
|
|||||||
index: this.prevout.index
|
index: this.prevout.index
|
||||||
},
|
},
|
||||||
coin: this.coin ? this.coin.toJSON() : null,
|
coin: this.coin ? this.coin.toJSON() : null,
|
||||||
script: utils.toHex(bcoin.protocol.framer.script(this.script)),
|
script: utils.toHex(this.script.encode()),
|
||||||
witness: utils.toHex(bcoin.protocol.framer.witness(this.witness)),
|
witness: utils.toHex(bcoin.protocol.framer.witness(this.witness)),
|
||||||
sequence: this.sequence
|
sequence: this.sequence
|
||||||
};
|
};
|
||||||
@ -215,7 +215,7 @@ Input._fromJSON = function _fromJSON(json) {
|
|||||||
index: json.prevout.index
|
index: json.prevout.index
|
||||||
},
|
},
|
||||||
coin: json.coin ? bcoin.coin._fromJSON(json.coin) : null,
|
coin: json.coin ? bcoin.coin._fromJSON(json.coin) : null,
|
||||||
script: bcoin.protocol.parser.parseScript(new Buffer(json.script, 'hex')),
|
script: bcoin.script.parseScript(new Buffer(json.script, 'hex')),
|
||||||
witness: bcoin.protocol.parser.parseWitness(new Buffer(json.witness, 'hex')),
|
witness: bcoin.protocol.parser.parseWitness(new Buffer(json.witness, 'hex')),
|
||||||
sequence: json.sequence
|
sequence: json.sequence
|
||||||
};
|
};
|
||||||
|
|||||||
@ -110,14 +110,14 @@ Output.prototype.inspect = function inspect() {
|
|||||||
Output.prototype.toJSON = function toJSON() {
|
Output.prototype.toJSON = function toJSON() {
|
||||||
return {
|
return {
|
||||||
value: utils.btc(this.value),
|
value: utils.btc(this.value),
|
||||||
script: utils.toHex(bcoin.protocol.framer.script(this.script))
|
script: utils.toHex(this.script.encode())
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Output._fromJSON = function _fromJSON(json) {
|
Output._fromJSON = function _fromJSON(json) {
|
||||||
return {
|
return {
|
||||||
value: utils.satoshi(json.value),
|
value: utils.satoshi(json.value),
|
||||||
script: new bcoin.script(new Buffer(json.script, 'hex'))
|
script: bcoin.script.parseScript(new Buffer(json.script, 'hex'))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2708,6 +2708,13 @@ Script.sign = function sign(msg, key, type) {
|
|||||||
return sig;
|
return sig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Script.parseScript = function parseScript(buf) {
|
||||||
|
return {
|
||||||
|
code: Script.decode(buf),
|
||||||
|
raw: buf
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
Script.decode = function decode(buf) {
|
Script.decode = function decode(buf) {
|
||||||
var code = [];
|
var code = [];
|
||||||
var off = 0;
|
var off = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user