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