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