Search in sources :

Example 1 with CreatePrivacyGroupParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.

the class PrivCreatePrivacyGroup method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    LOG.trace("Executing {}", RpcMethod.PRIV_CREATE_PRIVACY_GROUP.getMethodName());
    final CreatePrivacyGroupParameter parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class);
    LOG.trace("Creating a privacy group with name {} and description {}", parameter.getName(), parameter.getDescription());
    final PrivacyGroup response;
    try {
        response = privacyController.createPrivacyGroup(parameter.getAddresses(), parameter.getName(), parameter.getDescription(), privacyIdProvider.getPrivacyUserId(requestContext.getUser()));
    } catch (Exception e) {
        LOG.error("Failed to create privacy group", e);
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason(e.getMessage()));
    }
    return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response.getPrivacyGroupId());
}
Also used : CreatePrivacyGroupParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with CreatePrivacyGroupParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.

the class PrivCreatePrivacyGroupTest method verifyCreatePrivacyGroup.

@Test
public void verifyCreatePrivacyGroup() {
    final String expected = "a wonderful group";
    final PrivacyGroup privacyGroup = new PrivacyGroup(expected, PrivacyGroup.Type.PANTHEON, NAME, DESCRIPTION, ADDRESSES);
    when(privacyController.createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY)).thenReturn(privacyGroup);
    when(privacyParameters.getPrivacyUserId()).thenReturn(FROM);
    final PrivCreatePrivacyGroup privCreatePrivacyGroup = new PrivCreatePrivacyGroup(privacyController, privacyIdProvider);
    final CreatePrivacyGroupParameter param = new CreatePrivacyGroupParameter(ADDRESSES, NAME, DESCRIPTION);
    final Object[] params = new Object[] { param };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_createPrivacyGroup", params), user);
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privCreatePrivacyGroup.response(request);
    final String result = (String) response.getResult();
    assertThat(result).isEqualTo(expected);
    verify(privacyController).createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY);
}
Also used : CreatePrivacyGroupParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) JsonObject(io.vertx.core.json.JsonObject) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 3 with CreatePrivacyGroupParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.

the class PrivCreatePrivacyGroupTest method returnsCorrectErrorEnclaveError.

@Test
public void returnsCorrectErrorEnclaveError() {
    when(privacyController.createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY)).thenThrow(new EnclaveClientException(400, "Enclave error"));
    final PrivCreatePrivacyGroup privCreatePrivacyGroup = new PrivCreatePrivacyGroup(privacyController, privacyIdProvider);
    final CreatePrivacyGroupParameter param = new CreatePrivacyGroupParameter(ADDRESSES, NAME, DESCRIPTION);
    final Object[] params = new Object[] { param };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_createPrivacyGroup", params));
    final JsonRpcErrorResponse response = (JsonRpcErrorResponse) privCreatePrivacyGroup.response(request);
    final JsonRpcError result = response.getError();
    assertThat(result).isEqualTo(JsonRpcError.ENCLAVE_ERROR);
}
Also used : CreatePrivacyGroupParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) JsonObject(io.vertx.core.json.JsonObject) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) Test(org.junit.Test)

Aggregations

CreatePrivacyGroupParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter)3 JsonObject (io.vertx.core.json.JsonObject)2 PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)2 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)2 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 Test (org.junit.Test)2 EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)1 JsonRpcError (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError)1