Search in sources :

Example 6 with ContractCallTransactionBody

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

the class SmartContractFeeBuilder method getContractCallBodyTxSize.

/**
 * This method returns total bytes in Contract Call body Transaction
 */
private int getContractCallBodyTxSize(TransactionBody txBody) {
    /*
		 * ContractID contractID - BASIC_ENTITY_ID_SIZE int64 gas - LONG_SIZE int64 amount - LONG_SIZE bytes
		 * functionParameters - calculated value
		 *
		 */
    int contractCallBodySize = BASIC_ACCOUNT_SIZE + LONG_SIZE;
    ContractCallTransactionBody contractCallTxBody = txBody.getContractCall();
    if (contractCallTxBody.getFunctionParameters() != null) {
        contractCallBodySize += contractCallTxBody.getFunctionParameters().size();
    }
    if (contractCallTxBody.getAmount() != 0) {
        contractCallBodySize += LONG_SIZE;
    }
    return contractCallBodySize;
}
Also used : ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody)

Example 7 with ContractCallTransactionBody

use of com.hederahashgraph.api.proto.java.ContractCallTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method assertContractCallResult.

private void assertContractCallResult(ContractCallTransactionBody transactionBody, TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
    ContractFunctionResult result = record.getContractCallResult();
    // get the corresponding entity id from the local cache, fall back to parseContractId if not found.
    ContractID protoContractId = record.getContractCallResult().getContractID();
    EntityId contractId = contractIds.getOrDefault(protoContractId, parseContractId(protoContractId));
    ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getAmount(), ContractResult::getAmount).returns(contractId, ContractResult::getContractId).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(toBytes(transactionBody.getFunctionParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
    assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) DomainUtils.toBytes(com.hedera.mirror.common.util.DomainUtils.toBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteBuffer(java.nio.ByteBuffer) ContractID(com.hederahashgraph.api.proto.java.ContractID) Map(java.util.Map) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Version(org.springframework.data.util.Version) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Collectors(java.util.stream.Collectors) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) STAKEDID_NOT_SET(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) ObjectAssert(org.assertj.core.api.ObjectAssert) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) Value(lombok.Value) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Int32Value(com.google.protobuf.Int32Value) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Assertions(org.junit.jupiter.api.Assertions) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Collections(java.util.Collections) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Aggregations

ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)7 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)6 Transaction (com.hederahashgraph.api.proto.java.Transaction)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 ByteString (com.google.protobuf.ByteString)3 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 Range (com.google.common.collect.Range)2 BytesValue (com.google.protobuf.BytesValue)2 Int32Value (com.google.protobuf.Int32Value)2 StringValue (com.google.protobuf.StringValue)2 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)2 Contract (com.hedera.mirror.common.domain.contract.Contract)2 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)2 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)2 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)2