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