minor. remove sendBlock/sendTX.

This commit is contained in:
Christopher Jeffrey 2016-05-18 23:21:53 -07:00
parent 5f6aa10cbc
commit f714bbf2c0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
7 changed files with 35 additions and 88 deletions

View File

@ -46,7 +46,6 @@ function Block(data) {
bcoin.abstractblock.call(this, data);
this.type = 'block';
this.txs = [];
this._cbHeight = null;
this._commitmentHash = null;
@ -563,9 +562,9 @@ Block.prototype.getPrevout = function getPrevout() {
Block.prototype.inspect = function inspect() {
return {
type: this.type,
height: this.height,
type: 'block',
hash: utils.revHex(this.hash('hex')),
height: this.height,
size: this.getSize(),
virtualSize: this.getVirtualSize(),
date: utils.date(this.ts),
@ -594,8 +593,8 @@ Block.prototype.inspect = function inspect() {
Block.prototype.toJSON = function toJSON() {
return {
type: 'block',
height: this.height,
hash: utils.revHex(this.hash('hex')),
height: this.height,
version: this.version,
prevBlock: utils.revHex(this.prevBlock),
merkleRoot: utils.revHex(this.merkleRoot),

View File

@ -261,25 +261,12 @@ Fullnode.prototype.sendTX = function sendTX(item, wait, callback) {
if (err)
return callback(err);
if (!wait) {
self.pool.announce(item);
return callback();
}
self.pool.announce(item);
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.
*/

View File

@ -62,7 +62,6 @@ function MTX(options) {
if (!options)
options = {};
this.type = 'tx';
this.version = options.version || 1;
this.inputs = [];
this.outputs = [];

View File

@ -302,7 +302,20 @@ Peer.prototype.sendInv = function sendInv(items) {
items = items.slice(0, 50000);
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));
};

View File

@ -274,7 +274,7 @@ Pool.prototype._init = function _init() {
this.chain.on('block', function(block, entry, peer) {
// Emit merkle txs after the fact
if (block.type === 'merkleblock') {
if (self.options.spv) {
utils.forEachSerial(block.txs, function(tx, next) {
self._handleTX(tx, peer, next);
}, function(err) {
@ -1639,32 +1639,6 @@ Pool.prototype.fulfill = function fulfill(hash) {
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.
* @param {TX|Block} msg
@ -1685,8 +1659,7 @@ Pool.prototype.broadcast = function broadcast(msg, callback) {
item = new BroadcastItem(this, msg, callback);
// return item.start();
return item;
return item.start();
};
/**
@ -1697,16 +1670,7 @@ Pool.prototype.broadcast = function broadcast(msg, callback) {
*/
Pool.prototype.announce = function announce(msg) {
var i, msg;
msg = {
type: (msg instanceof bcoin.tx)
? constants.inv.TX
: constants.inv.BLOCK,
hash: msg.hash()
};
for (i = 0; i < this.peers.all.length; i++)
for (var i = 0; i < this.peers.all.length; i++)
this.peers.all[i].sendInv(msg);
};
@ -1727,9 +1691,8 @@ Pool.prototype.destroy = function destroy(callback) {
this.stopSync();
this.inv.list.forEach(function(entry) {
clearTimeout(entry.timer);
entry.timer = null;
this.inv.list.slice().forEach(function(entry) {
entry.finish();
});
Object.keys(this.request.map).forEach(function(hash) {
@ -2154,7 +2117,7 @@ function BroadcastItem(pool, item, callback) {
this.type = (item instanceof bcoin.tx)
? constants.inv.TX
: constants.inv.BLOCK;
// this.msg = item;
this.msg = item;
this.hash = item.hash();
this.normalValue = item.renderNormal();
this.witnessValue = item.render();
@ -2164,8 +2127,6 @@ function BroadcastItem(pool, item, callback) {
assert((this.type & constants.WITNESS_MASK) === 0);
this.addCallback(callback);
this.start(item);
}
utils.inherits(BroadcastItem, EventEmitter);
@ -2182,10 +2143,9 @@ BroadcastItem.prototype.addCallback = function addCallback(callback) {
/**
* Start the broadcast.
* @param {TX|Block} item
*/
BroadcastItem.prototype.start = function start(item) {
BroadcastItem.prototype.start = function start() {
var self = this;
var i;
@ -2195,7 +2155,7 @@ BroadcastItem.prototype.start = function start(item) {
this.pool.inv.map[this.key] = this;
utils.binaryInsert(this.pool.inv.list, this, compare);
this.refresh(item);
this.refresh();
return this;
};
@ -2204,7 +2164,9 @@ BroadcastItem.prototype.start = function start(item) {
* Refresh the timeout on the broadcast.
*/
BroadcastItem.prototype.refresh = function refresh(item) {
BroadcastItem.prototype.refresh = function refresh() {
var self = this;
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
@ -2215,10 +2177,8 @@ BroadcastItem.prototype.refresh = function refresh(item) {
self.finish(new Error('Timed out.'));
}, this.pool.inv.timeout);
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);
}
for (i = 0; i < this.pool.peers.all.length; i++)
this.pool.peers.all[i].sendInv(this);
};
/**

View File

@ -187,21 +187,11 @@ SPVNode.prototype.sendTX = function sendTX(item, wait, callback) {
}
if (!wait) {
this.pool.sendTX(item);
this.pool.broadcast(item);
return utils.nextTick(callback);
}
return this.pool.sendTX(item, callback);
};
/**
* Broadcast a block.
* @param {Block} item
* @param {Function} callback
*/
SPVNode.prototype.sendBlock = function sendBlock(item, callback) {
return this.pool.sendBlock(item, callback);
return this.pool.broadcast(item, callback);
};
/**

View File

@ -60,7 +60,6 @@ function TX(data) {
assert(Array.isArray(data.outputs));
assert(typeof data.locktime === 'number');
this.type = 'tx';
this.version = data.version;
this.flag = data.flag;
this.inputs = [];
@ -1739,7 +1738,7 @@ TX.prototype.__defineGetter__('wtxid', function() {
TX.prototype.inspect = function inspect() {
return {
type: this.type,
type: 'tx',
hash: utils.revHex(this.hash('hex')),
witnessHash: utils.revHex(this.witnessHash('hex')),
size: this.getSize(),