Skip to content

Commit

Permalink
Wallet: make balance futures work for all balance types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed Sep 2, 2015
1 parent a73677e commit 9470601
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions core/src/main/java/org/bitcoinj/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3210,23 +3210,14 @@ public ListenableFuture<Coin> getBalanceFuture(final Coin value, final BalanceTy
@SuppressWarnings("FieldAccessNotGuarded")
private void checkBalanceFuturesLocked(@Nullable Coin avail) {
checkState(lock.isHeldByCurrentThread());
Coin estimated = null;
final ListIterator<BalanceFutureRequest> it = balanceFutureRequests.listIterator();
while (it.hasNext()) {
final BalanceFutureRequest req = it.next();
Coin val = null;
if (req.type == BalanceType.AVAILABLE) {
if (avail == null) avail = getBalance(BalanceType.AVAILABLE);
if (avail.compareTo(req.value) < 0) continue;
val = avail;
} else if (req.type == BalanceType.ESTIMATED) {
if (estimated == null) estimated = getBalance(BalanceType.ESTIMATED);
if (estimated.compareTo(req.value) < 0) continue;
val = estimated;
}
Coin val = getBalance(req.type); // This could be slow for lots of futures.
if (val.compareTo(req.value) < 0) continue;
// Found one that's finished.
it.remove();
final Coin v = checkNotNull(val);
final Coin v = val;
// Don't run any user-provided future listeners with our lock held.
Threading.USER_THREAD.execute(new Runnable() {
@Override public void run() {
Expand Down

0 comments on commit 9470601

Please sign in to comment.