diff --git a/apitest/src/test/java/bisq/apitest/method/MethodTest.java b/apitest/src/test/java/bisq/apitest/method/MethodTest.java index b7524580999..16a3e1da6d9 100644 --- a/apitest/src/test/java/bisq/apitest/method/MethodTest.java +++ b/apitest/src/test/java/bisq/apitest/method/MethodTest.java @@ -34,8 +34,6 @@ import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY; import static bisq.core.payment.payload.PaymentMethod.PERFECT_MONEY; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType.MEDIATOR; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType.REFUND_AGENT; import static java.util.Comparator.comparing; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -46,6 +44,10 @@ public class MethodTest extends ApiTestCase { + protected static final String ARBITRATOR = "arbitrator"; + protected static final String MEDIATOR = "mediator"; + protected static final String REFUND_AGENT = "refundagent"; + // Convenience methods for building gRPC request objects protected final GetBalanceRequest createBalanceRequest() { @@ -147,7 +149,7 @@ protected static RegisterDisputeAgentRequest createRegisterDisputeAgentRequest(S @SuppressWarnings("ResultOfMethodCallIgnored") protected static void registerDisputeAgents(BisqAppConfig bisqAppConfig) { var disputeAgentsService = grpcStubs(bisqAppConfig).disputeAgentsService; - disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(MEDIATOR.name())); - disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(REFUND_AGENT.name())); + disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(MEDIATOR)); + disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(REFUND_AGENT)); } } diff --git a/apitest/src/test/java/bisq/apitest/method/RegisterDisputeAgentsTest.java b/apitest/src/test/java/bisq/apitest/method/RegisterDisputeAgentsTest.java index 149013bbedf..f11f3e7ef13 100644 --- a/apitest/src/test/java/bisq/apitest/method/RegisterDisputeAgentsTest.java +++ b/apitest/src/test/java/bisq/apitest/method/RegisterDisputeAgentsTest.java @@ -33,9 +33,6 @@ import static bisq.apitest.config.BisqAppConfig.arbdaemon; import static bisq.apitest.config.BisqAppConfig.seednode; import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType.ARBITRATOR; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType.MEDIATOR; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType.REFUND_AGENT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; @@ -60,7 +57,7 @@ public static void setUp() { @Order(1) public void testRegisterArbitratorShouldThrowException() { var req = - createRegisterDisputeAgentRequest(ARBITRATOR.name()); + createRegisterDisputeAgentRequest(ARBITRATOR); Throwable exception = assertThrows(StatusRuntimeException.class, () -> grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req)); assertEquals("INVALID_ARGUMENT: arbitrators must be registered in a Bisq UI", @@ -82,7 +79,7 @@ public void testInvalidDisputeAgentTypeArgShouldThrowException() { @Order(3) public void testInvalidRegistrationKeyArgShouldThrowException() { var req = RegisterDisputeAgentRequest.newBuilder() - .setDisputeAgentType(REFUND_AGENT.name().toLowerCase()) + .setDisputeAgentType(REFUND_AGENT) .setRegistrationKey("invalid" + DEV_PRIVILEGE_PRIV_KEY).build(); Throwable exception = assertThrows(StatusRuntimeException.class, () -> grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req)); @@ -94,7 +91,7 @@ public void testInvalidRegistrationKeyArgShouldThrowException() { @Order(4) public void testRegisterMediator() { var req = - createRegisterDisputeAgentRequest(MEDIATOR.name()); + createRegisterDisputeAgentRequest(MEDIATOR); grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req); } @@ -102,7 +99,7 @@ public void testRegisterMediator() { @Order(5) public void testRegisterRefundAgent() { var req = - createRegisterDisputeAgentRequest(REFUND_AGENT.name()); + createRegisterDisputeAgentRequest(REFUND_AGENT); grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req); } diff --git a/core/src/main/java/bisq/core/api/CoreDisputeAgentsService.java b/core/src/main/java/bisq/core/api/CoreDisputeAgentsService.java index f0ae9a531b4..725044c21e7 100644 --- a/core/src/main/java/bisq/core/api/CoreDisputeAgentsService.java +++ b/core/src/main/java/bisq/core/api/CoreDisputeAgentsService.java @@ -17,6 +17,7 @@ package bisq.core.api; +import bisq.core.support.SupportType; import bisq.core.support.dispute.mediation.mediator.Mediator; import bisq.core.support.dispute.mediation.mediator.MediatorManager; import bisq.core.support.dispute.refund.refundagent.RefundAgent; @@ -40,10 +41,13 @@ import lombok.extern.slf4j.Slf4j; import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY; -import static bisq.core.support.dispute.agent.DisputeAgent.DisputeAgentType; +import static bisq.core.support.SupportType.ARBITRATION; +import static bisq.core.support.SupportType.MEDIATION; +import static bisq.core.support.SupportType.REFUND; +import static bisq.core.support.SupportType.TRADE; +import static java.lang.String.format; import static java.net.InetAddress.getLoopbackAddress; import static java.util.Arrays.asList; -import static java.util.Arrays.stream; @Slf4j class CoreDisputeAgentsService { @@ -71,7 +75,7 @@ public CoreDisputeAgentsService(Config config, this.languageCodes = asList("de", "en", "es", "fr"); } - void registerDisputeAgent(String disputeAgentTypeString, String registrationKey) { + void registerDisputeAgent(String disputeAgentType, String registrationKey) { if (!p2PService.isBootstrapped()) throw new IllegalStateException("p2p service is not bootstrapped yet"); @@ -83,26 +87,28 @@ void registerDisputeAgent(String disputeAgentTypeString, String registrationKey) if (!registrationKey.equals(DEV_PRIVILEGE_PRIV_KEY)) throw new IllegalArgumentException("invalid registration key"); - Optional disputeAgentType = getDisputeAgentTypeForString(disputeAgentTypeString); - if (disputeAgentType.isPresent()) { + Optional supportType = getSupportType(disputeAgentType); + if (supportType.isPresent()) { ECKey ecKey; String signature; - switch ((disputeAgentType.get())) { - case ARBITRATOR: + switch (supportType.get()) { + case ARBITRATION: throw new IllegalArgumentException("arbitrators must be registered in a Bisq UI"); - case MEDIATOR: + case MEDIATION: ecKey = mediatorManager.getRegistrationKey(registrationKey); signature = mediatorManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey)); registerMediator(nodeAddress, languageCodes, ecKey, signature); return; - case REFUND_AGENT: + case REFUND: ecKey = refundAgentManager.getRegistrationKey(registrationKey); signature = refundAgentManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey)); registerRefundAgent(nodeAddress, languageCodes, ecKey, signature); return; + case TRADE: + throw new IllegalArgumentException("trade agent registration not supported"); } } else { - throw new IllegalArgumentException("unknown dispute agent type " + disputeAgentTypeString); + throw new IllegalArgumentException(format("unknown dispute agent type '%s'", disputeAgentType)); } } @@ -148,10 +154,20 @@ private void registerRefundAgent(NodeAddress nodeAddress, new IllegalStateException("could not register refund agent")); } - private Optional getDisputeAgentTypeForString(String disputeAgentTypeString) { - return stream(DisputeAgentType.values()) - .filter(da -> da.name().equalsIgnoreCase(disputeAgentTypeString) - || da.alternateName().equalsIgnoreCase(disputeAgentTypeString)) - .findFirst(); + private Optional getSupportType(String disputeAgentType) { + switch (disputeAgentType.toLowerCase()) { + case "arbitrator": + return Optional.of(ARBITRATION); + case "mediator": + return Optional.of(MEDIATION); + case "refundagent": + case "refund_agent": + return Optional.of(REFUND); + case "tradeagent": + case "trade_agent": + return Optional.of(TRADE); + default: + return Optional.empty(); + } } } diff --git a/core/src/main/java/bisq/core/support/dispute/agent/DisputeAgent.java b/core/src/main/java/bisq/core/support/dispute/agent/DisputeAgent.java index 77afe3cdef1..aa583d04de8 100644 --- a/core/src/main/java/bisq/core/support/dispute/agent/DisputeAgent.java +++ b/core/src/main/java/bisq/core/support/dispute/agent/DisputeAgent.java @@ -43,18 +43,6 @@ public abstract class DisputeAgent implements ProtectedStoragePayload, ExpirablePayload { public static final long TTL = TimeUnit.DAYS.toMillis(10); - public enum DisputeAgentType { - ARBITRATOR, - MEDIATOR, - REFUND_AGENT; - - public String alternateName() { - return this.equals(REFUND_AGENT) - ? REFUND_AGENT.name().replace("_", "") - : this.name(); - } - } - protected final NodeAddress nodeAddress; protected final PubKeyRing pubKeyRing; protected final List languageCodes;