Refactorings

This commit is contained in:
Manfred Karrer 2019-01-03 22:34:47 +01:00
parent c1792a3e7f
commit c87383a017
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
2 changed files with 8 additions and 29 deletions

View file

@ -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<Tx> optionalBlindVoteTx = daoStateService.getTx(blindVoteTxId);
checkArgument(optionalBlindVoteTx.isPresent(), "blindVoteTx with txId " +
blindVoteTxId + " not found.");
Tx blindVoteTx = optionalBlindVoteTx.get();
Optional<TxType> 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);
}

View file

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