Search in sources :

Example 1 with CryptoDeleteTransactionBody

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

the class HapiCryptoDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    AccountID target;
    if (referenceType == ReferenceType.REGISTRY_NAME) {
        target = TxnUtils.asId(account, spec);
    } else {
        account = lookUpAccountWithAlias(spec, aliasKeySource);
        target = asAccount(account);
    }
    CryptoDeleteTransactionBody opBody = spec.txns().<CryptoDeleteTransactionBody, CryptoDeleteTransactionBody.Builder>body(CryptoDeleteTransactionBody.class, b -> {
        transferAccount.ifPresent(a -> b.setTransferAccountID(spec.registry().getAccountID(a)));
        b.setDeleteAccountID(target);
    });
    return b -> b.setCryptoDelete(opBody);
}
Also used : CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ReferenceType(com.hedera.services.bdd.spec.queries.crypto.ReferenceType) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) HapiPropertySource.asAccount(com.hedera.services.bdd.spec.HapiPropertySource.asAccount) QueryUtils.lookUpAccountWithAlias(com.hedera.services.bdd.spec.queries.QueryUtils.lookUpAccountWithAlias) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody)

Example 2 with CryptoDeleteTransactionBody

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

the class CryptoDeleteTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    try {
        CryptoDeleteTransactionBody op = txnCtx.accessor().getTxn().getCryptoDelete();
        AccountID id = op.getDeleteAccountID();
        if (ledger.isKnownTreasury(id)) {
            txnCtx.setStatus(ACCOUNT_IS_TREASURY);
            return;
        }
        AccountID beneficiary = op.getTransferAccountID();
        if (ledger.isDetached(id) || ledger.isDetached(beneficiary)) {
            txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
            return;
        }
        if (!ledger.allTokenBalancesVanish(id)) {
            txnCtx.setStatus(TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES);
            return;
        }
        ledger.delete(id, beneficiary);
        sigImpactHistorian.markEntityChanged(id.getAccountNum());
        txnCtx.setStatus(SUCCESS);
    } catch (MissingAccountException mae) {
        txnCtx.setStatus(INVALID_ACCOUNT_ID);
    } catch (DeletedAccountException dae) {
        txnCtx.setStatus(ACCOUNT_DELETED);
    } catch (Exception e) {
        log.warn("Avoidable exception!", e);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) MissingAccountException(com.hedera.services.exceptions.MissingAccountException) CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody) DeletedAccountException(com.hedera.services.exceptions.DeletedAccountException) MissingAccountException(com.hedera.services.exceptions.MissingAccountException) DeletedAccountException(com.hedera.services.exceptions.DeletedAccountException)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)2 CryptoDeleteTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody)2 MoreObjects (com.google.common.base.MoreObjects)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource.asAccount (com.hedera.services.bdd.spec.HapiPropertySource.asAccount)1 QueryUtils.lookUpAccountWithAlias (com.hedera.services.bdd.spec.queries.QueryUtils.lookUpAccountWithAlias)1 ReferenceType (com.hedera.services.bdd.spec.queries.crypto.ReferenceType)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 DeletedAccountException (com.hedera.services.exceptions.DeletedAccountException)1 MissingAccountException (com.hedera.services.exceptions.MissingAccountException)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 Key (com.hederahashgraph.api.proto.java.Key)1 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1 TransactionResponse (com.hederahashgraph.api.proto.java.TransactionResponse)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1