Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Replace TxInput/boolean fields in ParsingModel with BlindVoteOutputSt…
Browse files Browse the repository at this point in the history
…ate enum
  • Loading branch information
chirhonul committed Aug 11, 2018
1 parent 33dd797 commit 4b459e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ boolean validate(byte[] opReturnData, int blockHeight, ParsingModel parsingModel
boolean isInPhase = periodService.isInPhase(blockHeight, DaoPhase.Phase.VOTE_REVEAL);
if (!isInPhase)
log.warn("Not in VOTE_REVEAL phase. blockHeight={}", blockHeight);
return parsingModel.getInputFromBlindVoteStakeOutput() != null &&
parsingModel.isValidInputFromBlindVoteStakeOutput() &&
return parsingModel.getBlindVoteOutputState() == ParsingModel.BlindVoteOutputState.VALID &&
parsingModel.getVoteRevealUnlockStakeOutput() != null &&
opReturnData.length == 38 &&
isInPhase;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/bisq/core/dao/node/parser/ParsingModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
@Getter
@Setter
class ParsingModel {
/**
* The different possible states for an output used in a blind vote.
*/
enum BlindVoteOutputState {
UNKNOWN, VALID, INVALID
}
private TempTx tx;
private long availableInputValue = 0;
private long burntBondValue = 0;
Expand Down Expand Up @@ -68,12 +74,11 @@ class ParsingModel {
@Nullable
private OpReturnType opReturnTypeCandidate;

private BlindVoteOutputState blindVoteOutputState;

// At end of parsing when we do the full validation we set the type here
@Nullable
private OpReturnType verifiedOpReturnType;
@Nullable
private TxInput inputFromBlindVoteStakeOutput;
private boolean isValidInputFromBlindVoteStakeOutput;

ParsingModel() {
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/bisq/core/dao/node/parser/TxInputParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ void process(TxInput txInput, int blockHeight, String txId, int inputIndex, Pars
case ISSUANCE_CANDIDATE_OUTPUT:
break;
case BLIND_VOTE_LOCK_STAKE_OUTPUT:
if (parsingModel.getInputFromBlindVoteStakeOutput() == null) {
parsingModel.setInputFromBlindVoteStakeOutput(txInput);
// At the end of the parsing the OpReturnVoteRevealParser will verify that
// this property is true, otherwise the tx will be considered invalid.
parsingModel.setValidInputFromBlindVoteStakeOutput(true);
if (parsingModel.getBlindVoteOutputState() == ParsingModel.BlindVoteOutputState.UNKNOWN) {
// We found the input that's used as output of a blind vote. Only transactions with one such output
// is valid.
parsingModel.setBlindVoteOutputState(ParsingModel.BlindVoteOutputState.VALID);
} else {
log.warn("We have a tx which has 2 connected txOutputs marked as BLIND_VOTE_LOCK_STAKE_OUTPUT. " +
log.warn("We have a tx which has >1 connected txOutputs marked as BLIND_VOTE_LOCK_STAKE_OUTPUT. " +
"This is not a valid BSQ tx.");
parsingModel.setValidInputFromBlindVoteStakeOutput(false);
parsingModel.setBlindVoteOutputState(ParsingModel.BlindVoteOutputState.INVALID);
}
break;
case BLIND_VOTE_OP_RETURN_OUTPUT:
Expand Down

0 comments on commit 4b459e5

Please sign in to comment.