Search in sources :

Example 1 with EnclaveClientException

use of org.hyperledger.besu.enclave.EnclaveClientException in project besu by hyperledger.

the class PrivateTransactionLocatorTest method mockEnlaveNoSingleTxOrAddBlob.

/*
   Overrride enclave so it returns 404 when searching for a single tx (first call) and when
   searching for the add blob (second call)
  */
private void mockEnlaveNoSingleTxOrAddBlob() {
    final EnclaveClientException payloadNotFoundException = new EnclaveClientException(404, "Payload not found");
    when(enclave.receive(anyString(), eq(participantKey))).thenThrow(payloadNotFoundException).thenThrow(payloadNotFoundException);
}
Also used : EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException)

Example 2 with EnclaveClientException

use of org.hyperledger.besu.enclave.EnclaveClientException in project besu by hyperledger.

the class PrivateTransactionLocatorTest method mockEnclaveForNonExistingPayload.

private void mockEnclaveForNonExistingPayload(final Transaction pmt) {
    final String privateTransactionLookupId = pmt.getData().orElseThrow().toBase64String();
    final EnclaveClientException payloadNotFoundException = new EnclaveClientException(404, "Payload not found");
    when(enclave.receive(eq(privateTransactionLookupId), eq(participantKey))).thenThrow(payloadNotFoundException);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException)

Example 3 with EnclaveClientException

use of org.hyperledger.besu.enclave.EnclaveClientException 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 4 with EnclaveClientException

use of org.hyperledger.besu.enclave.EnclaveClientException in project besu by hyperledger.

the class PrivGetPrivateTransaction method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    LOG.trace("Executing {}", RpcMethod.PRIV_GET_PRIVATE_TRANSACTION.getMethodName());
    final Hash hash = requestContext.getRequiredParameter(0, Hash.class);
    final String enclaveKey = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
    final Optional<PrivateTransaction> maybePrivateTx;
    try {
        maybePrivateTx = privacyController.findPrivateTransactionByPmtHash(hash, enclaveKey).map(PrivateTransaction.class::cast);
    } catch (EnclaveClientException e) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason(e.getMessage()));
    }
    return maybePrivateTx.map(this::mapTransactionResult).map(result -> new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result)).orElse(new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivateTransactionLegacyResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult) PrivacyController(org.hyperledger.besu.ethereum.privacy.PrivacyController) Logger(org.slf4j.Logger) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) LoggerFactory(org.slf4j.LoggerFactory) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException) JsonRpcEnclaveErrorConverter(org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcEnclaveErrorConverter) PrivateTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) PrivacyIdProvider(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Optional(java.util.Optional) PrivateTransactionGroupResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionGroupResult) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) Hash(org.hyperledger.besu.datatypes.Hash) Hash(org.hyperledger.besu.datatypes.Hash) 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)

Example 5 with EnclaveClientException

use of org.hyperledger.besu.enclave.EnclaveClientException in project besu by hyperledger.

the class PrivGetTransactionReceipt method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    LOG.trace("Executing {}", RpcMethod.PRIV_GET_TRANSACTION_RECEIPT.getMethodName());
    final Hash pmtTransactionHash = requestContext.getRequiredParameter(0, Hash.class);
    final String enclaveKey = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
    final ExecutedPrivateTransaction privateTransaction;
    try {
        privateTransaction = privacyController.findPrivateTransactionByPmtHash(pmtTransactionHash, enclaveKey).orElse(null);
    } catch (final EnclaveClientException e) {
        return handleEnclaveException(requestContext, e);
    }
    if (privateTransaction == null) {
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null);
    }
    final String contractAddress = calculateContractAddress(privateTransaction);
    LOG.trace("Calculated contractAddress: {}", contractAddress);
    final Hash blockHash = privateTransaction.getBlockHash();
    final PrivateTransactionReceipt privateTransactionReceipt = privateStateStorage.getTransactionReceipt(blockHash, pmtTransactionHash).or(() -> findPrivateReceiptByPrivateTxHash(privateStateStorage, blockHash, privateTransaction)).orElse(PrivateTransactionReceipt.FAILED);
    LOG.trace("Processed private transaction receipt");
    final PrivateTransactionReceiptResult result = buildPrivateTransactionReceiptResult(privateTransaction, privateTransactionReceipt);
    LOG.trace("Created Private Transaction Receipt Result from given Transaction Hash {}", privateTransaction.getPmtHash());
    return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);
}
Also used : PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException)

Aggregations

EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)18 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)8 Test (org.junit.Test)7 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)6 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)5 Optional (java.util.Optional)4 Bytes (org.apache.tuweni.bytes.Bytes)4 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Hash (org.hyperledger.besu.datatypes.Hash)3 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)3 Collections (java.util.Collections)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 Address (org.hyperledger.besu.datatypes.Address)2 EnclaveIOException (org.hyperledger.besu.enclave.EnclaveIOException)2 EnclaveServerException (org.hyperledger.besu.enclave.EnclaveServerException)2 GoQuorumReceiveResponse (org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse)2