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);
}
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);
}
}
Aggregations