use of org.bitcoinj.core.TransactionConfidence.ConfidenceType.PENDING in project bisq-core by bisq-network.
the class BsqWalletService method updateBsqBalance.
// /////////////////////////////////////////////////////////////////////////////////////////
// Balance
// /////////////////////////////////////////////////////////////////////////////////////////
private void updateBsqBalance() {
pendingBalance = Coin.valueOf(getTransactions(false).stream().flatMap(tx -> tx.getOutputs().stream()).filter(out -> {
final Transaction parentTx = out.getParentTransaction();
return parentTx != null && out.isMine(wallet) && parentTx.getConfidence().getConfidenceType() == PENDING;
}).mapToLong(out -> out.getValue().value).sum());
Set<String> confirmedTxIdSet = getTransactions(false).stream().filter(tx -> tx.getConfidence().getConfidenceType() == BUILDING).map(Transaction::getHashAsString).collect(Collectors.toSet());
lockedForVotingBalance = Coin.valueOf(readableBsqBlockChain.getLockedForVoteTxOutputs().stream().filter(txOutput -> confirmedTxIdSet.contains(txOutput.getTxId())).mapToLong(TxOutput::getValue).sum());
lockedInBondsBalance = Coin.valueOf(readableBsqBlockChain.getLockedInBondsOutputs().stream().filter(txOutput -> confirmedTxIdSet.contains(txOutput.getTxId())).mapToLong(TxOutput::getValue).sum());
availableBalance = bsqCoinSelector.select(NetworkParameters.MAX_MONEY, wallet.calculateAllSpendCandidates()).valueGathered.subtract(lockedForVotingBalance).subtract(lockedInBondsBalance);
if (availableBalance.isNegative())
availableBalance = Coin.ZERO;
bsqBalanceListeners.forEach(e -> e.onUpdateBalances(availableBalance, pendingBalance, lockedForVotingBalance, lockedInBondsBalance));
}
Aggregations