Search in sources :

Example 1 with SystemUndeleteTransactionBody

use of com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody 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 2 with SystemUndeleteTransactionBody

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

the class HapiSysUndelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (file.isPresent() && contract.isPresent()) {
        Assertions.fail("Ambiguous SystemUndelete---both file and contract present!");
    }
    SystemUndeleteTransactionBody opBody = spec.txns().<SystemUndeleteTransactionBody, SystemUndeleteTransactionBody.Builder>body(SystemUndeleteTransactionBody.class, b -> {
        file.ifPresent(n -> b.setFileID(asFileId(n, spec)));
        contract.ifPresent(n -> b.setContractID(asContractId(n, spec)));
    });
    return b -> b.setSystemUndelete(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TxnUtils.asFileId(com.hedera.services.bdd.spec.transactions.TxnUtils.asFileId) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) Function(java.util.function.Function) Consumer(java.util.function.Consumer) SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnUtils.asContractId(com.hedera.services.bdd.spec.transactions.TxnUtils.asContractId) SystemUndelete(com.hederahashgraph.api.proto.java.HederaFunctionality.SystemUndelete) SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody)

Aggregations

SystemUndeleteTransactionBody (com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody)2 MoreObjects (com.google.common.base.MoreObjects)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils.asContractId (com.hedera.services.bdd.spec.transactions.TxnUtils.asContractId)1 TxnUtils.asFileId (com.hedera.services.bdd.spec.transactions.TxnUtils.asFileId)1 HederaAccountCustomizer (com.hedera.services.ledger.accounts.HederaAccountCustomizer)1 ContractID (com.hederahashgraph.api.proto.java.ContractID)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 SystemUndelete (com.hederahashgraph.api.proto.java.HederaFunctionality.SystemUndelete)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1 TransactionReceipt (com.hederahashgraph.api.proto.java.TransactionReceipt)1 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)1 TransactionResponse (com.hederahashgraph.api.proto.java.TransactionResponse)1 RequestBuilder.getTransactionReceipt (com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt)1 RequestBuilder.getTransactionRecord (com.hederahashgraph.builder.RequestBuilder.getTransactionRecord)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1