diff --git a/core/src/main/java/bisq/core/dao/node/parser/TxOutputParser.java b/core/src/main/java/bisq/core/dao/node/parser/TxOutputParser.java index 3d6a933edf..d7a62273be 100644 --- a/core/src/main/java/bisq/core/dao/node/parser/TxOutputParser.java +++ b/core/src/main/java/bisq/core/dao/node/parser/TxOutputParser.java @@ -59,8 +59,6 @@ public class TxOutputParser { @Getter private boolean bsqOutputFound; @Getter - private Optional optionalOpReturnTypeCandidate = Optional.empty(); - @Getter private Optional optionalVerifiedOpReturnType = Optional.empty(); @Getter private Optional optionalIssuanceCandidate = Optional.empty(); @@ -82,9 +80,17 @@ public class TxOutputParser { } } - boolean isOpReturnCandidate(TempTxOutput txOutput) { - optionalOpReturnTypeCandidate = OpReturnParser.getOptionalOpReturnTypeCandidate(txOutput); - return optionalOpReturnTypeCandidate.isPresent(); + boolean isOpReturnOutput(TempTxOutput txOutput) { + return txOutput.getOpReturnData() != null; + } + + void processOpReturnOutput(boolean isLastOutput, TempTxOutput tempTxOutput) { + byte[] opReturnData = tempTxOutput.getOpReturnData(); + if (opReturnData != null) { + handleOpReturnOutput(tempTxOutput, isLastOutput); + } else { + log.error("This should be an opReturn output"); + } } /** @@ -110,14 +116,10 @@ public class TxOutputParser { handleBtcOutput(tempTxOutput, index); } } else { - handleOpReturnOutput(tempTxOutput, isLastOutput); + log.error("This should not be an opReturn output"); } } - boolean isOpReturnOutput(TempTxOutput txOutput) { - return txOutput.getOpReturnData() != null; - } - /** * Whether a transaction is a valid unlock bond transaction or not. * @@ -154,8 +156,8 @@ public class TxOutputParser { boolean isFirstOutput = index == 0; OpReturnType opReturnTypeCandidate = null; - if (optionalOpReturnTypeCandidate.isPresent()) - opReturnTypeCandidate = optionalOpReturnTypeCandidate.get(); + if (optionalVerifiedOpReturnType.isPresent()) + opReturnTypeCandidate = optionalVerifiedOpReturnType.get(); TxOutputType bsqOutput; if (isFirstOutput && opReturnTypeCandidate == OpReturnType.BLIND_VOTE) { @@ -182,8 +184,8 @@ public class TxOutputParser { // candidate to the parsingModel and we don't apply the TxOutputType as we do that later as the OpReturn check. if (availableInputValue > 0 && index == 1 && - optionalOpReturnTypeCandidate.isPresent() && - optionalOpReturnTypeCandidate.get() == OpReturnType.COMPENSATION_REQUEST) { + optionalVerifiedOpReturnType.isPresent() && + optionalVerifiedOpReturnType.get() == OpReturnType.COMPENSATION_REQUEST) { // We don't set the txOutputType yet as we have not fully validated the tx but put the candidate // into our local optionalIssuanceCandidate. diff --git a/core/src/main/java/bisq/core/dao/node/parser/TxParser.java b/core/src/main/java/bisq/core/dao/node/parser/TxParser.java index 0110480a4d..7d94509b00 100644 --- a/core/src/main/java/bisq/core/dao/node/parser/TxParser.java +++ b/core/src/main/java/bisq/core/dao/node/parser/TxParser.java @@ -116,8 +116,9 @@ public class TxParser { checkArgument(!outputs.isEmpty(), "outputs must not be empty"); int lastIndex = outputs.size() - 1; int lastNonOpReturnIndex = lastIndex; - if (txOutputParser.isOpReturnCandidate(outputs.get(lastIndex))) { - txOutputParser.processTxOutput(true, outputs.get(lastIndex), lastIndex); + if (txOutputParser.isOpReturnOutput(outputs.get(lastIndex))){ + // TODO(SQ): perhaps the check for isLastOutput could be skipped + txOutputParser.processOpReturnOutput(true, outputs.get(lastIndex)); lastNonOpReturnIndex -= 1; } @@ -145,7 +146,7 @@ public class TxParser { // use RawTx? TxType txType = TxParser.getBisqTxType( tempTx, - txOutputParser.getOptionalOpReturnTypeCandidate().isPresent(), + txOutputParser.getOptionalVerifiedOpReturnType().isPresent(), remainingInputValue, getOptionalOpReturnType() ); @@ -395,25 +396,7 @@ public class TxParser { */ private Optional getOptionalOpReturnType() { if (txOutputParser.isBsqOutputFound()) { - // We want to be sure that the initial assumption of the opReturn type was matching the result after full - // validation. - Optional optionalOpReturnTypeCandidate = txOutputParser.getOptionalOpReturnTypeCandidate(); - if (optionalOpReturnTypeCandidate.isPresent()) { - OpReturnType opReturnTypeCandidate = optionalOpReturnTypeCandidate.get(); - Optional optionalVerifiedOpReturnType = txOutputParser.getOptionalVerifiedOpReturnType(); - if (optionalVerifiedOpReturnType.isPresent()) { - OpReturnType verifiedOpReturnType = optionalVerifiedOpReturnType.get(); - if (opReturnTypeCandidate == verifiedOpReturnType) { - return optionalVerifiedOpReturnType; - } - } - } - - String msg = "We got a different opReturn type after validation as we expected initially. " + - "optionalOpReturnTypeCandidate=" + optionalOpReturnTypeCandidate + - ", optionalVerifiedOpReturnType=" + txOutputParser.getOptionalVerifiedOpReturnType(); - log.error(msg); - + return txOutputParser.getOptionalVerifiedOpReturnType(); } else { String msg = "We got a tx without any valid BSQ output but with burned BSQ. " + "Burned fee=" + remainingInputValue / 100D + " BSQ.";