Search in sources :

Example 1 with ContractCallLocalResponse

use of com.hederahashgraph.api.proto.java.ContractCallLocalResponse in project hedera-services by hashgraph.

the class ContractCallLocalResourceUsage method usageFor.

private FeeData usageFor(final Query query, final ResponseType type, final StateView view, @Nullable final Map<String, Object> queryCtx) {
    try {
        final var op = query.getContractCallLocal();
        ContractCallLocalResponse response;
        if (null == queryCtx) {
            response = dummyResponse(op.getContractID());
        } else {
            final var entityAccess = new StaticEntityAccess(view, aliasManager, validator, properties);
            final var codeCache = new CodeCache(nodeProperties, entityAccess);
            final var worldState = new HederaWorldState(ids, entityAccess, codeCache, properties);
            evmTxProcessor.setWorldState(worldState);
            response = CallLocalExecutor.execute(accountStore, evmTxProcessor, op, aliasManager);
            queryCtx.put(CONTRACT_CALL_LOCAL_CTX_KEY, response);
        }
        final var nonGasUsage = usageEstimator.getContractCallLocalFeeMatrices(op.getFunctionParameters().size(), response.getFunctionResult(), type);
        return nonGasUsage.toBuilder().setNodedata(nonGasUsage.getNodedata().toBuilder().setGas(op.getGas())).build();
    } catch (final Exception internal) {
        log.warn("Usage estimation unexpectedly failed for {}!", query, internal);
        throw new IllegalStateException(internal);
    }
}
Also used : CodeCache(com.hedera.services.store.contracts.CodeCache) HederaWorldState(com.hedera.services.store.contracts.HederaWorldState) ContractCallLocalResponse(com.hederahashgraph.api.proto.java.ContractCallLocalResponse) StaticEntityAccess(com.hedera.services.store.contracts.StaticEntityAccess)

Example 2 with ContractCallLocalResponse

use of com.hederahashgraph.api.proto.java.ContractCallLocalResponse in project hedera-services by hashgraph.

the class ContractCallLocalAnswerTest method getsCostAnswerResponse.

@Test
void getsCostAnswerResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee);
    // when:
    Response response = subject.responseGiven(query, view, OK, fee);
    // then:
    assertTrue(response.hasContractCallLocal());
    ContractCallLocalResponse opResponse = response.getContractCallLocal();
    assertEquals(OK, opResponse.getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, opResponse.getHeader().getResponseType());
    assertEquals(fee, opResponse.getHeader().getCost());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) ContractCallLocalResponse(com.hederahashgraph.api.proto.java.ContractCallLocalResponse) Query(com.hederahashgraph.api.proto.java.Query) ContractCallLocalQuery(com.hederahashgraph.api.proto.java.ContractCallLocalQuery) ContractCallLocalResponse(com.hederahashgraph.api.proto.java.ContractCallLocalResponse) Test(org.junit.jupiter.api.Test)

Aggregations

ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)2 CodeCache (com.hedera.services.store.contracts.CodeCache)1 HederaWorldState (com.hedera.services.store.contracts.HederaWorldState)1 StaticEntityAccess (com.hedera.services.store.contracts.StaticEntityAccess)1 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)1 Query (com.hederahashgraph.api.proto.java.Query)1 Response (com.hederahashgraph.api.proto.java.Response)1 Test (org.junit.jupiter.api.Test)1