From 2b1a822823a24e7c853778ed523fc1859a55fa76 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 6 Mar 2016 12:08:33 -0800 Subject: [PATCH] drop toCompact/fromCompact. --- lib/bcoin/block.js | 33 +--------------------------- lib/bcoin/coin.js | 15 ------------- lib/bcoin/input.js | 53 ++++++++++++++++++++++++++------------------- lib/bcoin/output.js | 15 ------------- lib/bcoin/tx.js | 42 ----------------------------------- 5 files changed, 32 insertions(+), 126 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 1d536add..e285122f 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -321,39 +321,8 @@ Block.fromJSON = function fromJSON(json) { return new Block(Block._fromJSON(json)); }; -Block.prototype.toCompact = function toCompact() { - return { - type: 'block', - hash: this.hash('hex'), - prevBlock: this.prevBlock, - ts: this.ts, - height: this.height, - block: utils.toHex(this.render()) - }; -}; - -Block._fromCompact = function _fromCompact(json) { - var raw, data; - - assert.equal(json.type, 'block'); - - raw = new Buffer(json.block, 'hex'); - - data = bcoin.protocol.parser.parseBlock(raw); - - data.height = json.height; - - return data; -}; - -Block.fromCompact = function fromCompact(json) { - return new Block(Block._fromCompact(json)); -}; - Block.prototype.toRaw = function toRaw(enc) { - var data; - - data = this.render(); + var data = this.render(); if (enc === 'hex') data = utils.toHex(data); diff --git a/lib/bcoin/coin.js b/lib/bcoin/coin.js index 3647db27..e9a90915 100644 --- a/lib/bcoin/coin.js +++ b/lib/bcoin/coin.js @@ -159,21 +159,6 @@ Coin.fromJSON = function fromJSON(json) { return new Coin(Coin._fromJSON(json)); }; -Coin.prototype.toCompact = function toCompact() { - return { - type: 'coin', - coin: this.toRaw('hex') - }; -}; - -Coin._fromCompact = function _fromCompact(json) { - return Coin._fromRaw(json.coin, 'hex'); -}; - -Coin.fromCompact = function fromCompact(json) { - return new Coin(Coin._fromCompact(json)); -}; - Coin.prototype.toRaw = function toRaw(enc) { var data = bcoin.protocol.framer.coin(this, true); diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index f7d4646b..aa81c8eb 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -289,28 +289,6 @@ Input.fromJSON = function fromJSON(json) { return new Input(Input._fromJSON(json)); }; -Input.prototype.toCompact = function toCompact() { - return { - type: 'input', - input: this.toRaw('hex'), - witness: this.witness.map(function(chunk) { - return utils.toHex(chunk); - }), - }; -}; - -Input._fromCompact = function _fromCompact(json) { - json = Input._fromRaw(json.input, 'hex'); - json.witness = json.witness.map(function(chunk) { - return new Buffer(chunk, 'hex'); - }); - return json; -}; - -Input.fromCompact = function fromCompact(json) { - return new Input(Input._fromCompact(json)); -}; - // NOTE: We cannot encode the witness here. Input.prototype.toRaw = function toRaw(enc) { var data = bcoin.protocol.framer.input(this); @@ -334,6 +312,37 @@ Input.fromRaw = function fromRaw(data, enc) { return new Input(Input._fromRaw(data, enc)); }; +Input.prototype.toExtended = function toExtended(enc) { + var input = bcoin.protocol.framer.input(this); + var witness = bcoin.protocol.framer.witness(this.witness); + var data = new Buffer(data.length + witness.length); + var off = 0; + + off += utils.copy(input, data, off); + off += utils.copy(witness, data, off); + + if (enc === 'hex') + data = utils.toHex(data); + + return data; +}; + +Input._fromExtended = function _fromExtended(data, enc) { + var input; + + if (enc === 'hex') + data = new Buffer(data, 'hex'); + + input = bcoin.protocol.parser.parseInput(data); + input.witness = bcoin.protocol.parser.parseWitness(data.slice(input._size)); + + return input; +}; + +Input.fromExtended = function fromExtended(data, enc) { + return new Input(Input._fromExtended(data, enc)); +}; + /** * Expose */ diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index cc2affc1..0faa143b 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -150,21 +150,6 @@ Output.fromJSON = function fromJSON(json) { return new Output(Output._fromJSON(json)); }; -Output.prototype.toCompact = function toCompact() { - return { - type: 'output', - output: this.toRaw('hex') - }; -}; - -Output._fromCompact = function _fromCompact(json) { - return Output._fromRaw(json.output, 'hex'); -}; - -Output.fromCompact = function fromCompact(json) { - return new Output(Output._fromCompact(json)); -}; - Output.prototype.toRaw = function toRaw(enc) { var data = bcoin.protocol.framer.output(this); diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 434ac4d0..35f4cec8 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1003,48 +1003,6 @@ TX.prototype.inspect = function inspect() { }; }; -TX.prototype.toCompact = function toCompact(coins) { - return { - type: this.type, - block: this.block, - height: this.height, - ts: this.ts, - ps: this.ps, - coins: coins ? this.inputs.map(function(input) { - return input.output ? input.output.toRaw('hex') : null; - }) : null, - tx: utils.toHex(this.render()) - }; -}; - -TX._fromCompact = function _fromCompact(json) { - var raw, data, tx; - - raw = new Buffer(json.tx, 'hex'); - data = bcoin.protocol.parser.parseTX(raw); - - data.height = json.height; - data.block = json.block; - data.ts = json.ts; - data.ps = json.ps; - - if (json.coins) { - json.coins.forEach(function(output, i) { - if (!output) - return; - - data.inputs[i].output = bcoin.coin._fromRaw(output, 'hex'); - }); - } - - return data; -}; - -TX.fromCompact = function fromCompact(json) { - assert.equal(json.type, 'tx'); - return new TX(TX._fromCompact(json)); -}; - TX.prototype.toJSON = function toJSON() { return { type: 'tx',