Merge pull request #1744 from eordano/performance/proposals

Fixes performance issue with txproposals
This commit is contained in:
Matias Alejo Garcia 2014-11-10 16:20:39 -03:00
commit 53e0065b74
2 changed files with 17 additions and 19 deletions

View File

@ -1303,7 +1303,7 @@ Wallet.prototype._getActionList = function(actions) {
* @return {Object[]} each object returned represents a transaction proposal * @return {Object[]} each object returned represents a transaction proposal
*/ */
Wallet.prototype.getPendingTxProposals = function() { Wallet.prototype.getPendingTxProposals = function() {
var that = this; var self = this;
var ret = []; var ret = [];
ret.txs = []; ret.txs = [];
var pendingForUs = 0; var pendingForUs = 0;
@ -1313,24 +1313,22 @@ Wallet.prototype.getPendingTxProposals = function() {
_.find(txps, function(txp) { _.find(txps, function(txp) {
if (txp.isPending) { if (txp.isPending) {
pendingForUs++; pendingForUs++;
var tx = txp.builder.build(); var addresses = {};
var outs = []; var outs = JSON.parse(txp.builder.vanilla.outs);
tx.outs.forEach(function(o) { outs.forEach(function(o) {
var addr = bitcore.Address.fromScriptPubKey(o.getScript(), that.getNetworkName())[0].toString(); if (!self.publicKeyRing.addressToPath[o.Straddress]) {
if (!that.addressIsOwn(addr, { if (!addresses[o.address]) addresses[o.address] = 0;
excludeMain: true addresses[o.address] += (o.amountSatStr || Math.round(o.amount * bitcore.util.COIN));
})) { };
outs.push({ });
address: addr, txp.outs = [];
value: bitcore.util.valueToBigInt(o.getValue()) * satToUnit, _.each(addresses, function(value, address) {
}); txp.outs.push({address: address, value: value * satToUnit});
}
}); });
// extra fields // extra fields
txp.outs = outs;
txp.fee = txp.builder.feeSat * satToUnit; txp.fee = txp.builder.feeSat * satToUnit;
txp.missingSignatures = tx.countInputMissingSignatures(0); txp.missingSignatures = txp.builder.build().countInputMissingSignatures(0);
txp.actionList = that._getActionList(txp.peerActions); txp.actionList = self._getActionList(txp.peerActions);
ret.txs.push(txp); ret.txs.push(txp);
} }
}); });
@ -2203,7 +2201,7 @@ Wallet.prototype.addressIsOwn = function(addrStr, opts) {
}; };
/* /**
* Estimate a tx fee in satoshis given its input count * Estimate a tx fee in satoshis given its input count
* only for spending all wallet funds * only for spending all wallet funds
*/ */

View File

@ -62,12 +62,12 @@ angular.module('copayApp.services')
}; };
root.updateTxsAndBalance = _.debounce(function(w) { root.updateTxsAndBalance = function(w) {
root.updateTxs(); root.updateTxs();
root.updateBalance(w, function() { root.updateBalance(w, function() {
$rootScope.$digest(); $rootScope.$digest();
}); });
}, 3000); };
root.installWalletHandlers = function($scope, w) { root.installWalletHandlers = function($scope, w) {