Search in sources :

Example 1 with ContractUpdateTransactionBody

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

the class HapiContractUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    Optional<Key> key = newKey.map(spec.registry()::getKey);
    ContractUpdateTransactionBody opBody = spec.txns().<ContractUpdateTransactionBody, ContractUpdateTransactionBody.Builder>body(ContractUpdateTransactionBody.class, b -> {
        if (contract.length() == HEXED_EVM_ADDRESS_LEN) {
            b.setContractID(ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(CommonUtils.unhex(contract))));
        } else {
            b.setContractID(TxnUtils.asContractId(contract, spec));
        }
        if (useDeprecatedAdminKey) {
            b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
        } else if (wipeToThresholdKey) {
            b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else if (useEmptyAdminKeyList) {
            b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
        } else {
            key.ifPresent(b::setAdminKey);
        }
        newExpirySecs.ifPresent(t -> b.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
        newMemo.ifPresent(s -> {
            if (useDeprecatedMemoField) {
                b.setMemo(s);
            } else {
                b.setMemoWrapper(StringValue.newBuilder().setValue(s).build());
            }
        });
        newAutoRenew.ifPresent(autoRenew -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(autoRenew).build()));
        bytecode.ifPresent(f -> b.setFileID(TxnUtils.asFileId(bytecode.get(), spec)).build());
    });
    return builder -> builder.setContractUpdateInstance(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) HEXED_EVM_ADDRESS_LEN(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.HEXED_EVM_ADDRESS_LEN) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CommonUtils(com.swirlds.common.CommonUtils) DEPRECATED_CID_ADMIN_KEY(com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate.DEPRECATED_CID_ADMIN_KEY) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Key(com.hederahashgraph.api.proto.java.Key)

Example 2 with ContractUpdateTransactionBody

use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody 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));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) ContractDeleteTransactionBody(com.hederahashgraph.api.proto.java.ContractDeleteTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ContractUpdateTransactionBody

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

the class EntityRecordItemListenerContractTest method contractUpdateAllToNew.

@ParameterizedTest
@EnumSource(value = ContractIdType.class, names = { "PLAIN", "PARSABLE_EVM" })
void contractUpdateAllToNew(ContractIdType contractIdType) {
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, false, false, c -> c.obtainerId(null));
    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(null, Contract::getCreatedTimestamp).returns(null, // FileId is ignored on updates by HAPI
    Contract::getFileId));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ContractUpdateTransactionBody

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

the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToNew.

@Test
void contractUpdateAllWithMemoToNew() {
    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(null, Contract::getCreatedTimestamp).returns(null, // FileId is ignored on updates by HAPI
    Contract::getFileId));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ContractUpdateTransactionBody

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

the class SmartContractFeeBuilder method getContractUpdateBodyTxSize.

/**
 * This method returns total bytes in Contract Update Transaction
 */
private int getContractUpdateBodyTxSize(TransactionBody txBody) {
    /*
		 * ContractID contractID - BASIC_ENTITY_ID_SIZE Timestamp expirationTime - LONG_SIZE + INT_SIZE
		 * AccountID proxyAccountID - BASIC_ENTITY_ID_SIZE Duration autoRenewPeriod - LONG_SIZE + INT_SIZE
		 * FileID fileID - BASIC_ENTITY_ID_SIZE Key adminKey - calculated value string memo - calculated value
		 */
    int contractUpdateBodySize = BASIC_ENTITY_ID_SIZE;
    ContractUpdateTransactionBody contractUpdateTxBody = txBody.getContractUpdateInstance();
    if (contractUpdateTxBody.hasProxyAccountID()) {
        contractUpdateBodySize += BASIC_ENTITY_ID_SIZE;
    }
    if (contractUpdateTxBody.hasFileID()) {
        contractUpdateBodySize += BASIC_ENTITY_ID_SIZE;
    }
    if (contractUpdateTxBody.hasExpirationTime()) {
        contractUpdateBodySize += (LONG_SIZE);
    }
    if (contractUpdateTxBody.hasAutoRenewPeriod()) {
        contractUpdateBodySize += (LONG_SIZE);
    }
    if (contractUpdateTxBody.hasAdminKey()) {
        contractUpdateBodySize += getAccountKeyStorageSize(contractUpdateTxBody.getAdminKey());
    }
    if (contractUpdateTxBody.getMemo() != null) {
        contractUpdateBodySize += contractUpdateTxBody.getMemoBytes().size();
    }
    return contractUpdateBodySize;
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)

Aggregations

ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)9 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)7 Transaction (com.hederahashgraph.api.proto.java.Transaction)6 Contract (com.hedera.mirror.common.domain.contract.Contract)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)5 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)3 ByteString (com.google.protobuf.ByteString)2 StringValue (com.google.protobuf.StringValue)2 ContractID (com.hederahashgraph.api.proto.java.ContractID)2 Duration (com.hederahashgraph.api.proto.java.Duration)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 MoreObjects (com.google.common.base.MoreObjects)1 Range (com.google.common.collect.Range)1 BytesValue (com.google.protobuf.BytesValue)1