Search in sources :

Example 1 with TokenInfo

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

the class HapiTokenUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final TokenInfo info = HapiTokenFeeScheduleUpdate.lookupInfo(spec, token, log, loggingOff);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
            var estimate = TokenUpdateUsage.newEstimate(_txn, suFrom(svo));
            estimate.givenCurrentExpiry(info.getExpiry().getSeconds()).givenCurrentMemo(info.getMemo()).givenCurrentName(info.getName()).givenCurrentSymbol(info.getSymbol());
            if (info.hasFreezeKey()) {
                estimate.givenCurrentFreezeKey(Optional.of(info.getFreezeKey()));
            }
            if (info.hasAdminKey()) {
                estimate.givenCurrentAdminKey(Optional.of(info.getAdminKey()));
            }
            if (info.hasSupplyKey()) {
                estimate.givenCurrentSupplyKey(Optional.of(info.getSupplyKey()));
            }
            if (info.hasKycKey()) {
                estimate.givenCurrentKycKey(Optional.of(info.getKycKey()));
            }
            if (info.hasWipeKey()) {
                estimate.givenCurrentWipeKey(Optional.of(info.getWipeKey()));
            }
            if (info.hasFeeScheduleKey()) {
                estimate.givenCurrentFeeScheduleKey(Optional.of(info.getFeeScheduleKey()));
            }
            if (info.hasPauseKey()) {
                estimate.givenCurrentPauseKey(Optional.of(info.getPauseKey()));
            }
            if (info.hasAutoRenewAccount()) {
                estimate.givenCurrentlyUsingAutoRenewAccount();
            }
            return estimate.get();
        };
        return spec.fees().forActivityBasedOp(HederaFunctionality.TokenUpdate, metricsCalc, txn, numPayerKeys);
    } catch (Throwable t) {
        log.warn("Couldn't estimate usage", t);
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TokenUpdateUsage(com.hedera.services.usage.token.TokenUpdateUsage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo)

Example 2 with TokenInfo

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

the class HapiTokenFeeScheduleUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final TokenInfo info = lookupInfo(spec, token, log, loggingOff);
        final FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> usageEstimate(_txn, svo, info);
        return spec.fees().forActivityBasedOp(TokenFeeScheduleUpdate, metricsCalc, txn, numPayerKeys);
    } catch (Throwable ignore) {
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : FeeScheduleUpdateMeta(com.hedera.services.usage.token.meta.FeeScheduleUpdateMeta) Transaction(com.hederahashgraph.api.proto.java.Transaction) TokenFeeScheduleUpdate(com.hederahashgraph.api.proto.java.HederaFunctionality.TokenFeeScheduleUpdate) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) ExtantFeeScheduleContext(com.hedera.services.usage.token.meta.ExtantFeeScheduleContext) Function(java.util.function.Function) HapiGetTokenInfo(com.hedera.services.bdd.spec.queries.token.HapiGetTokenInfo) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) CustomFee(com.hederahashgraph.api.proto.java.CustomFee) TokenOpsUsage(com.hedera.services.usage.token.TokenOpsUsage) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) HapiGetTokenInfo(com.hedera.services.bdd.spec.queries.token.HapiGetTokenInfo) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo)

Aggregations

MoreObjects (com.google.common.base.MoreObjects)2 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)2 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)2 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)2 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)2 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)2 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)2 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)2 Key (com.hederahashgraph.api.proto.java.Key)2 TokenInfo (com.hederahashgraph.api.proto.java.TokenInfo)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 TransactionResponse (com.hederahashgraph.api.proto.java.TransactionResponse)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2