Search in sources :

Example 1 with ConsensusUpdateTopic

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

the class HapiTopicUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    if (!spec.registry().hasTopicMeta(topic)) {
        return spec.fees().maxFeeTinyBars();
    } else {
        /* Lookup topic metadata saved during creation. */
        long oldExpiry = spec.registry().getTopicExpiry(topic);
        ConsensusCreateTopicTransactionBody oldMeta = spec.registry().getTopicMeta(topic);
        /* Computed the increase in RBS due to this update. */
        long tentativeRbsIncrease = 0;
        try {
            TransactionBody updateTxn = CommonUtils.extractTransactionBody(txn);
            tentativeRbsIncrease = ConsensusServiceFeeBuilder.getUpdateTopicRbsIncrease(updateTxn.getTransactionID().getTransactionValidStart(), oldMeta.getAdminKey(), oldMeta.getSubmitKey(), oldMeta.getMemo(), oldMeta.hasAutoRenewAccount(), Timestamp.newBuilder().setSeconds(oldExpiry).build(), updateTxn.getConsensusUpdateTopic());
        } catch (Exception impossible) {
            throw new IllegalStateException(impossible);
        }
        /* Create a custom activity metrics calculator based on the rbsIncrease. */
        final long rbsIncrease = tentativeRbsIncrease;
        FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> ConsensusServiceFeeBuilder.getConsensusUpdateTopicFee(txBody, rbsIncrease, sigUsage);
        /* Return the net fee. */
        return spec.fees().forActivityBasedOp(ConsensusUpdateTopic, metricsCalc, txn, numPayerKeys);
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) EMPTY_KEY(com.hedera.services.bdd.suites.HapiApiSuite.EMPTY_KEY) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConsensusUpdateTopic(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusUpdateTopic) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) TxnUtils.asTopicId(com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TxnUtils.asTimestamp(com.hedera.services.bdd.spec.transactions.TxnUtils.asTimestamp) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MoreObjects(com.google.common.base.MoreObjects) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) TxnUtils.asDuration(com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration) Consumer(java.util.function.Consumer) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)

Aggregations

MoreObjects (com.google.common.base.MoreObjects)1 StringValue (com.google.protobuf.StringValue)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils.asDuration (com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration)1 TxnUtils.asId (com.hedera.services.bdd.spec.transactions.TxnUtils.asId)1 TxnUtils.asTimestamp (com.hedera.services.bdd.spec.transactions.TxnUtils.asTimestamp)1 TxnUtils.asTopicId (com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId)1 EMPTY_KEY (com.hedera.services.bdd.suites.HapiApiSuite.EMPTY_KEY)1 CommonUtils (com.hedera.services.legacy.proto.utils.CommonUtils)1 ConsensusCreateTopicTransactionBody (com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)1 ConsensusUpdateTopicTransactionBody (com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 ConsensusUpdateTopic (com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusUpdateTopic)1 Key (com.hederahashgraph.api.proto.java.Key)1 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)1 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1