Search in sources :

Example 1 with PrivateTransactionReceiptResult

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

Example 2 with PrivateTransactionReceiptResult

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");
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.Test)

Example 3 with PrivateTransactionReceiptResult

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);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 4 with PrivateTransactionReceiptResult

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);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Aggregations

JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)4 PrivateTransactionReceiptResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult)4 ExecutedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction)4 PrivateTransactionDataFixture.privateMarkerTransaction (org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction)3 Transaction (org.hyperledger.besu.ethereum.core.Transaction)3 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)3 Test (org.junit.Test)3 PrivateTransactionReceipt (org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Hash (org.hyperledger.besu.datatypes.Hash)1 EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)1 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1