use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-services by hashgraph.
the class SmartContractFeeBuilder method getContractUpdateStorageBytesSec.
private long getContractUpdateStorageBytesSec(TransactionBody txBody, Timestamp contractExpiryTime) {
long storageSize = 0;
ContractUpdateTransactionBody contractUpdateTxBody = txBody.getContractUpdateInstance();
if (contractUpdateTxBody.hasAdminKey()) {
storageSize += getAccountKeyStorageSize(contractUpdateTxBody.getAdminKey());
}
if (contractUpdateTxBody.getMemo() != null) {
storageSize += contractUpdateTxBody.getMemoBytes().size();
}
Instant expirationTime = RequestBuilder.convertProtoTimeStamp(contractExpiryTime);
Timestamp txValidStartTimestamp = txBody.getTransactionID().getTransactionValidStart();
Instant txValidStartTime = RequestBuilder.convertProtoTimeStamp(txValidStartTimestamp);
Duration duration = Duration.between(txValidStartTime, expirationTime);
long seconds = Math.min(duration.getSeconds(), MAX_ENTITY_LIFETIME);
storageSize = storageSize * seconds;
return storageSize;
}
use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-services by hashgraph.
the class ContractUpdateResourceUsageTest method setup.
@BeforeEach
private void setup() throws Throwable {
contractUpdateTxn = mock(TransactionBody.class);
ContractUpdateTransactionBody update = mock(ContractUpdateTransactionBody.class);
given(update.getContractID()).willReturn(target);
given(contractUpdateTxn.hasContractUpdateInstance()).willReturn(true);
given(contractUpdateTxn.getContractUpdateInstance()).willReturn(update);
nonContractUpdateTxn = mock(TransactionBody.class);
given(nonContractUpdateTxn.hasContractUpdateInstance()).willReturn(false);
account = mock(MerkleAccount.class);
given(account.getExpiry()).willReturn(Long.MAX_VALUE);
accounts = mock(MerkleMap.class);
given(accounts.get(accountKey)).willReturn(account);
view = mock(StateView.class);
given(view.accounts()).willReturn(accounts);
sigUsage = mock(SigValueObj.class);
usageEstimator = mock(SmartContractFeeBuilder.class);
subject = new ContractUpdateResourceUsage(usageEstimator);
}
use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.
@ParameterizedTest
@CsvSource({ "PLAIN, 5005, 5005", "PARSABLE_EVM, 0, 0", "CREATE2_EVM, , 5002" })
void contractUpdateAllToExisting(ContractIdType contractIdType, Long newAutoRenewAccount, Long expectedAutoRenewAccount) {
// first create the contract
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> {
c.obtainerId(null).declineReward(true).stakedAccountId(1L);
if (newAutoRenewAccount == null) {
c.autoRenewAccountId(expectedAutoRenewAccount);
}
});
Contract contract = setupResult.contract;
// now update
Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true, b -> {
if (newAutoRenewAccount != null) {
b.getAutoRenewAccountIdBuilder().setAccountNum(newAutoRenewAccount);
}
});
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(expectedAutoRenewAccount, Contract::getAutoRenewAccountId).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToExisting.
@Test
void contractUpdateAllWithMemoToExisting() {
// first create the contract
EntityId contractId = EntityId.of(CONTRACT_ID);
Contract contract = domainBuilder.contract().customize(c -> c.obtainerId(null).id(contractId.getId()).num(contractId.getEntityNum()).stakedNodeId(1L)).persist();
// now update
Transaction transaction = contractUpdateAllTransaction(false);
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(EntityId.of(CONTRACT_ID)), () -> 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));
}
Aggregations