Search in sources :

Example 6 with SubType

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());
            }
        }
    }
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType) ArrayList(java.util.ArrayList) FeeData(com.hederahashgraph.api.proto.java.FeeData)

Aggregations

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