Search in sources :

Example 1 with SubType

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

the class HapiTokenCreate method getTxnSubType.

private SubType getTxnSubType(final TransactionBody txn) {
    final var op = txn.getTokenCreation();
    SubType chosenType;
    final var usesCustomFees = op.hasFeeScheduleKey() || op.getCustomFeesCount() > 0;
    if (op.getTokenType() == NON_FUNGIBLE_UNIQUE) {
        chosenType = usesCustomFees ? TOKEN_NON_FUNGIBLE_UNIQUE_WITH_CUSTOM_FEES : TOKEN_NON_FUNGIBLE_UNIQUE;
    } else {
        chosenType = usesCustomFees ? TOKEN_FUNGIBLE_COMMON_WITH_CUSTOM_FEES : TOKEN_FUNGIBLE_COMMON;
    }
    return chosenType;
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType)

Example 2 with SubType

use of com.hederahashgraph.api.proto.java.SubType 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)

Example 3 with SubType

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

the class BasicFcfsUsagePricesTest method getsTransferUsagePricesAtCurrent.

@Test
void getsTransferUsagePricesAtCurrent() {
    // given:
    subject.loadPriceSchedules();
    Timestamp at = Timestamp.newBuilder().setSeconds(currentExpiry - 1).build();
    // when:
    Map<SubType, FeeData> actual = subject.pricesGiven(ContractCall, at);
    // then:
    assertEquals(currentContractCallPrices, actual);
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FeeData(com.hederahashgraph.api.proto.java.FeeData) Test(org.junit.jupiter.api.Test)

Example 4 with SubType

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

the class BasicFcfsUsagePricesTest method getsTransferUsagePricesPastCurrentBeforeNextExpiry.

@Test
void getsTransferUsagePricesPastCurrentBeforeNextExpiry() throws Exception {
    // given:
    subject.loadPriceSchedules();
    Timestamp at = Timestamp.newBuilder().setSeconds(nextExpiry - 1).build();
    // when:
    Map<SubType, FeeData> actual = subject.pricesGiven(ContractCall, at);
    // then:
    assertEquals(nextContractCallPrices, actual);
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FeeData(com.hederahashgraph.api.proto.java.FeeData) Test(org.junit.jupiter.api.Test)

Example 5 with SubType

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

the class TokenCreateUsage method get.

public FeeData get() {
    int baseSize = TOKEN_OPS_USAGE_UTILS.getTokenTxnBaseSize(op);
    var opTokenCreation = this.op.getTokenCreation();
    var lifetime = opTokenCreation.hasAutoRenewAccount() ? opTokenCreation.getAutoRenewPeriod().getSeconds() : ESTIMATOR_UTILS.relativeLifetime(this.op, opTokenCreation.getExpiry().getSeconds());
    lifetime = Math.min(lifetime, MAX_ENTITY_LIFETIME);
    usageEstimator.addBpt(baseSize);
    final var feeSchedulesSize = opTokenCreation.getCustomFeesCount() > 0 ? tokenOpsUsage.bytesNeededToRepr(opTokenCreation.getCustomFeesList()) : 0;
    usageEstimator.addRbs((baseSize + feeSchedulesSize) * lifetime);
    addNetworkRecordRb(BASIC_ENTITY_ID_SIZE);
    addTokenTransfersRecordRb(1, opTokenCreation.getInitialSupply() > 0 ? 1 : 0, 0);
    SubType chosenType;
    final var usesCustomFees = opTokenCreation.hasFeeScheduleKey() || opTokenCreation.getCustomFeesCount() > 0;
    if (opTokenCreation.getTokenType() == NON_FUNGIBLE_UNIQUE) {
        chosenType = usesCustomFees ? TOKEN_NON_FUNGIBLE_UNIQUE_WITH_CUSTOM_FEES : TOKEN_NON_FUNGIBLE_UNIQUE;
    } else {
        chosenType = usesCustomFees ? TOKEN_FUNGIBLE_COMMON_WITH_CUSTOM_FEES : TOKEN_FUNGIBLE_COMMON;
    }
    return usageEstimator.get(chosenType);
}
Also used : SubType(com.hederahashgraph.api.proto.java.SubType)

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