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