1

I'm try get pending balance from wallet, but results do not match with pending transactions? Thanks for advice!

1 Answer 1

0

Edit: I don't think there's a method to do that, but this should do the same thing:

// calculate balance, only include transactions that are not in a block
List<TransactionOutput> candidates = wallet.calculateAllSpendCandidates(false, false);
Coin value = Coin.ZERO;
for (TransactionOutput out : candidates) {
    if(out.getParentTransaction().getAppearsInHashes() == null) {
        // Not seen in any block that we know of
        value = value.add(out.getValue());
    }
}
6
  • I want to get only pending amount, Wallet.getBalance() returns the available amount. Wallet.getBalance(Wallet.BalanceType.ESTIMATED) returns a total amount (available + pending). In theory total amount - available amount = pending amount, but this result not match with amount that I send to test. Commented Jul 23, 2015 at 17:23
  • @AnderAcosta Gotcha. Let me check the source to see if what you're looking for is possible.
    – Nick ODell
    Commented Jul 23, 2015 at 17:42
  • @AnderAcosta See edit.
    – Nick ODell
    Commented Jul 23, 2015 at 17:56
  • I'm using this: Coin pending = Coin.ZERO; for (Transaction transaction : wallet.getPendingTransactions()) { pending = pending.add(transaction.getValueSentToMe(wallet)); } I test your code and comparate the values, this returns the same value of your code Commented Jul 23, 2015 at 18:41
  • I think found a error. When I get the pending transactions , I get one, according blockchain.info has more than 1000 confirmations , but in the wallet , this transaction is in pending state. I checked the downloaded blocks and is synchronized with the blockchain . It may be a bug of bitcoinJ? This is the transaction: blockchain.info/tx/… Commented Jul 24, 2015 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.