minor refactor.
This commit is contained in:
parent
17df9b41ce
commit
b4d40ca098
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user