From c87383a01715b022f0b01951a07bd0cba85df8ce Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 3 Jan 2019 22:34:47 +0100 Subject: [PATCH] Refactorings --- .../voteresult/VoteResultConsensus.java | 12 ++++++--- .../votereveal/VoteRevealConsensus.java | 25 ------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultConsensus.java b/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultConsensus.java index 529fbf271e..a69b8d98e9 100644 --- a/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultConsensus.java +++ b/core/src/main/java/bisq/core/dao/governance/voteresult/VoteResultConsensus.java @@ -114,29 +114,33 @@ public class VoteResultConsensus { } } - public static Tx getBlindVoteTx(TxOutput blindVoteStakeOutput, DaoStateService daoStateService, - PeriodService periodService, int chainHeight) + public static void validateBlindVoteTx(String blindVoteTxId, DaoStateService daoStateService, + PeriodService periodService, int chainHeight) throws VoteResultException.ValidationException { try { - String blindVoteTxId = blindVoteStakeOutput.getTxId(); Optional optionalBlindVoteTx = daoStateService.getTx(blindVoteTxId); + checkArgument(optionalBlindVoteTx.isPresent(), "blindVoteTx with txId " + blindVoteTxId + " not found."); + Tx blindVoteTx = optionalBlindVoteTx.get(); Optional optionalTxType = daoStateService.getOptionalTxType(blindVoteTx.getId()); + checkArgument(optionalTxType.isPresent(), "optionalTxType must be present" + ". blindVoteTxId=" + blindVoteTx.getId()); + checkArgument(optionalTxType.get() == TxType.BLIND_VOTE, "blindVoteTx must have type BLIND_VOTE but is " + optionalTxType.get() + ". blindVoteTxId=" + blindVoteTx.getId()); + checkArgument(periodService.isTxInCorrectCycle(blindVoteTx.getBlockHeight(), chainHeight), "blindVoteTx is not in correct cycle. blindVoteTx.getBlockHeight()=" + blindVoteTx.getBlockHeight() + ". chainHeight=" + chainHeight + ". blindVoteTxId=" + blindVoteTx.getId()); + checkArgument(periodService.isInPhase(blindVoteTx.getBlockHeight(), DaoPhase.Phase.BLIND_VOTE), "blindVoteTx is not in BLIND_VOTE phase. blindVoteTx.getBlockHeight()=" + blindVoteTx.getBlockHeight() + ". blindVoteTxId=" + blindVoteTx.getId()); - return blindVoteTx; } catch (Throwable t) { throw new VoteResultException.ValidationException(t); } diff --git a/core/src/main/java/bisq/core/dao/governance/votereveal/VoteRevealConsensus.java b/core/src/main/java/bisq/core/dao/governance/votereveal/VoteRevealConsensus.java index 1aab110725..19993205fe 100644 --- a/core/src/main/java/bisq/core/dao/governance/votereveal/VoteRevealConsensus.java +++ b/core/src/main/java/bisq/core/dao/governance/votereveal/VoteRevealConsensus.java @@ -18,9 +18,7 @@ package bisq.core.dao.governance.votereveal; import bisq.core.dao.governance.blindvote.BlindVote; -import bisq.core.dao.governance.period.PeriodService; import bisq.core.dao.state.model.blockchain.OpReturnType; -import bisq.core.dao.state.model.governance.DaoPhase; import bisq.common.app.Version; import bisq.common.crypto.Hash; @@ -67,27 +65,4 @@ public class VoteRevealConsensus { throw e; } } - - public static boolean isBlindVoteTxInCorrectPhaseAndCycle(PeriodService periodService, String blindVoteTxId, int chainHeight) { - boolean isVoteRevealPhase = periodService.getPhaseForHeight(chainHeight) == DaoPhase.Phase.VOTE_REVEAL; - boolean isBlindVoteTxInCorrectCycle = periodService.isTxInCorrectCycle(blindVoteTxId, chainHeight); - return isVoteRevealPhase && isBlindVoteTxInCorrectCycle; - } - - public static boolean missedPhaseOrCycle(PeriodService periodService, String blindVoteTxId, int chainHeight) { - boolean isBlindVoteTxInCorrectCycle = periodService.isTxInCorrectCycle(blindVoteTxId, chainHeight); - boolean isAfterVoteRevealPhase = periodService.getPhaseForHeight(chainHeight).ordinal() > DaoPhase.Phase.VOTE_REVEAL.ordinal(); - - // We missed the reveal phase but we are in the correct cycle - boolean missedPhaseSameCycle = isAfterVoteRevealPhase && isBlindVoteTxInCorrectCycle; - - // If we missed the cycle we don't care about the phase anymore. - boolean isBlindVoteTxInPastCycle = periodService.isTxInPastCycle(blindVoteTxId, chainHeight); - return missedPhaseSameCycle || isBlindVoteTxInPastCycle; - } - - public static boolean isVoteRevealTxInCorrectPhaseAndCycle(PeriodService periodService, String voteRevealTxId, int chainHeight) { - return periodService.isTxInPhase(voteRevealTxId, DaoPhase.Phase.VOTE_REVEAL) && - periodService.isTxInCorrectCycle(voteRevealTxId, chainHeight); - } }