Search in sources :

Example 6 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum 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)

Example 7 with ResponseCodeEnum

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

the class TokenListChecks method checkKeys.

public static ResponseCodeEnum checkKeys(final boolean hasAdminKey, final Key adminKey, final boolean hasKycKey, final Key kycKey, final boolean hasWipeKey, final Key wipeKey, final boolean hasSupplyKey, final Key supplyKey, final boolean hasFreezeKey, final Key freezeKey, final boolean hasFeeScheduleKey, final Key feeScheduleKey, final boolean hasPauseKey, final Key pauseKey) {
    ResponseCodeEnum validity = checkAdminKey(hasAdminKey, adminKey);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasKycKey, kycKey, INVALID_KYC_KEY);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasWipeKey, wipeKey, INVALID_WIPE_KEY);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasSupplyKey, supplyKey, INVALID_SUPPLY_KEY);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasFreezeKey, freezeKey, INVALID_FREEZE_KEY);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasFeeScheduleKey, feeScheduleKey, INVALID_CUSTOM_FEE_SCHEDULE_KEY);
    if (validity != OK) {
        return validity;
    }
    validity = checkKeyOfType(hasPauseKey, pauseKey, INVALID_PAUSE_KEY);
    return validity;
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum)

Example 8 with ResponseCodeEnum

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

the class FileAppendTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    var op = txnCtx.accessor().getTxn().getFileAppend();
    try {
        var target = op.getFileID();
        var data = op.getContents().toByteArray();
        ResponseCodeEnum validity;
        if (fileNumbers.isSoftwareUpdateFile(target.getFileNum())) {
            validity = hfs.exists(target) ? OK : INVALID_FILE_ID;
        } else {
            Optional<HFileMeta> attr = hfs.exists(target) ? Optional.of(hfs.getattr(target)) : Optional.empty();
            validity = classify(attr);
        }
        if (validity != OK) {
            txnCtx.setStatus(validity);
            return;
        }
        if (networkCtx.get().getPreparedUpdateFileNum() == target.getFileNum()) {
            txnCtx.setStatus(PREPARED_UPDATE_FILE_IS_IMMUTABLE);
            return;
        }
        final var result = hfs.append(target, data);
        final var status = result.outcome();
        txnCtx.setStatus(status);
    } catch (IllegalArgumentException iae) {
        mapToStatus(iae, txnCtx);
    } catch (Exception unknown) {
        log.warn("Unrecognized failure handling {}!", txnCtx.accessor().getSignedTxnWrapper(), unknown);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) HFileMeta(com.hedera.services.files.HFileMeta)

Example 9 with ResponseCodeEnum

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

the class SigOpsRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    hfs = scenario.hfs();
    aliasManager = mock(AliasManager.class);
    runningAvgs = mock(MiscRunningAvgs.class);
    speedometers = mock(MiscSpeedometers.class);
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    expectedErrorStatus = null;
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    signingOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var payerKeys = signingOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
    expectedSigs = new ArrayList<>();
    if (payerKeys.hasErrorReport()) {
        expectedErrorStatus = payerKeys.getErrorReport();
    } else {
        PlatformSigsCreationResult payerResult = PlatformSigOps.createCryptoSigsFrom(payerKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
        expectedSigs.addAll(payerResult.getPlatformSigs());
        SigningOrderResult<ResponseCodeEnum> otherKeys = signingOrder.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
        if (otherKeys.hasErrorReport()) {
            expectedErrorStatus = otherKeys.getErrorReport();
        } else {
            PlatformSigsCreationResult otherResult = PlatformSigOps.createCryptoSigsFrom(otherKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
            if (!otherResult.hasFailed()) {
                expectedSigs.addAll(otherResult.getPlatformSigs());
            }
        }
    }
}
Also used : AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PojoSigMapPubKeyToSigBytes(com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) MiscRunningAvgs(com.hedera.services.stats.MiscRunningAvgs) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 10 with ResponseCodeEnum

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

the class GetFileContentsAnswerTest method usesValidator.

@Test
void usesValidator() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    given(optionValidator.queryableFileStatus(asFile(target), view)).willReturn(FILE_DELETED);
    // when:
    ResponseCodeEnum validity = subject.checkValidity(query, view);
    // then:
    assertEquals(FILE_DELETED, validity);
    // and:
    verify(optionValidator).queryableFileStatus(any(), any());
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) Query(com.hederahashgraph.api.proto.java.Query) FileGetContentsQuery(com.hederahashgraph.api.proto.java.FileGetContentsQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)52 Test (org.junit.jupiter.api.Test)38 Query (com.hederahashgraph.api.proto.java.Query)24 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)8 AccountID (com.hederahashgraph.api.proto.java.AccountID)6 Response (com.hederahashgraph.api.proto.java.Response)6 CryptoGetAccountBalanceResponse (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 SignedTxnAccessor (com.hedera.services.utils.SignedTxnAccessor)3 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)3 ContractID (com.hederahashgraph.api.proto.java.ContractID)3 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)3 AliasManager (com.hedera.services.ledger.accounts.AliasManager)2 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)2 EntityNum (com.hedera.services.utils.EntityNum)2 TopicID (com.hederahashgraph.api.proto.java.TopicID)2 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)2 Instant (java.time.Instant)2 ByteString (com.google.protobuf.ByteString)1 EntityNumbers (com.hedera.services.config.EntityNumbers)1