misc fixes and improvements.
This commit is contained in:
parent
4cc9b93fdd
commit
07ddae9d33
@ -91,6 +91,10 @@ Input.prototype.__defineGetter__('redeem', function() {
|
||||
return this.data.redeem;
|
||||
});
|
||||
|
||||
Input.prototype.__defineGetter__('scripthash', function() {
|
||||
return this.data.scripthash;
|
||||
});
|
||||
|
||||
Input.prototype.__defineGetter__('scriptaddress', function() {
|
||||
return this.data.scriptaddress;
|
||||
});
|
||||
|
||||
@ -89,6 +89,10 @@ Output.prototype.__defineGetter__('addresses', function() {
|
||||
return this.data.addresses || [];
|
||||
});
|
||||
|
||||
Output.prototype.__defineGetter__('scripthash', function() {
|
||||
return this.data.scripthash;
|
||||
});
|
||||
|
||||
Output.prototype.__defineGetter__('scriptaddress', function() {
|
||||
return this.data.scriptaddress;
|
||||
});
|
||||
|
||||
@ -396,6 +396,9 @@ Peer.prototype._onPacket = function onPacket(packet) {
|
||||
if (cmd === 'getaddr')
|
||||
return this._handleGetAddr();
|
||||
|
||||
if (cmd === 'reject')
|
||||
return this._handleReject(payload);
|
||||
|
||||
if (cmd === 'merkleblock' || cmd === 'block') {
|
||||
payload.network = true;
|
||||
payload.relayedBy = this.host || '0.0.0.0';
|
||||
@ -574,6 +577,18 @@ Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
||||
this.emit('headers', headers);
|
||||
};
|
||||
|
||||
Peer.prototype._handleReject = function handleReject(payload) {
|
||||
var hash = utils.toHex(payload.data);
|
||||
var entry = this._broadcast.map[hash];
|
||||
|
||||
this.emit('reject', payload);
|
||||
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
entry.e.emit('reject', payload);
|
||||
};
|
||||
|
||||
Peer.prototype.loadHeaders = function loadHeaders(hashes, stop) {
|
||||
utils.debug(
|
||||
'Requesting headers packet from %s with getheaders',
|
||||
@ -613,6 +628,7 @@ Peer.prototype.reject = function reject(details) {
|
||||
utils.debug(
|
||||
'Sending reject packet to %s',
|
||||
this.host);
|
||||
|
||||
this._write(this.framer.reject(details));
|
||||
};
|
||||
|
||||
|
||||
@ -27,7 +27,10 @@ function Pool(options) {
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.options = options || {};
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
this.options = options;
|
||||
|
||||
if (this.options.debug)
|
||||
bcoin.debug = this.options.debug;
|
||||
@ -36,6 +39,12 @@ function Pool(options) {
|
||||
network.set(this.options.network);
|
||||
|
||||
this.options.fullNode = !!this.options.fullNode;
|
||||
|
||||
if (options.type === 'spv')
|
||||
this.options.fullNode = false;
|
||||
else if (options.type === 'full')
|
||||
this.options.fullNode = true;
|
||||
|
||||
this.options.headers = this.options.headers;
|
||||
this.options.multiplePeers = this.options.multiplePeers;
|
||||
this.options.relay = this.options.relay == null
|
||||
@ -45,7 +54,6 @@ function Pool(options) {
|
||||
this.originalSeeds = (options.seeds || network.seeds).map(utils.parseHost);
|
||||
this.setSeeds([]);
|
||||
|
||||
this.storage = this.options.storage;
|
||||
this.destroyed = false;
|
||||
this.size = options.size || 32;
|
||||
this.parallel = options.parallel || 2000;
|
||||
@ -93,7 +101,6 @@ function Pool(options) {
|
||||
this.requestTimeout = options.requestTimeout || 10000;
|
||||
|
||||
this.chain = new bcoin.chain({
|
||||
storage: this.storage,
|
||||
fullNode: this.options.fullNode,
|
||||
multiplePeers: this.options.multiplePeers
|
||||
});
|
||||
@ -143,10 +150,10 @@ function Pool(options) {
|
||||
map: {}
|
||||
};
|
||||
|
||||
// Currently broadcasted TXs
|
||||
// Currently broadcasted objects
|
||||
this.inv = {
|
||||
list: [],
|
||||
timeout: options.txTimeout || 60000
|
||||
timeout: options.invTimeout || 60000
|
||||
};
|
||||
|
||||
// Added and watched wallets
|
||||
@ -191,7 +198,7 @@ Pool.prototype._init = function _init() {
|
||||
peer ? peer.host : ''
|
||||
);
|
||||
|
||||
self.emit('reorg', [data.expected, data.received]);
|
||||
self.emit('fork', [data.expected, data.received]);
|
||||
|
||||
if (!peer)
|
||||
return;
|
||||
@ -693,9 +700,12 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
||||
Pool.prototype._addIndex = function _addIndex(block, peer) {
|
||||
var added = this.chain.add(block, peer);
|
||||
|
||||
if (added === 0)
|
||||
return false;
|
||||
|
||||
this.emit('chain-progress', this.chain.fillPercent(), peer);
|
||||
|
||||
return added > 0;
|
||||
return true;
|
||||
};
|
||||
|
||||
Pool.prototype.isFull = function isFull() {
|
||||
@ -883,6 +893,10 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
|
||||
result[0].once('request', function() {
|
||||
entry.e.emit('ack', peer);
|
||||
});
|
||||
|
||||
result[0].once('reject', function(payload) {
|
||||
entry.e.emit('reject', payload, peer);
|
||||
});
|
||||
});
|
||||
|
||||
self._scheduleRequests();
|
||||
|
||||
@ -1269,13 +1269,6 @@ script.lockTime = function lockTime(s) {
|
||||
return script.num(lockTime, true);
|
||||
};
|
||||
|
||||
script.spendable = function spendable(s, lockTime) {
|
||||
if (script.lockTime(s) > lockTime)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
script.getInputData = function getData(s, prev) {
|
||||
var output, type;
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ function TX(data, block) {
|
||||
this.outputs = [];
|
||||
this.lock = data.lock || 0;
|
||||
this.ts = data.ts || 0;
|
||||
this.block = null;
|
||||
this.block = data.block || null;
|
||||
this._hash = null;
|
||||
|
||||
this._raw = data._raw || null;
|
||||
@ -62,6 +62,7 @@ function TX(data, block) {
|
||||
|
||||
this.unspent = data.unspent || null;
|
||||
this.hardFee = data.hardFee || null;
|
||||
this.subtractFee = data.subtractFee || null;
|
||||
this.changeAddress = data.changeAddress || null;
|
||||
this.changeIndex = data.changeIndex != null ? data.changeIndex : -1;
|
||||
|
||||
@ -922,6 +923,17 @@ TX.prototype.getUnspent = function getUnspent(unspent, address, fee) {
|
||||
value: new bn(0)
|
||||
});
|
||||
|
||||
// if (this.subtractFee) {
|
||||
// var f = new bn((Math.ceil(tx.maxSize() / 1024) - 1) * constants.tx.fee);
|
||||
// for (var j = 0; j < this.outputs.length; j++) {
|
||||
// if (this.outputs[j].value.cmp(f.addn(constants.tx.dust)) >= 0) {
|
||||
// this.outputs[j].value = this.outputs[j].value.sub(f);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// total = tx.funds('out');
|
||||
// }
|
||||
|
||||
// Change fee value if it is more than 1024
|
||||
// bytes (10000 satoshi for every 1024 bytes).
|
||||
do {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user