use of com.hederahashgraph.api.proto.java.TransactionBody 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.TransactionBody in project hedera-services by hashgraph.
the class HapiCryptoTransfer method toStringHelper.
@Override
protected MoreObjects.ToStringHelper toStringHelper() {
MoreObjects.ToStringHelper helper = super.toStringHelper();
if (txnSubmitted != null) {
try {
TransactionBody txn = CommonUtils.extractTransactionBody(txnSubmitted);
helper.add("transfers", TxnUtils.readableTransferList(txn.getCryptoTransfer().getTransfers()));
helper.add("tokenTransfers", TxnUtils.readableTokenTransfers(txn.getCryptoTransfer().getTokenTransfersList()));
} catch (Exception ignore) {
}
}
return helper;
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.
@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractUpdateAllToExisting(ContractIdType contractIdType) {
// first create the contract
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> c.obtainerId(null));
Contract contract = setupResult.contract;
// now update
Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method assertContractCreateResult.
private void assertContractCreateResult(ContractCreateTransactionBody transactionBody, TransactionRecord record) {
long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
TransactionReceipt receipt = record.getReceipt();
ContractFunctionResult result = record.getContractCreateResult();
ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getInitialBalance(), ContractResult::getAmount).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId).returns(toBytes(transactionBody.getConstructorParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
if (receipt.getStatus() == ResponseCodeEnum.SUCCESS) {
contractResult.returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId);
}
assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractDeleteToNewCreate2EvmAddress.
@Test
void contractDeleteToNewCreate2EvmAddress() {
SetupResult setupResult = setupContract(CONTRACT_ID, ContractIdType.CREATE2_EVM, false, false);
Transaction transaction = contractDeleteTransaction(setupResult.protoContractId, false);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.DELETE);
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(dbTransaction.getEntityId()).isEqualTo(setupResult.contract.toEntityId()));
}
Aggregations