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);
}
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);
}
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);
}
}
}
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));
}
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);
}
Aggregations