Fixed actions on txProposal event

This commit is contained in:
Ivan Socolsky 2014-09-29 18:04:58 -03:00
commit 645734f139
2 changed files with 19 additions and 15 deletions

View file

@ -378,7 +378,7 @@ Wallet.prototype._onTxProposal = function(senderId, data) {
if (tx.isComplete()) { if (tx.isComplete()) {
this._checkSentTx(m.ntxid, function(ret) { this._checkSentTx(m.ntxid, function(ret) {
if (ret) { if (ret) {
m.txp.setSent(m.mtxid); m.txp.setSent(m.ntxid);
self.emit('txProposalsUpdated'); self.emit('txProposalsUpdated');
self.store(); self.store();
} }
@ -2107,9 +2107,20 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
cb = cb || function() {}; cb = cb || function() {};
var txps = _.where(this.getTxProposals(), { if (!_.some(self.getTxProposals(), {
isPending: true
}))
return cb();
var proposalsChanged = false;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
if (err) return cb(err);
var txps = _.where(self.getTxProposals(), {
isPending: true isPending: true
}); });
if (txps.length === 0) return cb();
var inputs = _.flatten(_.map(txps, function(txp) { var inputs = _.flatten(_.map(txps, function(txp) {
return _.map(txp.builder.utxos, function(utxo) { return _.map(txp.builder.utxos, function(utxo) {
return { return {
@ -2120,14 +2131,6 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
}); });
})); }));
if (inputs.length === 0)
return cb();
var proposalsChanged = false;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
if (err) return cb(err);
_.each(unspentList, function(unspent) { _.each(unspentList, function(unspent) {
_.each(inputs, function(input) { _.each(inputs, function(input) {
input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout); input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout);

View file

@ -1592,6 +1592,7 @@ describe('Wallet model', function() {
w._onTxProposal('senderID', data); w._onTxProposal('senderID', data);
txp.setSent.called.should.be.false; txp.setSent.called.should.be.false;
txp.setSent.calledWith(1).should.be.false;
w.sendTxProposal.called.should.be.false; w.sendTxProposal.called.should.be.false;
done(); done();
}); });