drop toCompact/fromCompact.

This commit is contained in:
Christopher Jeffrey 2016-03-06 12:08:33 -08:00
parent cc1f423e3f
commit 2b1a822823
5 changed files with 32 additions and 126 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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
*/

View File

@ -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);

View File

@ -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',