minor. remove sendBlock/sendTX.
This commit is contained in:
parent
5f6aa10cbc
commit
f714bbf2c0
@ -46,7 +46,6 @@ function Block(data) {
|
|||||||
|
|
||||||
bcoin.abstractblock.call(this, data);
|
bcoin.abstractblock.call(this, data);
|
||||||
|
|
||||||
this.type = 'block';
|
|
||||||
this.txs = [];
|
this.txs = [];
|
||||||
this._cbHeight = null;
|
this._cbHeight = null;
|
||||||
this._commitmentHash = null;
|
this._commitmentHash = null;
|
||||||
@ -563,9 +562,9 @@ Block.prototype.getPrevout = function getPrevout() {
|
|||||||
|
|
||||||
Block.prototype.inspect = function inspect() {
|
Block.prototype.inspect = function inspect() {
|
||||||
return {
|
return {
|
||||||
type: this.type,
|
type: 'block',
|
||||||
height: this.height,
|
|
||||||
hash: utils.revHex(this.hash('hex')),
|
hash: utils.revHex(this.hash('hex')),
|
||||||
|
height: this.height,
|
||||||
size: this.getSize(),
|
size: this.getSize(),
|
||||||
virtualSize: this.getVirtualSize(),
|
virtualSize: this.getVirtualSize(),
|
||||||
date: utils.date(this.ts),
|
date: utils.date(this.ts),
|
||||||
@ -594,8 +593,8 @@ Block.prototype.inspect = function inspect() {
|
|||||||
Block.prototype.toJSON = function toJSON() {
|
Block.prototype.toJSON = function toJSON() {
|
||||||
return {
|
return {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
height: this.height,
|
|
||||||
hash: utils.revHex(this.hash('hex')),
|
hash: utils.revHex(this.hash('hex')),
|
||||||
|
height: this.height,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
prevBlock: utils.revHex(this.prevBlock),
|
prevBlock: utils.revHex(this.prevBlock),
|
||||||
merkleRoot: utils.revHex(this.merkleRoot),
|
merkleRoot: utils.revHex(this.merkleRoot),
|
||||||
|
|||||||
@ -261,25 +261,12 @@ Fullnode.prototype.sendTX = function sendTX(item, wait, callback) {
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!wait) {
|
self.pool.announce(item);
|
||||||
self.pool.announce(item);
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.pool.announce(item, callback);
|
return callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast a block.
|
|
||||||
* @param {Block} item
|
|
||||||
* @param {Function} callback
|
|
||||||
*/
|
|
||||||
|
|
||||||
Fullnode.prototype.sendBlock = function sendBlock(item, callback) {
|
|
||||||
return this.pool.sendBlock(item, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the network.
|
* Connect to the network.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -62,7 +62,6 @@ function MTX(options) {
|
|||||||
if (!options)
|
if (!options)
|
||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
this.type = 'tx';
|
|
||||||
this.version = options.version || 1;
|
this.version = options.version || 1;
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
|
|||||||
@ -302,7 +302,20 @@ Peer.prototype.sendInv = function sendInv(items) {
|
|||||||
items = items.slice(0, 50000);
|
items = items.slice(0, 50000);
|
||||||
|
|
||||||
if (this.filter)
|
if (this.filter)
|
||||||
items = items.map(this.isWatched, this);
|
items = items.filter(this.isWatched, this);
|
||||||
|
|
||||||
|
items = items.map(function(msg) {
|
||||||
|
if (!(msg instanceof bcoin.tx)
|
||||||
|
&& !(msg instanceof bcoin.block)) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: (msg instanceof bcoin.tx)
|
||||||
|
? constants.inv.TX
|
||||||
|
: constants.inv.BLOCK,
|
||||||
|
hash: msg.hash()
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
this.write(this.framer.inv(items));
|
this.write(this.framer.inv(items));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -274,7 +274,7 @@ Pool.prototype._init = function _init() {
|
|||||||
|
|
||||||
this.chain.on('block', function(block, entry, peer) {
|
this.chain.on('block', function(block, entry, peer) {
|
||||||
// Emit merkle txs after the fact
|
// Emit merkle txs after the fact
|
||||||
if (block.type === 'merkleblock') {
|
if (self.options.spv) {
|
||||||
utils.forEachSerial(block.txs, function(tx, next) {
|
utils.forEachSerial(block.txs, function(tx, next) {
|
||||||
self._handleTX(tx, peer, next);
|
self._handleTX(tx, peer, next);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
@ -1639,32 +1639,6 @@ Pool.prototype.fulfill = function fulfill(hash) {
|
|||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast a block.
|
|
||||||
* @param {Block} block
|
|
||||||
* @param {Function} callback - Returns [Error]. Executes on request, reject,
|
|
||||||
* or timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Pool.prototype.sendBlock = function sendBlock(block, callback) {
|
|
||||||
return this.broadcast(block, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast a transaction.
|
|
||||||
* @param {TX} tx
|
|
||||||
* @param {Function} callback - Returns [Error]. Executes on request, reject,
|
|
||||||
* or timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Pool.prototype.sendTX = function sendTX(tx, callback) {
|
|
||||||
// Failsafe to avoid getting banned by bitcoind nodes.
|
|
||||||
if (!tx.isSane())
|
|
||||||
return utils.asyncify(callback)(new Error('CheckTransaction failed.'));
|
|
||||||
|
|
||||||
return this.broadcast(tx, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast a transaction or block.
|
* Broadcast a transaction or block.
|
||||||
* @param {TX|Block} msg
|
* @param {TX|Block} msg
|
||||||
@ -1685,8 +1659,7 @@ Pool.prototype.broadcast = function broadcast(msg, callback) {
|
|||||||
|
|
||||||
item = new BroadcastItem(this, msg, callback);
|
item = new BroadcastItem(this, msg, callback);
|
||||||
|
|
||||||
// return item.start();
|
return item.start();
|
||||||
return item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1697,16 +1670,7 @@ Pool.prototype.broadcast = function broadcast(msg, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.announce = function announce(msg) {
|
Pool.prototype.announce = function announce(msg) {
|
||||||
var i, msg;
|
for (var i = 0; i < this.peers.all.length; i++)
|
||||||
|
|
||||||
msg = {
|
|
||||||
type: (msg instanceof bcoin.tx)
|
|
||||||
? constants.inv.TX
|
|
||||||
: constants.inv.BLOCK,
|
|
||||||
hash: msg.hash()
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; i < this.peers.all.length; i++)
|
|
||||||
this.peers.all[i].sendInv(msg);
|
this.peers.all[i].sendInv(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1727,9 +1691,8 @@ Pool.prototype.destroy = function destroy(callback) {
|
|||||||
|
|
||||||
this.stopSync();
|
this.stopSync();
|
||||||
|
|
||||||
this.inv.list.forEach(function(entry) {
|
this.inv.list.slice().forEach(function(entry) {
|
||||||
clearTimeout(entry.timer);
|
entry.finish();
|
||||||
entry.timer = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(this.request.map).forEach(function(hash) {
|
Object.keys(this.request.map).forEach(function(hash) {
|
||||||
@ -2154,7 +2117,7 @@ function BroadcastItem(pool, item, callback) {
|
|||||||
this.type = (item instanceof bcoin.tx)
|
this.type = (item instanceof bcoin.tx)
|
||||||
? constants.inv.TX
|
? constants.inv.TX
|
||||||
: constants.inv.BLOCK;
|
: constants.inv.BLOCK;
|
||||||
// this.msg = item;
|
this.msg = item;
|
||||||
this.hash = item.hash();
|
this.hash = item.hash();
|
||||||
this.normalValue = item.renderNormal();
|
this.normalValue = item.renderNormal();
|
||||||
this.witnessValue = item.render();
|
this.witnessValue = item.render();
|
||||||
@ -2164,8 +2127,6 @@ function BroadcastItem(pool, item, callback) {
|
|||||||
assert((this.type & constants.WITNESS_MASK) === 0);
|
assert((this.type & constants.WITNESS_MASK) === 0);
|
||||||
|
|
||||||
this.addCallback(callback);
|
this.addCallback(callback);
|
||||||
|
|
||||||
this.start(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(BroadcastItem, EventEmitter);
|
utils.inherits(BroadcastItem, EventEmitter);
|
||||||
@ -2182,10 +2143,9 @@ BroadcastItem.prototype.addCallback = function addCallback(callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the broadcast.
|
* Start the broadcast.
|
||||||
* @param {TX|Block} item
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BroadcastItem.prototype.start = function start(item) {
|
BroadcastItem.prototype.start = function start() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
@ -2195,7 +2155,7 @@ BroadcastItem.prototype.start = function start(item) {
|
|||||||
this.pool.inv.map[this.key] = this;
|
this.pool.inv.map[this.key] = this;
|
||||||
utils.binaryInsert(this.pool.inv.list, this, compare);
|
utils.binaryInsert(this.pool.inv.list, this, compare);
|
||||||
|
|
||||||
this.refresh(item);
|
this.refresh();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -2204,7 +2164,9 @@ BroadcastItem.prototype.start = function start(item) {
|
|||||||
* Refresh the timeout on the broadcast.
|
* Refresh the timeout on the broadcast.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BroadcastItem.prototype.refresh = function refresh(item) {
|
BroadcastItem.prototype.refresh = function refresh() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (this.timeout) {
|
if (this.timeout) {
|
||||||
clearTimeout(this.timeout);
|
clearTimeout(this.timeout);
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
@ -2215,10 +2177,8 @@ BroadcastItem.prototype.refresh = function refresh(item) {
|
|||||||
self.finish(new Error('Timed out.'));
|
self.finish(new Error('Timed out.'));
|
||||||
}, this.pool.inv.timeout);
|
}, this.pool.inv.timeout);
|
||||||
|
|
||||||
for (i = 0; i < this.pool.peers.all.length; i++) {
|
for (i = 0; i < this.pool.peers.all.length; i++)
|
||||||
if (this.pool.peers.all[i].isWatched(item))
|
this.pool.peers.all[i].sendInv(this);
|
||||||
this.pool.peers.all[i].sendInv(this);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -187,21 +187,11 @@ SPVNode.prototype.sendTX = function sendTX(item, wait, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!wait) {
|
if (!wait) {
|
||||||
this.pool.sendTX(item);
|
this.pool.broadcast(item);
|
||||||
return utils.nextTick(callback);
|
return utils.nextTick(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.pool.sendTX(item, callback);
|
return this.pool.broadcast(item, callback);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast a block.
|
|
||||||
* @param {Block} item
|
|
||||||
* @param {Function} callback
|
|
||||||
*/
|
|
||||||
|
|
||||||
SPVNode.prototype.sendBlock = function sendBlock(item, callback) {
|
|
||||||
return this.pool.sendBlock(item, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -60,7 +60,6 @@ function TX(data) {
|
|||||||
assert(Array.isArray(data.outputs));
|
assert(Array.isArray(data.outputs));
|
||||||
assert(typeof data.locktime === 'number');
|
assert(typeof data.locktime === 'number');
|
||||||
|
|
||||||
this.type = 'tx';
|
|
||||||
this.version = data.version;
|
this.version = data.version;
|
||||||
this.flag = data.flag;
|
this.flag = data.flag;
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
@ -1739,7 +1738,7 @@ TX.prototype.__defineGetter__('wtxid', function() {
|
|||||||
|
|
||||||
TX.prototype.inspect = function inspect() {
|
TX.prototype.inspect = function inspect() {
|
||||||
return {
|
return {
|
||||||
type: this.type,
|
type: 'tx',
|
||||||
hash: utils.revHex(this.hash('hex')),
|
hash: utils.revHex(this.hash('hex')),
|
||||||
witnessHash: utils.revHex(this.witnessHash('hex')),
|
witnessHash: utils.revHex(this.witnessHash('hex')),
|
||||||
size: this.getSize(),
|
size: this.getSize(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user