Search in sources :

Example 1 with JsonCallParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter in project besu by hyperledger.

the class EthCall method resultByBlockHash.

@Override
protected Object resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) {
    JsonCallParameter callParams = JsonCallParameterUtil.validateAndGetCallParams(request);
    final BlockHeader header = blockchainQueries.get().getBlockHeaderByHash(blockHash).orElse(null);
    if (header == null) {
        return errorResponse(request, BLOCK_NOT_FOUND);
    }
    return transactionSimulator.process(callParams, buildTransactionValidationParams(header, callParams), OperationTracer.NO_TRACING, header).map(result -> result.getValidationResult().either((() -> result.isSuccessful() ? new JsonRpcSuccessResponse(request.getRequest().getId(), result.getOutput().toString()) : errorResponse(request, result)), reason -> new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcErrorConverter.convertTransactionInvalidReason(reason)))).orElse(errorResponse(request, INTERNAL_ERROR));
}
Also used : ValidationResult(org.hyperledger.besu.ethereum.mainnet.ValidationResult) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) BLOCK_NOT_FOUND(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.BLOCK_NOT_FOUND) INTERNAL_ERROR(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INTERNAL_ERROR) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) JsonRpcErrorConverter(org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) BlockParameterOrBlockHash(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash) ImmutableTransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) Hash(org.hyperledger.besu.datatypes.Hash) JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with JsonCallParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter 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 3 with JsonCallParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter in project besu by hyperledger.

the class EthCallTest method shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenGasPriceIsZero.

@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenGasPriceIsZero() {
    JsonCallParameter callParameters = callParameter(Wei.ZERO, null, null);
    internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.empty(), true);
}
Also used : JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) Test(org.junit.Test)

Example 4 with JsonCallParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter in project besu by hyperledger.

the class EthCallTest method shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenFeesAreZero.

@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenFeesAreZero() {
    JsonCallParameter callParameters = callParameter(null, Wei.ZERO, Wei.ZERO);
    internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), true);
}
Also used : JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) Test(org.junit.Test)

Example 5 with JsonCallParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter in project besu by hyperledger.

the class EthCallTest method shouldAutoSelectIsAllowedExeceedingBalanceToFalseWhenGasPriceIsNotZeroAfterEIP1559.

@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToFalseWhenGasPriceIsNotZeroAfterEIP1559() {
    JsonCallParameter callParameters = callParameter(Wei.ONE, null, null);
    internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), false);
}
Also used : JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) Test(org.junit.Test)

Aggregations

JsonCallParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter)41 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)33 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)32 Test (org.junit.jupiter.api.Test)28 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)22 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)13 Test (org.junit.Test)9 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 JsonRpcErrorConverter (org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter)2 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 TransactionSimulatorResult (org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Hash (org.hyperledger.besu.datatypes.Hash)1 Wei (org.hyperledger.besu.datatypes.Wei)1 InvalidJsonRpcParameters (org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters)1 AbstractBlockParameterMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod)1 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)1 BlockParameterOrBlockHash (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash)1 TraceTypeParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter)1