Search in sources :

Example 1 with SystemDeleteTransactionBody

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

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

the class HapiSysDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (file.isPresent() && contract.isPresent()) {
        Assertions.fail("Ambiguous SystemDelete---both file and contract present!");
    }
    SystemDeleteTransactionBody opBody = spec.txns().<SystemDeleteTransactionBody, SystemDeleteTransactionBody.Builder>body(SystemDeleteTransactionBody.class, b -> {
        newExpiry.ifPresent(l -> b.setExpirationTime(TimestampSeconds.newBuilder().setSeconds(l)));
        file.ifPresent(n -> b.setFileID(asFileId(n, spec)));
        contract.ifPresent(n -> b.setContractID(asContractId(n, spec)));
    });
    return b -> b.setSystemDelete(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody) TxnUtils.asFileId(com.hedera.services.bdd.spec.transactions.TxnUtils.asFileId) SystemDelete(com.hederahashgraph.api.proto.java.HederaFunctionality.SystemDelete) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) Function(java.util.function.Function) Consumer(java.util.function.Consumer) OptionalLong(java.util.OptionalLong) 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) TimestampSeconds(com.hederahashgraph.api.proto.java.TimestampSeconds) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnUtils.asContractId(com.hedera.services.bdd.spec.transactions.TxnUtils.asContractId) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody)

Aggregations

SystemDeleteTransactionBody (com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody)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 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 ContractID (com.hederahashgraph.api.proto.java.ContractID)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 SystemDelete (com.hederahashgraph.api.proto.java.HederaFunctionality.SystemDelete)1 TimestampSeconds (com.hederahashgraph.api.proto.java.TimestampSeconds)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