diff --git a/lib/bcoin/coin.js b/lib/bcoin/coin.js index d1788056..9d7858b2 100644 --- a/lib/bcoin/coin.js +++ b/lib/bcoin/coin.js @@ -117,7 +117,7 @@ Coin.prototype.toJSON = function toJSON() { version: this.version, height: this.height, value: utils.btc(this.value), - script: utils.toHex(bcoin.protocol.framer.script(this.script)), + script: utils.toHex(this.script.encode()), coinbase: this.coinbase, hash: this.hash ? utils.revHex(this.hash) : null, index: this.index @@ -129,7 +129,7 @@ Coin._fromJSON = function _fromJSON(json) { version: json.version, height: json.height, 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, hash: json.hash ? utils.revHex(json.hash) : null, index: json.index diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index 3c7fac6f..9d9e548b 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -202,7 +202,7 @@ Input.prototype.toJSON = function toJSON() { index: this.prevout.index }, 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)), sequence: this.sequence }; @@ -215,7 +215,7 @@ Input._fromJSON = function _fromJSON(json) { index: json.prevout.index }, 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')), sequence: json.sequence }; diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index 6a7ca59a..c762877a 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -110,14 +110,14 @@ Output.prototype.inspect = function inspect() { Output.prototype.toJSON = function toJSON() { return { 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) { return { value: utils.satoshi(json.value), - script: new bcoin.script(new Buffer(json.script, 'hex')) + script: bcoin.script.parseScript(new Buffer(json.script, 'hex')) }; }; diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index dca73ca2..b94d0dfc 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -2708,6 +2708,13 @@ Script.sign = function sign(msg, key, type) { return sig; }; +Script.parseScript = function parseScript(buf) { + return { + code: Script.decode(buf), + raw: buf + }; +}; + Script.decode = function decode(buf) { var code = []; var off = 0;