diff --git a/core/src/main/java/bisq/core/trade/AutoConfirmResult.java b/core/src/main/java/bisq/core/trade/AutoConfirmResult.java index c2b0c573ea..29f6bce8ac 100644 --- a/core/src/main/java/bisq/core/trade/AutoConfirmResult.java +++ b/core/src/main/java/bisq/core/trade/AutoConfirmResult.java @@ -21,15 +21,16 @@ import bisq.core.locale.Res; import bisq.common.proto.ProtoUtil; -import javax.annotation.Nullable; - import lombok.Value; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Nullable; + @Slf4j @Value public class AutoConfirmResult { public enum State { + UNDEFINED, FEATURE_DISABLED, TX_NOT_FOUND, TX_NOT_CONFIRMED, @@ -41,27 +42,25 @@ public class AutoConfirmResult { TX_HASH_INVALID, TX_KEY_INVALID, ADDRESS_INVALID, + NO_MATCH_FOUND, AMOUNT_NOT_MATCHING, TRADE_LIMIT_EXCEEDED, - TRADE_DATE_NOT_MATCHING; - - public static AutoConfirmResult.State fromProto(protobuf.Trade.AutoConfirmResult result) { - return ProtoUtil.enumFromProto(AutoConfirmResult.State.class, result.name()); - } - - public static protobuf.Trade.AutoConfirmResult toProtoMessage(AutoConfirmResult.State result) { - return protobuf.Trade.AutoConfirmResult.valueOf(result.name()); - } + TRADE_DATE_NOT_MATCHING } + // Only state gets persisted private final State state; + private final transient int confirmCount; private final transient int confirmsRequired; + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + public AutoConfirmResult(State state) { - this.state = state; - this.confirmCount = 0; - this.confirmsRequired = 0; + this(state, 0, 0); } // alternate constructor for showing confirmation progress information @@ -73,13 +72,33 @@ public class AutoConfirmResult { // alternate constructor for error scenarios public AutoConfirmResult(State state, @Nullable String errorMsg) { - this.state = state; - this.confirmCount = 0; - this.confirmsRequired = 0; - if (isErrorState()) + this(state, 0, 0); + + if (isErrorState()) { log.error(errorMsg != null ? errorMsg : state.toString()); + } } + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTOBUF + /////////////////////////////////////////////////////////////////////////////////////////// + + public protobuf.AutoConfirmResult toProtoMessage() { + return protobuf.AutoConfirmResult.newBuilder().setStateName(state.name()).build(); + } + + public static AutoConfirmResult fromProto(protobuf.AutoConfirmResult proto) { + AutoConfirmResult.State state = ProtoUtil.enumFromProto(AutoConfirmResult.State.class, proto.getStateName()); + return state != null ? new AutoConfirmResult(state) : new AutoConfirmResult(State.UNDEFINED); + + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + public String getTextStatus() { switch (state) { case TX_NOT_CONFIRMED: @@ -109,17 +128,4 @@ public class AutoConfirmResult { public boolean isErrorState() { return (!isPendingState() && !isSuccessState()); } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // PROTOBUF - /////////////////////////////////////////////////////////////////////////////////////////// - - public protobuf.Trade.AutoConfirmResult toProtoMessage() { - return State.toProtoMessage(state); - } - - public static AutoConfirmResult fromProto(protobuf.Trade.AutoConfirmResult proto) { - return new AutoConfirmResult(AutoConfirmResult.State.fromProto(proto)); - } } diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index eb9782abe3..5ca75ca76d 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -439,14 +439,16 @@ public abstract class Trade implements Tradable, Model { @Nullable private AutoConfirmResult autoConfirmResult; - public void setAutoConfirmResult(AutoConfirmResult autoConfirmResult) { + void setAutoConfirmResult(AutoConfirmResult autoConfirmResult) { this.autoConfirmResult = autoConfirmResult; autoConfirmResultProperty.setValue(autoConfirmResult); } + @Getter // This observable property can be used for UI to show a notification to user of the XMR proof status transient final private ObjectProperty autoConfirmResultProperty = new SimpleObjectProperty<>(); + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, initialization /////////////////////////////////////////////////////////////////////////////////////////// @@ -593,7 +595,7 @@ public abstract class Trade implements Tradable, Model { trade.setLockTime(proto.getLockTime()); trade.setLastRefreshRequestDate(proto.getLastRefreshRequestDate()); trade.setCounterCurrencyExtraData(ProtoUtil.stringOrNullFromProto(proto.getCounterCurrencyExtraData())); - trade.setAutoConfirmResult(AutoConfirmResult.fromProto(protobuf.Trade.AutoConfirmResult.valueOf(proto.getAutoConfirmResultValue()))); + trade.setAutoConfirmResult(AutoConfirmResult.fromProto(proto.getAutoConfirmResult())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 51791d4d8c..7b96a55f85 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1356,23 +1356,6 @@ message Trade { TRADE_PERIOD_OVER = 3; } - enum AutoConfirmResult { - FEATURE_DISABLED = 0; - TX_NOT_FOUND = 1; - TX_NOT_CONFIRMED = 2; - PROOF_OK = 3; - CONNECTION_FAIL = 4; - API_FAILURE = 5; - API_INVALID = 6; - TX_KEY_REUSED = 7; - TX_HASH_INVALID = 8; - TX_KEY_INVALID = 9; - ADDRESS_INVALID = 10; - AMOUNT_NOT_MATCHING = 11; - TRADE_LIMIT_EXCEEDED = 12; - TRADE_DATE_NOT_MATCHING = 13; - } - Offer offer = 1; ProcessModel process_model = 2; string taker_fee_tx_id = 3; @@ -1413,6 +1396,10 @@ message Trade { AutoConfirmResult auto_confirm_result = 38; } +message AutoConfirmResult { + string stateName = 1; // name of AutoConfirmResult.State enum +} + message BuyerAsMakerTrade { Trade trade = 1; }