Search in sources :

Example 1 with WritableBsqBlockChain

use of bisq.core.dao.blockchain.WritableBsqBlockChain 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);
        }
    });
}
Also used : Encryption(bisq.common.crypto.Encryption) Arrays(java.util.Arrays) Slf4j(lombok.extern.slf4j.Slf4j) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) SecretKey(javax.crypto.SecretKey) WritableBsqBlockChain(bisq.core.dao.blockchain.WritableBsqBlockChain) Proposal(bisq.core.dao.proposal.Proposal) Hash(bisq.common.crypto.Hash) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) HashMap(java.util.HashMap)

Aggregations

Encryption (bisq.common.crypto.Encryption)1 Hash (bisq.common.crypto.Hash)1 ReadableBsqBlockChain (bisq.core.dao.blockchain.ReadableBsqBlockChain)1 WritableBsqBlockChain (bisq.core.dao.blockchain.WritableBsqBlockChain)1 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)1 Proposal (bisq.core.dao.proposal.Proposal)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 SecretKey (javax.crypto.SecretKey)1 Slf4j (lombok.extern.slf4j.Slf4j)1