refactor isChange logic

This commit is contained in:
Manuel Araoz 2014-04-30 19:50:13 -03:00
commit fd9e6cb48a
8 changed files with 89 additions and 66 deletions

View file

@ -401,6 +401,7 @@ Wallet.prototype.addSeenToTxProposals = function() {
return ret;
};
// TODO: remove this method and use getAddressesInfo everywhere
Wallet.prototype.getAddresses = function(excludeChange) {
return this.publicKeyRing.getAddresses(excludeChange);
};
@ -411,6 +412,10 @@ Wallet.prototype.getAddressesStr = function(excludeChange) {
});
};
Wallet.prototype.getAddressesInfo = function(excludeChange) {
return this.publicKeyRing.getAddressesInfo(excludeChange);
};
Wallet.prototype.addressIsOwn = function(addrStr) {
var addrList = this.getAddressesStr();
var l = addrList.length;
@ -430,15 +435,6 @@ Wallet.prototype.getBalance = function(safe, cb) {
var balanceByAddr = {};
var isMain = {};
var COIN = bitcore.util.COIN;
var addresses = this.getAddressesStr(true);
if (!addresses.length) return cb(0, []);
// Prefill balanceByAddr with main address
addresses.forEach(function(a) {
balanceByAddr[a] = 0;
isMain[a] = 1;
});
var f = safe ? this.getSafeUnspent.bind(this) : this.getUnspent.bind(this);
f(function(utxos) {
for (var i = 0; i < utxos.length; i++) {
@ -453,7 +449,6 @@ Wallet.prototype.getBalance = function(safe, cb) {
balanceByAddr[a] = balanceByAddr[a] / COIN;
}
balance = balance / COIN;
return cb(balance, balanceByAddr, isMain);
});
};