Search in sources :

Example 1 with PublishToP2PNetworkException

use of bisq.core.dao.exceptions.PublishToP2PNetworkException in project bisq-core by bisq-network.

the class MyBlindVoteListService method publishBlindVote.

public void publishBlindVote(Coin stake, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
    try {
        SecretKey secretKey = BlindVoteConsensus.createSecretKey();
        BallotList sortedBallotList = BlindVoteConsensus.getSortedBallotList(ballotListService);
        byte[] encryptedVotes = getEncryptedVotes(sortedBallotList, secretKey);
        byte[] opReturnData = getOpReturnData(encryptedVotes);
        Coin blindVoteFee = BlindVoteConsensus.getFee(bsqStateService, bsqStateService.getChainHeight());
        Transaction blindVoteTx = getBlindVoteTx(stake, blindVoteFee, opReturnData);
        String blindVoteTxId = blindVoteTx.getHashAsString();
        byte[] encryptedMeritList = getEncryptedMeritList(blindVoteTxId, secretKey);
        // We prefer to not wait for the tx broadcast as if the tx broadcast would fail we still prefer to have our
        // blind vote stored and broadcasted to the p2p network. The tx might get re-broadcasted at a restart and
        // in worst case if it does not succeed the blind vote will be ignored anyway.
        // Inconsistently propagated blind votes in the p2p network could have potentially worse effects.
        BlindVote blindVote = new BlindVote(encryptedVotes, blindVoteTxId, stake.value, encryptedMeritList);
        addBlindVoteToList(blindVote);
        addToP2PNetwork(blindVote, errorMessage -> {
            log.error(errorMessage);
            exceptionHandler.handleException(new PublishToP2PNetworkException(errorMessage));
        });
        // We store our source data for the blind vote in myVoteList
        myVoteListService.createAndAddMyVote(sortedBallotList, secretKey, blindVote);
        publishTx(resultHandler, exceptionHandler, blindVoteTx);
    } catch (CryptoException | TransactionVerificationException | InsufficientMoneyException | WalletException | IOException exception) {
        exceptionHandler.handleException(exception);
    }
}
Also used : WalletException(bisq.core.btc.exceptions.WalletException) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) IOException(java.io.IOException) BallotList(bisq.core.dao.governance.ballot.BallotList) Coin(org.bitcoinj.core.Coin) SecretKey(javax.crypto.SecretKey) Transaction(org.bitcoinj.core.Transaction) CryptoException(bisq.common.crypto.CryptoException) PublishToP2PNetworkException(bisq.core.dao.exceptions.PublishToP2PNetworkException)

Aggregations

CryptoException (bisq.common.crypto.CryptoException)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 PublishToP2PNetworkException (bisq.core.dao.exceptions.PublishToP2PNetworkException)1 BallotList (bisq.core.dao.governance.ballot.BallotList)1 IOException (java.io.IOException)1 SecretKey (javax.crypto.SecretKey)1 Coin (org.bitcoinj.core.Coin)1 InsufficientMoneyException (org.bitcoinj.core.InsufficientMoneyException)1 Transaction (org.bitcoinj.core.Transaction)1