Search in sources :

Example 1 with ConsensusCreateTopicTransactionBody

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

Example 2 with ConsensusCreateTopicTransactionBody

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

the class HapiTopicCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    genKeysFor(spec);
    ConsensusCreateTopicTransactionBody opBody = spec.txns().<ConsensusCreateTopicTransactionBody, ConsensusCreateTopicTransactionBody.Builder>body(ConsensusCreateTopicTransactionBody.class, b -> {
        if (adminKey != null) {
            b.setAdminKey(adminKey);
        }
        topicMemo.ifPresent(b::setMemo);
        submitKey.ifPresent(b::setSubmitKey);
        autoRenewAccountId.ifPresent(id -> b.setAutoRenewAccount(asId(id, spec)));
        autoRenewPeriod.ifPresent(secs -> b.setAutoRenewPeriod(asDuration(secs)));
        if (clearAutoRenewPeriod) {
            b.clearAutoRenewPeriod();
        }
    });
    return b -> b.setConsensusCreateTopic(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Function(java.util.function.Function) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TxnUtils.netOf(com.hedera.services.bdd.spec.transactions.TxnUtils.netOf) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) MoreObjects(com.google.common.base.MoreObjects) TxnUtils.asDuration(com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) 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) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ConsensusCreateTopic(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusCreateTopic) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder)

Aggregations

MoreObjects (com.google.common.base.MoreObjects)2 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)2 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)2 TxnUtils.asDuration (com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration)2 TxnUtils.asId (com.hedera.services.bdd.spec.transactions.TxnUtils.asId)2 CommonUtils (com.hedera.services.legacy.proto.utils.CommonUtils)2 ConsensusCreateTopicTransactionBody (com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)2 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)2 Key (com.hederahashgraph.api.proto.java.Key)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 ConsensusServiceFeeBuilder (com.hederahashgraph.fee.ConsensusServiceFeeBuilder)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 OptionalLong (java.util.OptionalLong)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 ByteString (com.google.protobuf.ByteString)1