mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Redefine DisputeAgentType REFUNDAGENT as REFUND_AGENT
The CLI needs to be able to register a REFUND_AGENT using the 'refund_agent' or 'refundagent' parameter value (in any case), so an alt-name mapping was added to the enum def.
This commit is contained in:
parent
96abda4e2d
commit
35a77be7e4
@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
||||
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.REFUNDAGENT;
|
||||
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;
|
||||
|
||||
@ -148,6 +148,6 @@ public class MethodTest extends ApiTestCase {
|
||||
protected static void registerDisputeAgents(BisqAppConfig bisqAppConfig) {
|
||||
var disputeAgentsService = grpcStubs(bisqAppConfig).disputeAgentsService;
|
||||
disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(MEDIATOR.name()));
|
||||
disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(REFUNDAGENT.name()));
|
||||
disputeAgentsService.registerDisputeAgent(createRegisterDisputeAgentRequest(REFUND_AGENT.name()));
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ 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.REFUNDAGENT;
|
||||
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;
|
||||
@ -82,7 +82,7 @@ public class RegisterDisputeAgentsTest extends MethodTest {
|
||||
@Order(3)
|
||||
public void testInvalidRegistrationKeyArgShouldThrowException() {
|
||||
var req = RegisterDisputeAgentRequest.newBuilder()
|
||||
.setDisputeAgentType(REFUNDAGENT.name().toLowerCase())
|
||||
.setDisputeAgentType(REFUND_AGENT.name().toLowerCase())
|
||||
.setRegistrationKey("invalid" + DEV_PRIVILEGE_PRIV_KEY).build();
|
||||
Throwable exception = assertThrows(StatusRuntimeException.class, () ->
|
||||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req));
|
||||
@ -102,7 +102,7 @@ public class RegisterDisputeAgentsTest extends MethodTest {
|
||||
@Order(5)
|
||||
public void testRegisterRefundAgent() {
|
||||
var req =
|
||||
createRegisterDisputeAgentRequest(REFUNDAGENT.name());
|
||||
createRegisterDisputeAgentRequest(REFUND_AGENT.name());
|
||||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req);
|
||||
}
|
||||
|
||||
|
@ -32,15 +32,18 @@ import org.bitcoinj.core.ECKey;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
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 java.net.InetAddress.getLoopbackAddress;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Arrays.stream;
|
||||
|
||||
@Slf4j
|
||||
class CoreDisputeAgentsService {
|
||||
@ -65,10 +68,10 @@ class CoreDisputeAgentsService {
|
||||
this.refundAgentManager = refundAgentManager;
|
||||
this.p2PService = p2PService;
|
||||
this.nodeAddress = new NodeAddress(getLoopbackAddress().getHostAddress(), config.nodePort);
|
||||
this.languageCodes = Arrays.asList("de", "en", "es", "fr");
|
||||
this.languageCodes = asList("de", "en", "es", "fr");
|
||||
}
|
||||
|
||||
void registerDisputeAgent(String disputeAgentType, String registrationKey) {
|
||||
void registerDisputeAgent(String disputeAgentTypeString, String registrationKey) {
|
||||
if (!p2PService.isBootstrapped())
|
||||
throw new IllegalStateException("p2p service is not bootstrapped yet");
|
||||
|
||||
@ -80,23 +83,26 @@ class CoreDisputeAgentsService {
|
||||
if (!registrationKey.equals(DEV_PRIVILEGE_PRIV_KEY))
|
||||
throw new IllegalArgumentException("invalid registration key");
|
||||
|
||||
ECKey ecKey;
|
||||
String signature;
|
||||
switch (disputeAgentType) {
|
||||
case "arbitrator":
|
||||
throw new IllegalArgumentException("arbitrators must be registered in a Bisq UI");
|
||||
case "mediator":
|
||||
ecKey = mediatorManager.getRegistrationKey(registrationKey);
|
||||
signature = mediatorManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey));
|
||||
registerMediator(nodeAddress, languageCodes, ecKey, signature);
|
||||
return;
|
||||
case "refundagent":
|
||||
ecKey = refundAgentManager.getRegistrationKey(registrationKey);
|
||||
signature = refundAgentManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey));
|
||||
registerRefundAgent(nodeAddress, languageCodes, ecKey, signature);
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown dispute agent type " + disputeAgentType);
|
||||
Optional<DisputeAgentType> disputeAgentType = getDisputeAgentTypeForString(disputeAgentTypeString);
|
||||
if (disputeAgentType.isPresent()) {
|
||||
ECKey ecKey;
|
||||
String signature;
|
||||
switch ((disputeAgentType.get())) {
|
||||
case ARBITRATOR:
|
||||
throw new IllegalArgumentException("arbitrators must be registered in a Bisq UI");
|
||||
case MEDIATOR:
|
||||
ecKey = mediatorManager.getRegistrationKey(registrationKey);
|
||||
signature = mediatorManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey));
|
||||
registerMediator(nodeAddress, languageCodes, ecKey, signature);
|
||||
return;
|
||||
case REFUND_AGENT:
|
||||
ecKey = refundAgentManager.getRegistrationKey(registrationKey);
|
||||
signature = refundAgentManager.signStorageSignaturePubKey(Objects.requireNonNull(ecKey));
|
||||
registerRefundAgent(nodeAddress, languageCodes, ecKey, signature);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("unknown dispute agent type " + disputeAgentTypeString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,4 +147,11 @@ class CoreDisputeAgentsService {
|
||||
refundAgentManager.getDisputeAgentByNodeAddress(nodeAddress).orElseThrow(() ->
|
||||
new IllegalStateException("could not register refund agent"));
|
||||
}
|
||||
|
||||
private Optional<DisputeAgentType> getDisputeAgentTypeForString(String disputeAgentTypeString) {
|
||||
return stream(DisputeAgentType.values())
|
||||
.filter(da -> da.name().equalsIgnoreCase(disputeAgentTypeString)
|
||||
|| da.alternateName().equalsIgnoreCase(disputeAgentTypeString))
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,13 @@ public abstract class DisputeAgent implements ProtectedStoragePayload, Expirable
|
||||
public enum DisputeAgentType {
|
||||
ARBITRATOR,
|
||||
MEDIATOR,
|
||||
REFUNDAGENT
|
||||
REFUND_AGENT;
|
||||
|
||||
public String alternateName() {
|
||||
return this.equals(REFUND_AGENT)
|
||||
? REFUND_AGENT.name().replace("_", "")
|
||||
: this.name();
|
||||
}
|
||||
}
|
||||
|
||||
protected final NodeAddress nodeAddress;
|
||||
|
Loading…
Reference in New Issue
Block a user