use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult 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);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult in project besu by hyperledger.
the class PrivGetTransactionReceiptTest method transactionReceiptContainsRevertReasonWhenInvalidTransactionOccurs.
@Test
public void transactionReceiptContainsRevertReasonWhenInvalidTransactionOccurs() {
final Transaction pmt = privateMarkerTransaction();
final PrivateTransaction privateTransaction = privateTransactionBesu();
final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(pmt, privateTransaction);
when(privacyController.findPrivateTransactionByPmtHash(eq(pmt.getHash()), any())).thenReturn(Optional.of(executedPrivateTransaction));
final PrivateTransactionReceipt privateTransactionReceiptWithRevertReason = new PrivateTransactionReceipt(1, Collections.emptyList(), Bytes.EMPTY, Optional.of(Bytes.wrap(new byte[] { (byte) 0x01 })));
when(privateStateStorage.getTransactionReceipt(any(Bytes32.class), any(Bytes32.class))).thenReturn(Optional.of(privateTransactionReceiptWithRevertReason));
final JsonRpcRequestContext request = requestContext(pmt.getHash());
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetTransactionReceipt.response(request);
final PrivateTransactionReceiptResult result = (PrivateTransactionReceiptResult) response.getResult();
assertThat(result.getRevertReason()).isEqualTo("0x01");
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult in project besu by hyperledger.
the class PrivGetTransactionReceiptTest method returnReceiptIfBesuTransactionExists.
@Test
public void returnReceiptIfBesuTransactionExists() {
final Transaction pmt = privateMarkerTransaction();
final PrivateTransaction privateTransaction = privateTransactionBesu();
final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(pmt, privateTransaction);
when(privacyController.findPrivateTransactionByPmtHash(eq(pmt.getHash()), any())).thenReturn(Optional.of(executedPrivateTransaction));
final PrivateTransactionReceiptResult expectedResult = privateTransactionReceiptResultFor(privateTransaction, pmt);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetTransactionReceipt.response(requestContext(pmt.getHash()));
final PrivateTransactionReceiptResult result = (PrivateTransactionReceiptResult) response.getResult();
assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult in project besu by hyperledger.
the class PrivGetTransactionReceiptTest method returnReceiptIfLegacyTransactionExists.
@Test
public void returnReceiptIfLegacyTransactionExists() {
final Transaction pmt = privateMarkerTransaction();
final PrivateTransaction legacyPrivateTransaction = privateTransactionLegacy();
final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(pmt, legacyPrivateTransaction);
when(privacyController.findPrivateTransactionByPmtHash(eq(pmt.getHash()), any())).thenReturn(Optional.of(executedPrivateTransaction));
final PrivateTransactionReceiptResult expectedResult = privateTransactionReceiptResultFor(legacyPrivateTransaction, pmt);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetTransactionReceipt.response(requestContext(pmt.getHash()));
final PrivateTransactionReceiptResult result = (PrivateTransactionReceiptResult) response.getResult();
assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult);
}
Aggregations