Search in sources :

Example 1 with BUILDING

use of org.bitcoinj.core.TransactionConfidence.ConfidenceType.BUILDING 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));
}
Also used : BsqBlockChainChangeDispatcher(bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Getter(lombok.Getter) Coin(org.bitcoinj.core.Coin) ScriptException(org.bitcoinj.core.ScriptException) CoinSelection(org.bitcoinj.wallet.CoinSelection) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Wallet(org.bitcoinj.wallet.Wallet) FXCollections(javafx.collections.FXCollections) BsqNode(bisq.core.dao.node.BsqNode) Function(java.util.function.Function) Inject(javax.inject.Inject) HashSet(java.util.HashSet) NetworkParameters(org.bitcoinj.core.NetworkParameters) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) SendRequest(org.bitcoinj.wallet.SendRequest) Map(java.util.Map) AbstractWalletEventListener(org.bitcoinj.wallet.listeners.AbstractWalletEventListener) BUILDING(org.bitcoinj.core.TransactionConfidence.ConfidenceType.BUILDING) PENDING(org.bitcoinj.core.TransactionConfidence.ConfidenceType.PENDING) AddressFormatException(org.bitcoinj.core.AddressFormatException) WalletException(bisq.core.btc.exceptions.WalletException) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) BlockChain(org.bitcoinj.core.BlockChain) Tx(bisq.core.dao.blockchain.vo.Tx) Set(java.util.Set) BisqEnvironment(bisq.core.app.BisqEnvironment) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) Collectors(java.util.stream.Collectors) ECKey(org.bitcoinj.core.ECKey) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Script(org.bitcoinj.script.Script) TransactionInput(org.bitcoinj.core.TransactionInput) Preferences(bisq.core.user.Preferences) TransactionOutput(org.bitcoinj.core.TransactionOutput) Optional(java.util.Optional) FeeService(bisq.core.provider.fee.FeeService) Address(org.bitcoinj.core.Address) ObservableList(javafx.collections.ObservableList) Restrictions(bisq.core.btc.Restrictions) Transaction(org.bitcoinj.core.Transaction)

Aggregations

BisqEnvironment (bisq.core.app.BisqEnvironment)1 Restrictions (bisq.core.btc.Restrictions)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 BsqBlockChainChangeDispatcher (bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher)1 ReadableBsqBlockChain (bisq.core.dao.blockchain.ReadableBsqBlockChain)1 Tx (bisq.core.dao.blockchain.vo.Tx)1 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)1 BsqNode (bisq.core.dao.node.BsqNode)1 FeeService (bisq.core.provider.fee.FeeService)1 Preferences (bisq.core.user.Preferences)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1