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);
}
}
Aggregations