Search in sources :

Example 6 with AccountID

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

the class GetAccountInfoAnswer method responseGiven.

@Override
public Response responseGiven(final Query query, final StateView view, final ResponseCodeEnum validity, final long cost) {
    final CryptoGetInfoQuery op = query.getCryptoGetInfo();
    CryptoGetInfoResponse.Builder response = CryptoGetInfoResponse.newBuilder();
    final ResponseType type = op.getHeader().getResponseType();
    if (validity != OK) {
        response.setHeader(header(validity, type, cost));
    } else {
        if (type == COST_ANSWER) {
            response.setHeader(costAnswerHeader(OK, cost));
        } else {
            AccountID id = op.getAccountID();
            var optionalInfo = view.infoForAccount(id, aliasManager);
            if (optionalInfo.isPresent()) {
                response.setHeader(answerOnlyHeader(OK));
                response.setAccountInfo(optionalInfo.get());
            } else {
                response.setHeader(answerOnlyHeader(FAIL_INVALID));
            }
        }
    }
    return Response.newBuilder().setCryptoGetInfo(response).build();
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 7 with AccountID

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

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

the class AliasResolver method resolveInternal.

private Result resolveInternal(final AliasManager aliasManager, final AccountID idOrAlias, final Consumer<AccountID> resolvingAction) {
    AccountID resolvedId = idOrAlias;
    var isEvmAddress = false;
    var result = Result.KNOWN_ALIAS;
    if (isAlias(idOrAlias)) {
        final var alias = idOrAlias.getAlias();
        if (alias.size() == EntityIdUtils.EVM_ADDRESS_SIZE) {
            final var evmAddress = alias.toByteArray();
            if (aliasManager.isMirror(evmAddress)) {
                offerMirrorId(evmAddress, resolvingAction);
                return Result.KNOWN_ALIAS;
            } else {
                isEvmAddress = true;
            }
        }
        final var resolution = aliasManager.lookupIdBy(alias);
        if (resolution != MISSING_NUM) {
            resolvedId = resolution.toGrpcAccountId();
        } else {
            result = netOf(isEvmAddress, alias);
        }
        resolutions.put(alias, resolution);
    }
    resolvingAction.accept(resolvedId);
    return result;
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 9 with AccountID

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

the class CryptoCreateTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    try {
        TransactionBody cryptoCreateTxn = txnCtx.accessor().getTxn();
        AccountID sponsor = cryptoCreateTxn.getTransactionID().getAccountID();
        CryptoCreateTransactionBody op = cryptoCreateTxn.getCryptoCreateAccount();
        long balance = op.getInitialBalance();
        final var created = ledger.create(sponsor, balance, asCustomizer(op));
        sigImpactHistorian.markEntityChanged(created.getAccountNum());
        txnCtx.setCreated(created);
        txnCtx.setStatus(SUCCESS);
    } catch (InsufficientFundsException ife) {
        txnCtx.setStatus(INSUFFICIENT_PAYER_BALANCE);
    } catch (Exception e) {
        log.warn("Avoidable exception!", e);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException)

Example 10 with AccountID

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

the class TokenUpdateTransitionLogic method transitionFor.

private void transitionFor(TokenUpdateTransactionBody op) {
    var id = store.resolve(op.getToken());
    if (id == MISSING_TOKEN) {
        txnCtx.setStatus(INVALID_TOKEN_ID);
        return;
    }
    ResponseCodeEnum outcome;
    MerkleToken token = store.get(id);
    if (op.hasExpiry() && !validator.isValidExpiry(op.getExpiry())) {
        txnCtx.setStatus(INVALID_EXPIRATION_TIME);
        return;
    }
    if (token.adminKey().isEmpty() && !affectsExpiryOnly.test(op)) {
        txnCtx.setStatus(TOKEN_IS_IMMUTABLE);
        return;
    }
    if (token.isDeleted()) {
        txnCtx.setStatus(TOKEN_WAS_DELETED);
        return;
    }
    if (token.isPaused()) {
        txnCtx.setStatus(TOKEN_IS_PAUSED);
        return;
    }
    outcome = autoRenewAttachmentCheck(op, token);
    if (outcome != OK) {
        txnCtx.setStatus(outcome);
        return;
    }
    Optional<AccountID> replacedTreasury = Optional.empty();
    if (op.hasTreasury()) {
        var newTreasury = op.getTreasury();
        if (ledger.isDetached(newTreasury)) {
            txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
            return;
        }
        if (!store.associationExists(newTreasury, id)) {
            txnCtx.setStatus(INVALID_TREASURY_ACCOUNT_FOR_TOKEN);
            return;
        }
        var existingTreasury = token.treasury().toGrpcAccountId();
        if (!allowChangedTreasuryToOwnNfts && token.tokenType() == NON_FUNGIBLE_UNIQUE) {
            var existingTreasuryBalance = ledger.getTokenBalance(existingTreasury, id);
            if (existingTreasuryBalance > 0L) {
                abortWith(CURRENT_TREASURY_STILL_OWNS_NFTS);
                return;
            }
        }
        if (!newTreasury.equals(existingTreasury)) {
            if (ledger.isDetached(existingTreasury)) {
                txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
                return;
            }
            outcome = prepNewTreasury(id, token, newTreasury);
            if (outcome != OK) {
                abortWith(outcome);
                return;
            }
            replacedTreasury = Optional.of(token.treasury().toGrpcAccountId());
        }
    }
    outcome = store.update(op, txnCtx.consensusTime().getEpochSecond());
    if (outcome == OK && replacedTreasury.isPresent()) {
        final var oldTreasury = replacedTreasury.get();
        long replacedTreasuryBalance = ledger.getTokenBalance(oldTreasury, id);
        if (replacedTreasuryBalance > 0) {
            if (token.tokenType().equals(TokenType.FUNGIBLE_COMMON)) {
                outcome = ledger.doTokenTransfer(id, oldTreasury, op.getTreasury(), replacedTreasuryBalance);
            } else {
                outcome = store.changeOwnerWildCard(new NftId(id.getShardNum(), id.getRealmNum(), id.getTokenNum(), -1), oldTreasury, op.getTreasury());
            }
        }
    }
    if (outcome != OK) {
        abortWith(outcome);
        return;
    }
    txnCtx.setStatus(SUCCESS);
    sigImpactHistorian.markEntityChanged(id.getTokenNum());
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) MerkleToken(com.hedera.services.state.merkle.MerkleToken) NftId(com.hedera.services.store.models.NftId)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12