use of com.hederahashgraph.api.proto.java.SubType in project hedera-services by hashgraph.
the class ScheduleTypePatching method ensurePatchedFeeScheduleHasRequiredTypes.
private void ensurePatchedFeeScheduleHasRequiredTypes(TransactionFeeSchedule origTfs, TransactionFeeSchedule.Builder patchedTfs, Set<SubType> requiredTypes) {
/* The deprecated prices are the final fallback; if even they are not set, the function will be free */
final var oldDefaultPrices = origTfs.getFeeData();
FeeData explicitDefaultPrices = null;
/* First determine what types are already present; and what default prices to use, if any */
final List<SubType> listedTypes = new ArrayList<>();
for (var typedPrices : origTfs.getFeesList()) {
final var type = typedPrices.getSubType();
listedTypes.add(type);
if (type == DEFAULT) {
explicitDefaultPrices = typedPrices;
}
}
final Set<SubType> presentTypes = listedTypes.isEmpty() ? EnumSet.noneOf(SubType.class) : EnumSet.copyOf(listedTypes);
for (var type : requiredTypes) {
if (!presentTypes.contains(type)) {
if (explicitDefaultPrices != null) {
patchedTfs.addFees(explicitDefaultPrices.toBuilder().setSubType(type).build());
} else {
patchedTfs.addFees(oldDefaultPrices.toBuilder().setSubType(type).build());
}
}
}
}
Aggregations