use of bisq.core.dao.blockchain.vo.TxOutput in project bisq-desktop by bisq-network.
the class VoteListItem method calculateStake.
private void calculateStake() {
if (stake == 0) {
String txId = myVote.getTxId();
stake = readableBsqBlockChain.getLockedForVoteTxOutputs().stream().filter(txOutput -> txOutput.getTxId().equals(txId)).filter(txOutput -> txOutput.getIndex() == 0).mapToLong(TxOutput::getValue).sum();
stakeAsStringProperty.set(bsqFormatter.formatCoin(Coin.valueOf(stake)));
}
}
use of bisq.core.dao.blockchain.vo.TxOutput in project bisq-core by bisq-network.
the class BsqWalletService method getValueSentFromMeForTransaction.
@Override
public Coin getValueSentFromMeForTransaction(Transaction transaction) throws ScriptException {
Coin result = Coin.ZERO;
// We check all our inputs and get the connected outputs.
for (int i = 0; i < transaction.getInputs().size(); i++) {
TransactionInput input = transaction.getInputs().get(i);
// We grab the connected output for that input
TransactionOutput connectedOutput = input.getConnectedOutput();
if (connectedOutput != null) {
// We grab the parent tx of the connected output
final Transaction parentTransaction = connectedOutput.getParentTransaction();
final boolean isConfirmed = parentTransaction != null && parentTransaction.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
if (connectedOutput.isMineOrWatched(wallet)) {
if (isConfirmed) {
// We lookup if we have a BSQ tx matching the parent tx
// We cannot make that findTx call outside of the loop as the parent tx can change at each iteration
Optional<Tx> txOptional = readableBsqBlockChain.getTx(parentTransaction.getHash().toString());
if (txOptional.isPresent()) {
// BSQ tx and BitcoinJ tx have same outputs (mirrored data structure)
TxOutput txOutput = txOptional.get().getOutputs().get(connectedOutput.getIndex());
if (txOutput.isVerified()) {
// TODO check why values are not the same
if (txOutput.getValue() != connectedOutput.getValue().value)
log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " + "txOutput.getValue()={}, output.getValue().value={}, txId={}", txOutput.getValue(), connectedOutput.getValue().value, txOptional.get().getId());
// If it is a valid BSQ output we add it
result = result.add(Coin.valueOf(txOutput.getValue()));
}
}
}
/*else {
// TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
// if it will be required
// If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
result = result.add(connectedOutput.getValue());
}*/
}
}
}
return result;
}
use of bisq.core.dao.blockchain.vo.TxOutput in project bisq-core by bisq-network.
the class BsqWalletService method getValueSentToMeForTransaction.
@Override
public Coin getValueSentToMeForTransaction(Transaction transaction) throws ScriptException {
Coin result = Coin.ZERO;
final String txId = transaction.getHashAsString();
// We check if we have a matching BSQ tx. We do that call here to avoid repeated calls in the loop.
Optional<Tx> txOptional = readableBsqBlockChain.getTx(txId);
// We check all the outputs of our tx
for (int i = 0; i < transaction.getOutputs().size(); i++) {
TransactionOutput output = transaction.getOutputs().get(i);
final boolean isConfirmed = output.getParentTransaction() != null && output.getParentTransaction().getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING;
if (output.isMineOrWatched(wallet)) {
if (isConfirmed) {
if (txOptional.isPresent()) {
// The index of the BSQ tx outputs are the same like the bitcoinj tx outputs
TxOutput txOutput = txOptional.get().getOutputs().get(i);
if (txOutput.isVerified()) {
// TODO check why values are not the same
if (txOutput.getValue() != output.getValue().value)
log.warn("getValueSentToMeForTransaction: Value of BSQ output do not match BitcoinJ tx output. " + "txOutput.getValue()={}, output.getValue().value={}, txId={}", txOutput.getValue(), output.getValue().value, txId);
// If it is a valid BSQ output we add it
result = result.add(Coin.valueOf(txOutput.getValue()));
}
}
}
/*else {
// TODO atm we don't display amounts of unconfirmed txs but that might change so we leave that code
// if it will be required
// If the tx is not confirmed yet we add the value and assume it is a valid BSQ output.
result = result.add(output.getValue());
}*/
}
}
return result;
}
use of bisq.core.dao.blockchain.vo.TxOutput 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));
}
use of bisq.core.dao.blockchain.vo.TxOutput in project bisq-core by bisq-network.
the class IssuanceConsensus method applyVoteResult.
public static void applyVoteResult(Map<Proposal, Integer> stakeByProposalMap, ReadableBsqBlockChain readableBsqBlockChain, WritableBsqBlockChain writableBsqBlockChain) {
Map<String, TxOutput> txOutputsByTxIdMap = new HashMap<>();
final Set<TxOutput> compReqIssuanceTxOutputs = readableBsqBlockChain.getCompReqIssuanceTxOutputs();
compReqIssuanceTxOutputs.stream().filter(// our candidate is not yet verified and not set
txOutput -> !txOutput.isVerified()).forEach(txOutput -> txOutputsByTxIdMap.put(txOutput.getTxId(), txOutput));
stakeByProposalMap.forEach((proposal, value) -> {
int stakeResult = value;
if (stakeResult >= QUORUM) {
final String txId = proposal.getTxId();
if (txOutputsByTxIdMap.containsKey(txId)) {
final TxOutput txOutput = txOutputsByTxIdMap.get(txId);
writableBsqBlockChain.issueBsq(txOutput);
log.info("We issued new BSQ to txOutput {} for proposal {}", txOutput, proposal);
}
} else {
log.warn("We got a successful vote result but did not reach the quorum. stake={}, quorum={}", stakeResult, QUORUM);
}
});
}
Aggregations