Search in sources :

Example 1 with GoQuorumReceiveResponse

use of org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse in project besu by hyperledger.

the class GoQuorumEthGetQuorumPayload method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final String key = requestContext.getRequiredParameter(0, String.class);
    final Bytes bytes;
    try {
        bytes = Bytes.fromHexString(key);
    } catch (final IllegalArgumentException e) {
        LOG.debug("Enclave key contains invalid hex character {}", key);
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    if (bytes.size() != 64) {
        LOG.debug("Enclave key expected length 64, but length is {}", bytes.size());
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    try {
        final GoQuorumReceiveResponse receive = enclave.receive(bytes.toBase64String());
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), Bytes.wrap(receive.getPayload()).toHexString());
    } catch (final EnclaveClientException ex) {
        if (ex.getStatusCode() == 404) {
            return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), Bytes.EMPTY.toHexString());
        } else {
            LOG.debug("Error retrieving enclave payload: ", ex);
            return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR);
        }
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) GoQuorumReceiveResponse(org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse)

Example 2 with GoQuorumReceiveResponse

use of org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse in project besu by hyperledger.

the class GoQuorumBlockProcessor method retrievePrivateTransactionFromEnclave.

private Transaction retrievePrivateTransactionFromEnclave(final Transaction transaction) {
    final GoQuorumReceiveResponse receive = goQuorumEnclave.receive(transaction.getPayload().toBase64String());
    final Bytes privatePayload = Bytes.wrap(receive.getPayload());
    return new Transaction(transaction.getNonce(), transaction.getGasPrice().get(), transaction.getGasLimit(), transaction.getTo(), transaction.getValue(), transaction.getSignature(), privatePayload, transaction.getSender(), // checked again.
    transaction.getChainId(), Optional.of(transaction.getV()));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Transaction(org.hyperledger.besu.ethereum.core.Transaction) GoQuorumReceiveResponse(org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse)

Example 3 with GoQuorumReceiveResponse

use of org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse in project besu by hyperledger.

the class GoQuorumEthGetQuorumPayloadTest method correctRequest.

@Test
public void correctRequest() {
    final String hexString = Bytes.wrap(new byte[64]).toHexString();
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "eth_getQuorumPayload", new String[] { hexString }));
    when(enclave.receive(any())).thenReturn(new GoQuorumReceiveResponse(new byte[10], 0, null, null));
    final JsonRpcResponse response = method.response(request);
    assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
    assertThat(((JsonRpcSuccessResponse) response).getResult().toString()).isEqualTo("0x00000000000000000000");
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) GoQuorumReceiveResponse(org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse) Test(org.junit.Test)

Example 4 with GoQuorumReceiveResponse

use of org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse in project besu by hyperledger.

the class GoQuorumEnclaveTest method sendAndReceive.

@Test
public void sendAndReceive() {
    when(vertxTransmitter.post(any(), any(), any(), any())).thenReturn(new SendResponse(KEY));
    when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/transaction"), any(), anyBoolean())).thenReturn(new GoQuorumReceiveResponse(PAYLOAD, 0, null, null));
    final List<String> publicKeys = Arrays.asList("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
    final SendResponse sr = enclave.send(PAYLOAD, publicKeys.get(0), publicKeys);
    assertThat(sr.getKey()).isEqualTo(KEY);
    final GoQuorumReceiveResponse rr = enclave.receive(sr.getKey());
    assertThat(rr).isNotNull();
    assertThat(rr.getPayload()).isEqualTo(PAYLOAD);
}
Also used : SendResponse(org.hyperledger.besu.enclave.types.SendResponse) GoQuorumReceiveResponse(org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GoQuorumReceiveResponse (org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse)4 Bytes (org.apache.tuweni.bytes.Bytes)2 EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)1 SendResponse (org.hyperledger.besu.enclave.types.SendResponse)1 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)1 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)1 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1