minor refactor.
This commit is contained in:
parent
17df9b41ce
commit
b4d40ca098
@ -32,8 +32,6 @@ function Coin(tx, index) {
|
|||||||
this.height = tx.height;
|
this.height = tx.height;
|
||||||
this.value = tx.outputs[index].value;
|
this.value = tx.outputs[index].value;
|
||||||
this.script = tx.outputs[index].script;
|
this.script = tx.outputs[index].script;
|
||||||
this._offset = tx.outputs[index]._offset;
|
|
||||||
this._size = tx.outputs[index]._size;
|
|
||||||
this.coinbase = tx.isCoinbase();
|
this.coinbase = tx.isCoinbase();
|
||||||
this.hash = tx.hash('hex');
|
this.hash = tx.hash('hex');
|
||||||
this.index = index;
|
this.index = index;
|
||||||
@ -47,8 +45,6 @@ function Coin(tx, index) {
|
|||||||
this.coinbase = options.coinbase;
|
this.coinbase = options.coinbase;
|
||||||
this.hash = options.hash;
|
this.hash = options.hash;
|
||||||
this.index = options.index;
|
this.index = options.index;
|
||||||
this._size = options._size || 0;
|
|
||||||
this._offset = options._offset || 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Buffer.isBuffer(this.hash))
|
if (Buffer.isBuffer(this.hash))
|
||||||
@ -75,10 +71,6 @@ Coin.prototype.getSize = function getSize() {
|
|||||||
return 4 + 4 + 8 + this.script.getSize() + 32 + 4 + 1;
|
return 4 + 4 + 8 + this.script.getSize() + 32 + 4 + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Coin.prototype.isCoinbase = function isCoinbase() {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Coin.prototype.getConfirmations = function getConfirmations(height) {
|
Coin.prototype.getConfirmations = function getConfirmations(height) {
|
||||||
var top;
|
var top;
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
|
var BufferReader = require('./reader');
|
||||||
|
var BufferWriter = require('./writer');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input
|
* Input
|
||||||
@ -22,8 +24,6 @@ function Input(options, tx) {
|
|||||||
this.script = options.script || new bcoin.script([]);
|
this.script = options.script || new bcoin.script([]);
|
||||||
this.sequence = options.sequence == null ? 0xffffffff : options.sequence;
|
this.sequence = options.sequence == null ? 0xffffffff : options.sequence;
|
||||||
this.witness = options.witness || new bcoin.script.witness([]);
|
this.witness = options.witness || new bcoin.script.witness([]);
|
||||||
this._size = options._size || 0;
|
|
||||||
this._offset = options._offset || 0;
|
|
||||||
this._witnessSize = options._witnessSize || 0;
|
this._witnessSize = options._witnessSize || 0;
|
||||||
this._witnessOffset = options._witnessOffset || 0;
|
this._witnessOffset = options._witnessOffset || 0;
|
||||||
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
||||||
@ -270,13 +270,13 @@ Input.fromRaw = function fromRaw(data, enc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input.prototype.toExtended = function toExtended(enc) {
|
Input.prototype.toExtended = function toExtended(enc) {
|
||||||
var input = bcoin.protocol.framer.input(this);
|
var p = new BufferWriter();
|
||||||
var witness = this.witness.encode();
|
var data;
|
||||||
var data = new Buffer(data.length + witness.length);
|
|
||||||
var off = 0;
|
|
||||||
|
|
||||||
off += utils.copy(input, data, off);
|
bcoin.protocol.framer.input(this, p);
|
||||||
off += utils.copy(witness, data, off);
|
bcoin.protocol.framer.witness(this.witness, p);
|
||||||
|
|
||||||
|
data = p.render();
|
||||||
|
|
||||||
if (enc === 'hex')
|
if (enc === 'hex')
|
||||||
data = utils.toHex(data);
|
data = utils.toHex(data);
|
||||||
@ -285,13 +285,16 @@ Input.prototype.toExtended = function toExtended(enc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input._fromExtended = function _fromExtended(data, enc) {
|
Input._fromExtended = function _fromExtended(data, enc) {
|
||||||
var input;
|
var input, p;
|
||||||
|
|
||||||
if (enc === 'hex')
|
if (enc === 'hex')
|
||||||
data = new Buffer(data, 'hex');
|
data = new Buffer(data, 'hex');
|
||||||
|
|
||||||
input = bcoin.protocol.parser.parseInput(data);
|
p = new BufferReader(data);
|
||||||
input.witness = bcoin.protocol.parser.parseWitness(data.slice(input._size));
|
p.start();
|
||||||
|
input = bcoin.protocol.parser.parseInput(p);
|
||||||
|
input.witness = bcoin.protocol.parser.parseWitness(p).witness;
|
||||||
|
p.end();
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -291,7 +291,7 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
|
|||||||
self.verify(tx, function(err) {
|
self.verify(tx, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.type === 'VerifyError') {
|
if (err.type === 'VerifyError') {
|
||||||
if (err.score > -1)
|
if (err.score !== -1)
|
||||||
peer.sendReject(tx, err.reason, err.score);
|
peer.sendReject(tx, err.reason, err.score);
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ Mempool.prototype.verify = function verify(tx, callback) {
|
|||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
coin = input.output;
|
coin = input.output;
|
||||||
|
|
||||||
if (coin.isCoinbase()) {
|
if (coin.coinbase) {
|
||||||
if (this.chain.height - coin.height < constants.tx.coinbaseMaturity)
|
if (this.chain.height - coin.height < constants.tx.coinbaseMaturity)
|
||||||
return callback(new VerifyError('bad-txns-premature-spend-of-coinbase', 0));
|
return callback(new VerifyError('bad-txns-premature-spend-of-coinbase', 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,6 @@ function MTX(options) {
|
|||||||
this._whash = null;
|
this._whash = null;
|
||||||
this._raw = null;
|
this._raw = null;
|
||||||
this._size = 0;
|
this._size = 0;
|
||||||
this._offset = 0;
|
|
||||||
this._witnessSize = 0;
|
this._witnessSize = 0;
|
||||||
|
|
||||||
this.height = -1;
|
this.height = -1;
|
||||||
|
|||||||
@ -30,8 +30,6 @@ function Output(options, tx) {
|
|||||||
|
|
||||||
this.value = utils.satoshi(value || new bn(0));
|
this.value = utils.satoshi(value || new bn(0));
|
||||||
this.script = options.script || new bcoin.script([]);
|
this.script = options.script || new bcoin.script([]);
|
||||||
this._size = options._size || 0;
|
|
||||||
this._offset = options._offset || 0;
|
|
||||||
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
||||||
|
|
||||||
// For safety: do not allow usage of
|
// For safety: do not allow usage of
|
||||||
|
|||||||
@ -40,7 +40,6 @@ function TX(data, block, index) {
|
|||||||
this._whash = null;
|
this._whash = null;
|
||||||
this._raw = data._raw || null;
|
this._raw = data._raw || null;
|
||||||
this._size = data._size || 0;
|
this._size = data._size || 0;
|
||||||
this._offset = data._offset || 0;
|
|
||||||
this._witnessSize = data._witnessSize || 0;
|
this._witnessSize = data._witnessSize || 0;
|
||||||
|
|
||||||
this.height = data.height != null ? data.height : -1;
|
this.height = data.height != null ? data.height : -1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user