Search in sources :

Example 1 with ExecutedPrivateTransaction

use of org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction 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 ExecutedPrivateTransaction

use of org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction in project besu by hyperledger.

the class PrivGetPrivateTransactionTest method returnsPrivateTransactionLegacy.

@Test
public void returnsPrivateTransactionLegacy() {
    final PrivateTransaction legacyPrivateTransaction = PrivateTransactionDataFixture.privateTransactionLegacy();
    final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(legacyPrivateTransaction);
    when(privacyController.findPrivateTransactionByPmtHash(any(), any())).thenReturn(Optional.of(executedPrivateTransaction));
    final PrivateTransactionLegacyResult expectedResult = new PrivateTransactionLegacyResult(legacyPrivateTransaction);
    final JsonRpcRequestContext request = createRequestContext();
    final PrivateTransactionResult result = makeRequest(request);
    assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateTransactionLegacyResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Test(org.junit.Test)

Example 3 with ExecutedPrivateTransaction

use of org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction 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 4 with ExecutedPrivateTransaction

use of org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction in project besu by hyperledger.

the class PrivGetPrivateTransactionTest method returnsPrivateTransactionGroup.

@Test
public void returnsPrivateTransactionGroup() {
    final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateTransactionBesu();
    final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(privateTransaction);
    when(privacyController.findPrivateTransactionByPmtHash(any(), any())).thenReturn(Optional.of(executedPrivateTransaction));
    final PrivateTransactionGroupResult expectedResult = new PrivateTransactionGroupResult(privateTransaction);
    final JsonRpcRequestContext request = createRequestContext();
    final PrivateTransactionResult result = makeRequest(request);
    assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionGroupResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionGroupResult) Test(org.junit.Test)

Example 5 with ExecutedPrivateTransaction

use of org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction 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)

Aggregations

ExecutedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction)6 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)5 Test (org.junit.Test)5 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)4 PrivateTransactionReceiptResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult)4 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)3 PrivateTransactionDataFixture.privateMarkerTransaction (org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction)3 Transaction (org.hyperledger.besu.ethereum.core.Transaction)3 PrivateTransactionResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult)2 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 PrivateTransactionGroupResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionGroupResult)1 PrivateTransactionLegacyResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult)1