diff --git a/BRWallet.c b/BRWallet.c index ebdc892d7..75bbeb2e2 100644 --- a/BRWallet.c +++ b/BRWallet.c @@ -167,7 +167,7 @@ static int _BRWalletContainsTx(BRWallet *wallet, const BRTransaction *tx) static void _BRWalletUpdateBalance(BRWallet *wallet) { - int isInvalid, isPending; + int isInvalid, isPending = 0; uint64_t balance = 0, prevBalance = 0; time_t now = time(NULL); size_t i, j; @@ -225,7 +225,6 @@ static void _BRWalletUpdateBalance(BRWallet *wallet) if (isPending) { BRSetAdd(wallet->pendingTx, tx); array_add(wallet->balanceHist, balance); - continue; } } @@ -239,12 +238,17 @@ static void _BRWalletUpdateBalance(BRWallet *wallet) if (pkh && BRSetContains(wallet->allPKH, pkh)) { BRSetAdd(wallet->usedPKH, (void *)pkh); - array_add(wallet->utxos, ((const BRUTXO) { tx->txHash, (uint32_t)j })); - balance += tx->outputs[j].amount; + + if (!isPending) { + array_add(wallet->utxos, ((const BRUTXO) { tx->txHash, (uint32_t)j })); + balance += tx->outputs[j].amount; + } } } } + if (isPending) continue; + // transaction ordering is not guaranteed, so check the entire UTXO set against the entire spent output set for (j = array_count(wallet->utxos); j > 0; j--) { if (! BRSetContains(wallet->spentOutputs, &wallet->utxos[j - 1])) continue;