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);
}
}
Aggregations