diff --git a/lib/bcoin/coin.js b/lib/bcoin/coin.js index 27273ad2..e7188b91 100644 --- a/lib/bcoin/coin.js +++ b/lib/bcoin/coin.js @@ -32,8 +32,6 @@ function Coin(tx, index) { this.height = tx.height; this.value = tx.outputs[index].value; this.script = tx.outputs[index].script; - this._offset = tx.outputs[index]._offset; - this._size = tx.outputs[index]._size; this.coinbase = tx.isCoinbase(); this.hash = tx.hash('hex'); this.index = index; @@ -47,8 +45,6 @@ function Coin(tx, index) { this.coinbase = options.coinbase; this.hash = options.hash; this.index = options.index; - this._size = options._size || 0; - this._offset = options._offset || 0; } if (Buffer.isBuffer(this.hash)) @@ -75,10 +71,6 @@ Coin.prototype.getSize = function getSize() { return 4 + 4 + 8 + this.script.getSize() + 32 + 4 + 1; }; -Coin.prototype.isCoinbase = function isCoinbase() { - return false; -}; - Coin.prototype.getConfirmations = function getConfirmations(height) { var top; diff --git a/lib/bcoin/input.js b/lib/bcoin/input.js index d902ae09..5ebad7ef 100644 --- a/lib/bcoin/input.js +++ b/lib/bcoin/input.js @@ -7,6 +7,8 @@ var bcoin = require('../bcoin'); var utils = require('./utils'); var assert = utils.assert; +var BufferReader = require('./reader'); +var BufferWriter = require('./writer'); /** * Input @@ -22,8 +24,6 @@ function Input(options, tx) { this.script = options.script || new bcoin.script([]); this.sequence = options.sequence == null ? 0xffffffff : options.sequence; this.witness = options.witness || new bcoin.script.witness([]); - this._size = options._size || 0; - this._offset = options._offset || 0; this._witnessSize = options._witnessSize || 0; this._witnessOffset = options._witnessOffset || 0; this._mutable = !tx || (tx instanceof bcoin.mtx); @@ -270,13 +270,13 @@ Input.fromRaw = function fromRaw(data, enc) { }; Input.prototype.toExtended = function toExtended(enc) { - var input = bcoin.protocol.framer.input(this); - var witness = this.witness.encode(); - var data = new Buffer(data.length + witness.length); - var off = 0; + var p = new BufferWriter(); + var data; - off += utils.copy(input, data, off); - off += utils.copy(witness, data, off); + bcoin.protocol.framer.input(this, p); + bcoin.protocol.framer.witness(this.witness, p); + + data = p.render(); if (enc === 'hex') data = utils.toHex(data); @@ -285,13 +285,16 @@ Input.prototype.toExtended = function toExtended(enc) { }; Input._fromExtended = function _fromExtended(data, enc) { - var input; + var input, p; if (enc === 'hex') data = new Buffer(data, 'hex'); - input = bcoin.protocol.parser.parseInput(data); - input.witness = bcoin.protocol.parser.parseWitness(data.slice(input._size)); + p = new BufferReader(data); + p.start(); + input = bcoin.protocol.parser.parseInput(p); + input.witness = bcoin.protocol.parser.parseWitness(p).witness; + p.end(); return input; }; diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 0e9d06e2..cd5ed45f 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -291,7 +291,7 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) { self.verify(tx, function(err) { if (err) { if (err.type === 'VerifyError') { - if (err.score > -1) + if (err.score !== -1) peer.sendReject(tx, err.reason, err.score); return callback(err); } @@ -356,7 +356,7 @@ Mempool.prototype.verify = function verify(tx, callback) { input = tx.inputs[i]; coin = input.output; - if (coin.isCoinbase()) { + if (coin.coinbase) { if (this.chain.height - coin.height < constants.tx.coinbaseMaturity) return callback(new VerifyError('bad-txns-premature-spend-of-coinbase', 0)); } diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index aefc05fd..52b667c6 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -41,7 +41,6 @@ function MTX(options) { this._whash = null; this._raw = null; this._size = 0; - this._offset = 0; this._witnessSize = 0; this.height = -1; diff --git a/lib/bcoin/output.js b/lib/bcoin/output.js index f3a9cd85..5e038df3 100644 --- a/lib/bcoin/output.js +++ b/lib/bcoin/output.js @@ -30,8 +30,6 @@ function Output(options, tx) { this.value = utils.satoshi(value || new bn(0)); this.script = options.script || new bcoin.script([]); - this._size = options._size || 0; - this._offset = options._offset || 0; this._mutable = !tx || (tx instanceof bcoin.mtx); // For safety: do not allow usage of diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 4c8207d5..edeec60f 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -40,7 +40,6 @@ function TX(data, block, index) { this._whash = null; this._raw = data._raw || null; this._size = data._size || 0; - this._offset = data._offset || 0; this._witnessSize = data._witnessSize || 0; this.height = data.height != null ? data.height : -1;