Search in sources :

Example 1 with CallParameter

use of org.hyperledger.besu.ethereum.transaction.CallParameter in project besu by hyperledger.

the class ValidatorContractController method callFunction.

private Optional<TransactionSimulatorResult> callFunction(final long blockNumber, final Function function, final Address contractAddress) {
    final Bytes payload = Bytes.fromHexString(FunctionEncoder.encode(function));
    final CallParameter callParams = new CallParameter(null, contractAddress, -1, null, null, payload);
    return transactionSimulator.process(callParams, blockNumber);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter)

Example 2 with CallParameter

use of org.hyperledger.besu.ethereum.transaction.CallParameter in project besu by hyperledger.

the class MultiTenancyPrivacyControllerOnchainTest method simulatePrivateTransactionSucceedsForPresentEnclaveKey.

@Test
public void simulatePrivateTransactionSucceedsForPresentEnclaveKey() {
    when(privacyController.simulatePrivateTransaction(any(), any(), any(), any(long.class))).thenReturn(Optional.of(TransactionProcessingResult.successful(LOGS, 0, 0, Bytes.EMPTY, ValidationResult.valid())));
    final Optional<TransactionProcessingResult> result = multiTenancyPrivacyController.simulatePrivateTransaction(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1, new CallParameter(Address.ZERO, Address.ZERO, 0, Wei.ZERO, Wei.ZERO, Bytes.EMPTY), 1);
    assertThat(result.isPresent()).isTrue();
    assertThat(result.get().getValidationResult().isValid()).isTrue();
}
Also used : CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 3 with CallParameter

use of org.hyperledger.besu.ethereum.transaction.CallParameter in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method simulatePrivateTransactionWorksForValidEnclaveKey.

@Test
public void simulatePrivateTransactionWorksForValidEnclaveKey() {
    when(privacyController.simulatePrivateTransaction(any(), any(), any(), any(long.class))).thenReturn(Optional.of(TransactionProcessingResult.successful(LOGS, 0, 0, Bytes.EMPTY, ValidationResult.valid())));
    final Optional<TransactionProcessingResult> result = multiTenancyPrivacyController.simulatePrivateTransaction(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1, new CallParameter(Address.ZERO, Address.ZERO, 0, Wei.ZERO, Wei.ZERO, Bytes.EMPTY), 1);
    assertThat(result).isPresent();
    assertThat(result.get().getValidationResult().isValid()).isTrue();
}
Also used : CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 4 with CallParameter

use of org.hyperledger.besu.ethereum.transaction.CallParameter in project besu by hyperledger.

the class EthEstimateGas method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final JsonCallParameter callParams = validateAndGetCallParams(requestContext);
    final BlockHeader blockHeader = blockHeader();
    if (blockHeader == null) {
        return errorResponse(requestContext, JsonRpcError.INTERNAL_ERROR);
    }
    if (!blockchainQueries.getWorldStateArchive().isWorldStateAvailable(blockHeader.getStateRoot(), blockHeader.getHash())) {
        return errorResponse(requestContext, JsonRpcError.WORLD_STATE_UNAVAILABLE);
    }
    final CallParameter modifiedCallParams = overrideGasLimitAndPrice(callParams, blockHeader.getGasLimit());
    final EstimateGasOperationTracer operationTracer = new EstimateGasOperationTracer();
    return transactionSimulator.process(modifiedCallParams, ImmutableTransactionValidationParams.builder().from(TransactionValidationParams.transactionSimulator()).isAllowExceedingBalance(!callParams.isMaybeStrict().orElse(Boolean.FALSE)).build(), operationTracer, blockHeader.getNumber()).map(gasEstimateResponse(requestContext, operationTracer)).orElse(errorResponse(requestContext, JsonRpcError.INTERNAL_ERROR));
}
Also used : JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) EstimateGasOperationTracer(org.hyperledger.besu.evm.tracing.EstimateGasOperationTracer) JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 5 with CallParameter

use of org.hyperledger.besu.ethereum.transaction.CallParameter in project besu by hyperledger.

the class BlockAdapterBase method executeCall.

private Optional<CallResult> executeCall(final DataFetchingEnvironment environment) {
    final Map<String, Object> callData = environment.getArgument("data");
    final Address from = (Address) callData.get("from");
    final Address to = (Address) callData.get("to");
    final Long gas = (Long) callData.get("gas");
    final UInt256 gasPrice = (UInt256) callData.get("gasPrice");
    final UInt256 value = (UInt256) callData.get("value");
    final Bytes data = (Bytes) callData.get("data");
    final BlockchainQueries query = getBlockchainQueries(environment);
    final ProtocolSchedule protocolSchedule = environment.getGraphQlContext().get(GraphQLContextType.PROTOCOL_SCHEDULE);
    final long bn = header.getNumber();
    final TransactionSimulator transactionSimulator = new TransactionSimulator(query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule);
    long gasParam = -1;
    Wei gasPriceParam = null;
    Wei valueParam = null;
    if (gas != null) {
        gasParam = gas;
    }
    if (gasPrice != null) {
        gasPriceParam = Wei.of(gasPrice);
    }
    if (value != null) {
        valueParam = Wei.of(value);
    }
    final CallParameter param = new CallParameter(from, to, gasParam, gasPriceParam, valueParam, data);
    final Optional<TransactionSimulatorResult> opt = transactionSimulator.process(param, TransactionValidationParams.transactionSimulator(), OperationTracer.NO_TRACING, bn);
    if (opt.isPresent()) {
        final TransactionSimulatorResult result = opt.get();
        long status = 0;
        if (result.isSuccessful()) {
            status = 1;
        }
        final CallResult callResult = new CallResult(status, result.getGasEstimate(), result.getOutput());
        return Optional.of(callResult);
    }
    return Optional.empty();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Bytes(org.apache.tuweni.bytes.Bytes) TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Wei(org.hyperledger.besu.datatypes.Wei) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) UInt256(org.apache.tuweni.units.bigints.UInt256)

Aggregations

CallParameter (org.hyperledger.besu.ethereum.transaction.CallParameter)12 Bytes (org.apache.tuweni.bytes.Bytes)6 Address (org.hyperledger.besu.datatypes.Address)5 Test (org.junit.Test)5 TransactionSimulator (org.hyperledger.besu.ethereum.transaction.TransactionSimulator)4 TransactionSimulatorResult (org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult)4 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)3 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Optional (java.util.Optional)2 UInt256 (org.apache.tuweni.units.bigints.UInt256)2 Hash (org.hyperledger.besu.crypto.Hash)2 Wei (org.hyperledger.besu.datatypes.Wei)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)2 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 InetAddress (java.net.InetAddress)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 BaseUInt256Value (org.apache.tuweni.units.bigints.BaseUInt256Value)1