Search in sources :

Example 1 with ContractID

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

the class BaseHederaLedgerTestHelper method commonSetup.

protected void commonSetup() {
    sideEffectsTracker = mock(SideEffectsTracker.class);
    creator = mock(ExpiringCreations.class);
    historian = mock(AccountRecordsHistorian.class);
    ids = new EntityIdSource() {

        long nextId = NEXT_ID;

        @Override
        public TopicID newTopicId(final AccountID sponsor) {
            return TopicID.newBuilder().setTopicNum(nextId++).build();
        }

        @Override
        public AccountID newAccountId(AccountID newAccountSponsor) {
            return AccountID.newBuilder().setAccountNum(nextId++).build();
        }

        @Override
        public ContractID newContractId(AccountID newContractSponsor) {
            return ContractID.newBuilder().setContractNum(nextId++).build();
        }

        @Override
        public FileID newFileId(AccountID newFileSponsor) {
            return FileID.newBuilder().setFileNum(nextId++).build();
        }

        @Override
        public TokenID newTokenId(AccountID sponsor) {
            return TokenID.newBuilder().setTokenNum(nextId++).build();
        }

        @Override
        public ScheduleID newScheduleId(AccountID sponsor) {
            return ScheduleID.newBuilder().setScheduleNum(nextId++).build();
        }

        @Override
        public void reclaimLastId() {
            nextId--;
        }

        @Override
        public void reclaimProvisionalIds() {
        }

        @Override
        public void resetProvisionalIds() {
        }
    };
}
Also used : EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) TopicID(com.hederahashgraph.api.proto.java.TopicID) FileID(com.hederahashgraph.api.proto.java.FileID) ContractID(com.hederahashgraph.api.proto.java.ContractID) ExpiringCreations(com.hedera.services.state.expiry.ExpiringCreations) TokenID(com.hederahashgraph.api.proto.java.TokenID) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) AccountRecordsHistorian(com.hedera.services.records.AccountRecordsHistorian)

Example 2 with ContractID

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

the class SmartContractRequestHandler method systemUndelete.

/**
 * System account undoes the deletion marker on a smart contract that has been deleted but
 * not yet removed.
 *
 * @param txBody
 * 		API reuest to undelete the contract
 * @param consensusTimestamp
 * 		Platform consensus time
 * @return Details of contract undeletion result
 */
public TransactionRecord systemUndelete(TransactionBody txBody, Instant consensusTimestamp) {
    SystemUndeleteTransactionBody op = txBody.getSystemUndelete();
    ContractID cid = op.getContractID();
    var entity = EntityId.fromGrpcContractId(cid);
    TransactionReceipt receipt = getTransactionReceipt(SUCCESS, exchange.activeRates());
    long oldExpiry = 0;
    try {
        if (entityExpiries.containsKey(entity)) {
            oldExpiry = entityExpiries.get(entity);
        } else {
            receipt = getTransactionReceipt(INVALID_FILE_ID, exchange.activeRates());
        }
        if (oldExpiry > 0) {
            HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(oldExpiry);
            ledger.customizePotentiallyDeleted(asAccount(cid), customizer);
        }
        if (receipt.getStatus() == SUCCESS) {
            try {
                receipt = updateDeleteFlag(cid, false);
            } catch (Exception e) {
                receipt = getTransactionReceipt(FAIL_INVALID, exchange.activeRates());
                if (log.isDebugEnabled()) {
                    log.debug("systemUndelete exception: can't serialize or deserialize! tx= {} {}", txBody, e);
                }
            }
        }
        entityExpiries.remove(entity);
    } catch (Exception e) {
        log.warn("Unhandled exception in SystemUndelete", e);
        log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
        receipt = getTransactionReceipt(FILE_SYSTEM_EXCEPTION, exchange.activeRates());
    }
    TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
    return transactionRecord.build();
}
Also used : SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 3 with ContractID

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

the class SmartContractRequestHandler method systemDelete.

/**
 * System account deletes any contract. This simply marks the contract as deleted.
 *
 * @param txBody
 * 		API request to delete the contract
 * @param consensusTimestamp
 * 		Platform consensus time
 * @return Details of contract deletion result
 */
public TransactionRecord systemDelete(TransactionBody txBody, Instant consensusTimestamp) {
    SystemDeleteTransactionBody op = txBody.getSystemDelete();
    ContractID cid = op.getContractID();
    long newExpiry = op.getExpirationTime().getSeconds();
    TransactionReceipt receipt;
    receipt = updateDeleteFlag(cid, true);
    try {
        if (receipt.getStatus().equals(ResponseCodeEnum.SUCCESS)) {
            AccountID id = asAccount(cid);
            long oldExpiry = ledger.expiry(id);
            var entity = EntityId.fromGrpcContractId(cid);
            entityExpiries.put(entity, oldExpiry);
            HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(newExpiry);
            ledger.customizePotentiallyDeleted(id, customizer);
        }
    } catch (Exception e) {
        log.warn("Unhandled exception in SystemDelete", e);
        log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
        receipt = getTransactionReceipt(ResponseCodeEnum.FILE_SYSTEM_EXCEPTION, exchange.activeRates());
    }
    TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
    return transactionRecord.build();
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 4 with ContractID

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

the class HapiGetContractBytecode method getContractBytecodeQuery.

private Query getContractBytecodeQuery(HapiApiSpec spec, Transaction payment, boolean costOnly) {
    final ContractID resolvedTarget;
    if (contract.length() == HEXED_EVM_ADDRESS_LEN) {
        resolvedTarget = ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(unhex(contract))).build();
    } else {
        resolvedTarget = TxnUtils.asContractId(contract, spec);
    }
    ContractGetBytecodeQuery query = ContractGetBytecodeQuery.newBuilder().setHeader(costOnly ? answerCostHeader(payment) : answerHeader(payment)).setContractID(resolvedTarget).build();
    return Query.newBuilder().setContractGetBytecode(query).build();
}
Also used : ContractGetBytecodeQuery(com.hederahashgraph.api.proto.java.ContractGetBytecodeQuery) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 5 with ContractID

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

the class HapiGetContractInfo method readContractID.

private ContractID readContractID(HapiApiSpec spec) {
    String specExpectationsDir = specScopedDir(spec, validateDirPath);
    try {
        String expectationsDir = specExpectationsDir + "/" + contract;
        File contractIdFile = new File(expectationsDir + "/contractId.txt");
        ByteSource contractIdByteSource = Files.asByteSource(contractIdFile);
        ContractID contractID = ContractID.parseFrom(contractIdByteSource.read());
        return contractID;
    } catch (Exception e) {
        log.error("Something wrong with the expected ContractInfo file", e);
        return null;
    }
}
Also used : ByteSource(com.google.common.io.ByteSource) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID) File(java.io.File)

Aggregations

ContractID (com.hederahashgraph.api.proto.java.ContractID)33 Test (org.junit.jupiter.api.Test)18 EntityId (com.hedera.mirror.common.domain.entity.EntityId)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 AccountID (com.hederahashgraph.api.proto.java.AccountID)9 Contract (com.hedera.mirror.common.domain.contract.Contract)7 Assertions (org.junit.jupiter.api.Assertions)7 ByteString (com.google.protobuf.ByteString)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)6 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Range (com.google.common.collect.Range)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)4 Utility (com.hedera.mirror.importer.util.Utility)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 List (java.util.List)4