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