have node.sendTX add to mempool.

This commit is contained in:
Christopher Jeffrey 2016-04-08 18:03:17 -07:00
parent a166450335
commit 2a47abd98a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 30 additions and 21 deletions

View File

@ -197,8 +197,25 @@ Fullnode.prototype.broadcast = function broadcast(item, callback) {
return this.pool.broadcast(item, callback);
};
Fullnode.prototype.sendTX = function sendTX(item, callback) {
return this.pool.sendTX(item, callback);
Fullnode.prototype.sendTX = function sendTX(item, wait, callback) {
var self = this;
if (!callback) {
callback = wait;
wait = null;
}
this.mempool.addTX(item, function(err) {
if (err)
return callback(err);
if (!wait) {
self.pool.broadcast(item);
return callback();
}
self.pool.broadcast(item, callback);
});
};
Fullnode.prototype.sendBlock = function sendBlock(item, callback) {

View File

@ -306,12 +306,14 @@ NodeServer.prototype._init = function _init() {
address: req.options.address,
value: req.options.value
}, function(err, tx) {
if (err) {
wallet.destroy();
return next(err);
}
wallet.destroy();
if (err)
return next(err);
addTX(tx, function(err) {
self.node.sendTX(tx, false, function(err) {
if (err)
return next(err);
@ -321,20 +323,6 @@ NodeServer.prototype._init = function _init() {
});
});
function addMempool(tx, callback) {
if (!self.mempool)
return callback();
self.mempool.addTX(tx, callback);
}
function addTX(tx, callback) {
addMempool(tx, function(err) {
if (err)
return callback(err);
self.pool.broadcast(tx, callback);
});
}
// Zap Wallet TXs
this.post('/wallet/:id/zap', function(req, res, next, send) {
var id = req.options.id;

View File

@ -146,7 +146,11 @@ SPVNode.prototype.broadcast = function broadcast(item, callback) {
return this.pool.broadcast(item, callback);
};
SPVNode.prototype.sendTX = function sendTX(item, callback) {
SPVNode.prototype.sendTX = function sendTX(item, wait, callback) {
if (!callback) {
callback = wait;
wait = null;
}
return this.pool.sendTX(item, callback);
};