Search in sources :

Example 1 with FeeData

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

the class ContractUpdateResourceUsageTest method returnsDefaultUsageOnException.

@Test
void returnsDefaultUsageOnException() throws Exception {
    // when:
    FeeData actual = subject.usageGiven(contractUpdateTxn, sigUsage, null);
    // then:
    assertEquals(FeeData.getDefaultInstance(), actual);
}
Also used : FeeData(com.hederahashgraph.api.proto.java.FeeData) Test(org.junit.jupiter.api.Test)

Example 2 with FeeData

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

the class ScheduleEntryPojo method from.

public static ScheduleEntryPojo from(TransactionFeeSchedule grpc) {
    var pojo = new ScheduleEntryPojo();
    pojo.setHederaFunctionality(grpc.getHederaFunctionality().toString());
    List<ScopedResourcePricesPojo> feesList = new ArrayList<>();
    for (FeeData feeData : grpc.getFeesList()) {
        var subType = feeData.getSubType();
        var nodePrices = ResourcePricesPojo.from(feeData.getNodedata());
        var servicePrices = ResourcePricesPojo.from(feeData.getServicedata());
        var networkPrices = ResourcePricesPojo.from(feeData.getNetworkdata());
        var scopedPrices = new ScopedResourcePricesPojo();
        scopedPrices.setNodedata(nodePrices);
        scopedPrices.setNetworkdata(networkPrices);
        scopedPrices.setServicedata(servicePrices);
        scopedPrices.setSubType(subType);
        feesList.add(scopedPrices);
    }
    pojo.setFees(feesList);
    return pojo;
}
Also used : ArrayList(java.util.ArrayList) FeeData(com.hederahashgraph.api.proto.java.FeeData)

Example 3 with FeeData

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

the class GasCalculatorHederaUtil method ramByteHoursTinyBarsGiven.

public static long ramByteHoursTinyBarsGiven(final UsagePricesProvider usagePrices, final HbarCentExchange exchange, long consensusTime, HederaFunctionality functionType) {
    final var timestamp = Timestamp.newBuilder().setSeconds(consensusTime).build();
    FeeData prices = usagePrices.defaultPricesGiven(functionType, timestamp);
    long feeInTinyCents = prices.getServicedata().getRbh() / 1000;
    long feeInTinyBars = FeeBuilder.getTinybarsFromTinyCents(exchange.rate(timestamp), feeInTinyCents);
    return Math.max(1L, feeInTinyBars);
}
Also used : FeeData(com.hederahashgraph.api.proto.java.FeeData)

Example 4 with FeeData

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

the class BasicFcfsUsagePrices method ensurePricesMapHasRequiredTypes.

void ensurePricesMapHasRequiredTypes(final TransactionFeeSchedule tfs, final Map<SubType, FeeData> pricesMap, final Set<SubType> requiredTypes) {
    /* The deprecated prices are the final fallback; if even they are not set, the function will be free */
    final var oldDefaultPrices = tfs.getFeeData();
    FeeData newDefaultPrices = null;
    for (var typedPrices : tfs.getFeesList()) {
        final var type = typedPrices.getSubType();
        if (requiredTypes.contains(type)) {
            pricesMap.put(type, typedPrices);
        }
        if (type == DEFAULT) {
            newDefaultPrices = typedPrices;
        }
    }
    for (var type : requiredTypes) {
        if (!pricesMap.containsKey(type)) {
            if (newDefaultPrices != null) {
                pricesMap.put(type, newDefaultPrices.toBuilder().setSubType(type).build());
            } else {
                pricesMap.put(type, oldDefaultPrices.toBuilder().setSubType(type).build());
            }
        }
    }
}
Also used : FeeData(com.hederahashgraph.api.proto.java.FeeData)

Example 5 with FeeData

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

the class BasicFcfsUsagePricesTest method returnsDefaultUsagePricesForUnsupported.

@Test
void returnsDefaultUsagePricesForUnsupported() {
    // setup:
    MockAppender mockAppender = new MockAppender();
    var log = (org.apache.logging.log4j.core.Logger) LogManager.getLogger(BasicFcfsUsagePrices.class);
    log.addAppender(mockAppender);
    Level levelForReset = log.getLevel();
    log.setLevel(Level.DEBUG);
    // given:
    subject.loadPriceSchedules();
    Timestamp at = Timestamp.newBuilder().setSeconds(currentExpiry - 1).build();
    // when:
    Map<SubType, FeeData> actual = subject.pricesGiven(UNRECOGNIZED, at);
    // then:
    assertEquals(DEFAULT_RESOURCE_PRICES, actual);
    assertEquals(1, mockAppender.size());
    assertEquals("DEBUG - Default usage price will be used, no specific usage prices available for function " + "UNRECOGNIZED" + " @ 1970-01-15T06:56:06Z!", mockAppender.get(0));
    // tearDown:
    log.setLevel(levelForReset);
    log.removeAppender(mockAppender);
    mockAppender.clear();
}
Also used : MockAppender(com.hedera.test.mocks.MockAppender) SubType(com.hederahashgraph.api.proto.java.SubType) Level(org.apache.logging.log4j.Level) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FeeData(com.hederahashgraph.api.proto.java.FeeData) Test(org.junit.jupiter.api.Test)

Aggregations

FeeData (com.hederahashgraph.api.proto.java.FeeData)10 SubType (com.hederahashgraph.api.proto.java.SubType)4 Test (org.junit.jupiter.api.Test)4 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)3 ArrayList (java.util.ArrayList)2 MockAppender (com.hedera.test.mocks.MockAppender)1 HashMap (java.util.HashMap)1 Level (org.apache.logging.log4j.Level)1