Search in sources :

Example 1 with ContractCreateTransactionBody

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

the class SmartContractFeeBuilder method getContractCreateTransactionBodySize.

/**
 * This method returns total bytes in Contract Create Transaction body
 */
private int getContractCreateTransactionBodySize(TransactionBody txBody) {
    /*
		 * FileID fileID - BASIC_ENTITY_ID_SIZE Key adminKey - calculated value int64 gas - LONG_SIZE uint64
		 * initialBalance - LONG_SIZE AccountID proxyAccountID - BASIC_ENTITY_ID_SIZE bytes
		 * constructorParameters - calculated value Duration autoRenewPeriod - (LONG_SIZE + INT_SIZE)
		 * ShardID shardID - LONG_SIZE RealmID realmID - LONG_SIZE Key newRealmAdminKey - calculated
		 * value string memo - calculated value
		 *
		 */
    ContractCreateTransactionBody contractCreate = txBody.getContractCreateInstance();
    int adminKeySize = 0;
    int proxyAcctID = 0;
    if (contractCreate.hasAdminKey()) {
        adminKeySize = getAccountKeyStorageSize(contractCreate.getAdminKey());
    }
    int newRealmAdminKeySize = 0;
    if (contractCreate.hasNewRealmAdminKey()) {
        newRealmAdminKeySize = getAccountKeyStorageSize(contractCreate.getNewRealmAdminKey());
    }
    int constructParamSize = 0;
    if (contractCreate.getConstructorParameters() != null) {
        constructParamSize = contractCreate.getConstructorParameters().size();
    }
    if (contractCreate.hasProxyAccountID()) {
        proxyAcctID = BASIC_ENTITY_ID_SIZE;
    }
    int memoSize = 0;
    if (contractCreate.getMemo() != null) {
        memoSize = contractCreate.getMemoBytes().size();
    }
    return BASIC_CONTRACT_CREATE_SIZE + adminKeySize + proxyAcctID + constructParamSize + newRealmAdminKeySize + memoSize;
}
Also used : ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)

Example 2 with ContractCreateTransactionBody

use of com.hederahashgraph.api.proto.java.ContractCreateTransactionBody 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());
}
Also used : 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) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt)

Example 3 with ContractCreateTransactionBody

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

the class HapiContractCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (!omitAdminKey && !useDeprecatedAdminKey) {
        generateAdminKey(spec);
    }
    if (bytecodeFileFn.isPresent()) {
        bytecodeFile = Optional.of(bytecodeFileFn.get().get());
    }
    if (!bytecodeFile.isPresent()) {
        setBytecodeToDefaultContract(spec);
    }
    Optional<byte[]> params;
    if (explicitHexedParams.isPresent()) {
        params = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex);
    } else {
        params = abi.isPresent() ? Optional.of(CallTransaction.Function.fromJsonInterface(abi.get()).encodeArguments(args.get())) : Optional.empty();
    }
    FileID bytecodeFileId = TxnUtils.asFileId(bytecodeFile.get(), spec);
    ContractCreateTransactionBody opBody = spec.txns().<ContractCreateTransactionBody, ContractCreateTransactionBody.Builder>body(ContractCreateTransactionBody.class, b -> {
        if (useDeprecatedAdminKey) {
            b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
        } else if (!omitAdminKey) {
            b.setAdminKey(adminKey);
        }
        b.setFileID(bytecodeFileId);
        autoRenewPeriodSecs.ifPresent(p -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p).build()));
        balance.ifPresent(b::setInitialBalance);
        memo.ifPresent(b::setMemo);
        gas.ifPresent(b::setGas);
        proxy.ifPresent(p -> b.setProxyAccountID(asId(p, spec)));
        params.ifPresent(bytes -> b.setConstructorParameters(ByteString.copyFrom(bytes)));
    });
    return b -> b.setContractCreateInstance(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiFileCreate(com.hedera.services.bdd.spec.transactions.file.HapiFileCreate) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) ContractGetInfoResponse(com.hederahashgraph.api.proto.java.ContractGetInfoResponse) CallTransaction(org.ethereum.core.CallTransaction) HapiContractCall.doGasLookup(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.doGasLookup) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) HapiSpecRegistry(com.hedera.services.bdd.spec.infrastructure.HapiSpecRegistry) TxnVerbs(com.hedera.services.bdd.spec.transactions.TxnVerbs) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TxnUtils.solidityIdFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.solidityIdFrom) FileID(com.hederahashgraph.api.proto.java.FileID) TxnUtils.equivAccount(com.hedera.services.bdd.spec.transactions.TxnUtils.equivAccount) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) KeyGenerator(com.hedera.services.bdd.spec.keys.KeyGenerator) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) CommonUtils(com.swirlds.common.CommonUtils) ObjLongConsumer(java.util.function.ObjLongConsumer) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Supplier(java.util.function.Supplier) FileID(com.hederahashgraph.api.proto.java.FileID)

Aggregations

ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)3 ByteString (com.google.protobuf.ByteString)2 ContractID (com.hederahashgraph.api.proto.java.ContractID)2 Duration (com.hederahashgraph.api.proto.java.Duration)2 FileID (com.hederahashgraph.api.proto.java.FileID)2 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 MoreObjects (com.google.common.base.MoreObjects)1 Range (com.google.common.collect.Range)1 BytesValue (com.google.protobuf.BytesValue)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1