Search in sources :

Example 1 with TokenUpdateTransactionBody

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

the class TokenUpdateTransitionLogic method validate.

public ResponseCodeEnum validate(TransactionBody txnBody) {
    TokenUpdateTransactionBody op = txnBody.getTokenUpdate();
    if (!op.hasToken()) {
        return INVALID_TOKEN_ID;
    }
    var validity = !op.hasMemo() ? OK : validator.memoCheck(op.getMemo().getValue());
    if (validity != OK) {
        return validity;
    }
    var hasNewSymbol = op.getSymbol().length() > 0;
    if (hasNewSymbol) {
        validity = validator.tokenSymbolCheck(op.getSymbol());
        if (validity != OK) {
            return validity;
        }
    }
    var hasNewTokenName = op.getName().length() > 0;
    if (hasNewTokenName) {
        validity = validator.tokenNameCheck(op.getName());
        if (validity != OK) {
            return validity;
        }
    }
    validity = checkKeys(op.hasAdminKey(), op.getAdminKey(), op.hasKycKey(), op.getKycKey(), op.hasWipeKey(), op.getWipeKey(), op.hasSupplyKey(), op.getSupplyKey(), op.hasFreezeKey(), op.getFreezeKey(), op.hasFeeScheduleKey(), op.getFeeScheduleKey(), op.hasPauseKey(), op.getPauseKey());
    if (validity != OK) {
        return validity;
    }
    return validity;
}
Also used : TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)

Example 2 with TokenUpdateTransactionBody

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

the class HapiTokenUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var id = TxnUtils.asTokenId(token, spec);
    if (newSymbolFn.isPresent()) {
        newSymbol = Optional.of(newSymbolFn.get().apply(spec));
    }
    if (newNameFn.isPresent()) {
        newName = Optional.of(newNameFn.get().apply(spec));
    }
    TokenUpdateTransactionBody opBody = spec.txns().<TokenUpdateTransactionBody, TokenUpdateTransactionBody.Builder>body(TokenUpdateTransactionBody.class, b -> {
        b.setToken(id);
        newSymbol.ifPresent(b::setSymbol);
        newName.ifPresent(b::setName);
        newMemo.ifPresent(s -> b.setMemo(StringValue.newBuilder().setValue(s).build()));
        if (useImproperEmptyKey) {
            b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else if (useEmptyAdminKeyList) {
            b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
        } else {
            newAdminKey.ifPresent(a -> b.setAdminKey(spec.registry().getKey(a)));
        }
        newTreasury.ifPresent(a -> b.setTreasury(spec.registry().getAccountID(a)));
        newSupplyKey.ifPresent(k -> b.setSupplyKey(spec.registry().getKey(k)));
        newSupplyKeySupplier.ifPresent(s -> b.setSupplyKey(s.get()));
        newWipeKey.ifPresent(k -> b.setWipeKey(spec.registry().getKey(k)));
        newKycKey.ifPresent(k -> b.setKycKey(spec.registry().getKey(k)));
        if (useInvalidFeeScheduleKey) {
            b.setFeeScheduleKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else {
            newFeeScheduleKey.ifPresent(k -> b.setFeeScheduleKey(spec.registry().getKey(k)));
        }
        newFreezeKey.ifPresent(k -> b.setFreezeKey(spec.registry().getKey(k)));
        newPauseKey.ifPresent(k -> b.setPauseKey(spec.registry().getKey(k)));
        if (autoRenewAccount.isPresent()) {
            var autoRenewId = TxnUtils.asId(autoRenewAccount.get(), spec);
            b.setAutoRenewAccount(autoRenewId);
        }
        expiry.ifPresent(t -> b.setExpiry(Timestamp.newBuilder().setSeconds(t).build()));
        autoRenewPeriod.ifPresent(secs -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(secs).build()));
    });
    return b -> b.setTokenUpdate(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TokenUpdateUsage(com.hedera.services.usage.token.TokenUpdateUsage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)

Example 3 with TokenUpdateTransactionBody

use of com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertTokenUpdate.

private void insertTokenUpdate(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        TokenUpdateTransactionBody tokenUpdateTransactionBody = recordItem.getTransactionBody().getTokenUpdate();
        Token token = Token.of(EntityId.of(tokenUpdateTransactionBody.getToken()));
        if (tokenUpdateTransactionBody.hasFeeScheduleKey()) {
            token.setFeeScheduleKey(tokenUpdateTransactionBody.getFeeScheduleKey().toByteArray());
        }
        if (tokenUpdateTransactionBody.hasFreezeKey()) {
            token.setFreezeKey(tokenUpdateTransactionBody.getFreezeKey().toByteArray());
        }
        if (tokenUpdateTransactionBody.hasKycKey()) {
            token.setKycKey(tokenUpdateTransactionBody.getKycKey().toByteArray());
        }
        if (tokenUpdateTransactionBody.hasPauseKey()) {
            token.setPauseKey(tokenUpdateTransactionBody.getPauseKey().toByteArray());
        }
        if (tokenUpdateTransactionBody.hasSupplyKey()) {
            token.setSupplyKey(tokenUpdateTransactionBody.getSupplyKey().toByteArray());
        }
        if (tokenUpdateTransactionBody.hasTreasury()) {
            token.setTreasuryAccountId(EntityId.of(tokenUpdateTransactionBody.getTreasury()));
        }
        if (tokenUpdateTransactionBody.hasWipeKey()) {
            token.setWipeKey(tokenUpdateTransactionBody.getWipeKey().toByteArray());
        }
        if (!tokenUpdateTransactionBody.getName().isEmpty()) {
            token.setName(tokenUpdateTransactionBody.getName());
        }
        if (!tokenUpdateTransactionBody.getSymbol().isEmpty()) {
            token.setSymbol(tokenUpdateTransactionBody.getSymbol());
        }
        updateToken(token, consensusTimestamp);
    }
}
Also used : Token(com.hedera.mirror.common.domain.token.Token) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)

Aggregations

TokenUpdateTransactionBody (com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)3 MoreObjects (com.google.common.base.MoreObjects)1 StringValue (com.google.protobuf.StringValue)1 Token (com.hedera.mirror.common.domain.token.Token)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)1 TokenUpdateUsage (com.hedera.services.usage.token.TokenUpdateUsage)1 Duration (com.hederahashgraph.api.proto.java.Duration)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 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)1 TokenInfo (com.hederahashgraph.api.proto.java.TokenInfo)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