Search in sources :

Example 1 with TokenCreateTransactionBody

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

the class TokenCreateTransitionLogic method validate.

public ResponseCodeEnum validate(TransactionBody txnBody) {
    TokenCreateTransactionBody op = txnBody.getTokenCreation();
    final var domainType = TokenTypesMapper.mapToDomain(op.getTokenType());
    if (domainType == TokenType.NON_FUNGIBLE_UNIQUE && !dynamicProperties.areNftsEnabled()) {
        return NOT_SUPPORTED;
    }
    var validity = validator.memoCheck(op.getMemo());
    if (validity != OK) {
        return validity;
    }
    validity = validator.tokenSymbolCheck(op.getSymbol());
    if (validity != OK) {
        return validity;
    }
    validity = validator.tokenNameCheck(op.getName());
    if (validity != OK) {
        return validity;
    }
    validity = typeCheck(op.getTokenType(), op.getInitialSupply(), op.getDecimals());
    if (validity != OK) {
        return validity;
    }
    validity = supplyTypeCheck(op.getSupplyType(), op.getMaxSupply());
    if (validity != OK) {
        return validity;
    }
    validity = suppliesCheck(op.getInitialSupply(), op.getMaxSupply());
    if (validity != OK) {
        return validity;
    }
    if (!op.hasTreasury()) {
        return INVALID_TREASURY_ACCOUNT_FOR_TOKEN;
    }
    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;
    }
    if (op.getFreezeDefault() && !op.hasFreezeKey()) {
        return TOKEN_HAS_NO_FREEZE_KEY;
    }
    return validateAutoRenewAccount(op);
}
Also used : TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody)

Example 2 with TokenCreateTransactionBody

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

the class EntityRecordItemListener method insertTokenCreate.

private void insertTokenCreate(RecordItem recordItem) {
    if (!entityProperties.getPersist().isTokens()) {
        return;
    }
    // pull token details from TokenCreation body and TokenId from receipt
    TokenCreateTransactionBody tokenCreateTransactionBody = recordItem.getTransactionBody().getTokenCreation();
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    EntityId tokenId = EntityId.of(recordItem.getRecord().getReceipt().getTokenID());
    EntityId treasury = EntityId.of(tokenCreateTransactionBody.getTreasury());
    Token token = new Token();
    token.setCreatedTimestamp(consensusTimestamp);
    token.setDecimals(tokenCreateTransactionBody.getDecimals());
    token.setFreezeDefault(tokenCreateTransactionBody.getFreezeDefault());
    token.setInitialSupply(tokenCreateTransactionBody.getInitialSupply());
    token.setMaxSupply(tokenCreateTransactionBody.getMaxSupply());
    token.setModifiedTimestamp(consensusTimestamp);
    token.setName(tokenCreateTransactionBody.getName());
    token.setSupplyType(TokenSupplyTypeEnum.fromId(tokenCreateTransactionBody.getSupplyTypeValue()));
    token.setSymbol(tokenCreateTransactionBody.getSymbol());
    token.setTokenId(new TokenId(tokenId));
    token.setTotalSupply(tokenCreateTransactionBody.getInitialSupply());
    token.setTreasuryAccountId(treasury);
    token.setType(TokenTypeEnum.fromId(tokenCreateTransactionBody.getTokenTypeValue()));
    if (tokenCreateTransactionBody.hasFeeScheduleKey()) {
        token.setFeeScheduleKey(tokenCreateTransactionBody.getFeeScheduleKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasFreezeKey()) {
        token.setFreezeKey(tokenCreateTransactionBody.getFreezeKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasKycKey()) {
        token.setKycKey(tokenCreateTransactionBody.getKycKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasPauseKey()) {
        token.setPauseKey(tokenCreateTransactionBody.getPauseKey().toByteArray());
        token.setPauseStatus(TokenPauseStatusEnum.UNPAUSED);
    } else {
        token.setPauseStatus(TokenPauseStatusEnum.NOT_APPLICABLE);
    }
    if (tokenCreateTransactionBody.hasSupplyKey()) {
        token.setSupplyKey(tokenCreateTransactionBody.getSupplyKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasWipeKey()) {
        token.setWipeKey(tokenCreateTransactionBody.getWipeKey().toByteArray());
    }
    Set<EntityId> autoAssociatedAccounts = insertCustomFees(tokenCreateTransactionBody.getCustomFeesList(), consensusTimestamp, true, tokenId);
    autoAssociatedAccounts.add(treasury);
    if (recordItem.getRecord().getAutomaticTokenAssociationsCount() > 0) {
        // automatic_token_associations does not exist prior to services 0.18.0
        autoAssociatedAccounts.clear();
        recordItem.getRecord().getAutomaticTokenAssociationsList().stream().map(TokenAssociation::getAccountId).map(EntityId::of).forEach(autoAssociatedAccounts::add);
    }
    TokenFreezeStatusEnum freezeStatus = token.getFreezeKey() != null ? TokenFreezeStatusEnum.UNFROZEN : TokenFreezeStatusEnum.NOT_APPLICABLE;
    TokenKycStatusEnum kycStatus = token.getKycKey() != null ? TokenKycStatusEnum.GRANTED : TokenKycStatusEnum.NOT_APPLICABLE;
    autoAssociatedAccounts.forEach(account -> {
        TokenAccount tokenAccount = getAssociatedTokenAccount(account, false, consensusTimestamp, freezeStatus, kycStatus, tokenId);
        entityListener.onTokenAccount(tokenAccount);
    });
    entityListener.onToken(token);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenAssociation(com.hederahashgraph.api.proto.java.TokenAssociation) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)

Example 3 with TokenCreateTransactionBody

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

the class HapiTokenCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (symbolFn.isPresent()) {
        symbol = Optional.of(symbolFn.get().apply(spec));
    }
    if (nameFn.isPresent()) {
        name = Optional.of(nameFn.get().apply(spec));
    }
    TokenCreateTransactionBody opBody = spec.txns().<TokenCreateTransactionBody, TokenCreateTransactionBody.Builder>body(TokenCreateTransactionBody.class, b -> {
        tokenType.ifPresent(b::setTokenType);
        supplyType.ifPresent(b::setSupplyType);
        symbol.ifPresent(b::setSymbol);
        name.ifPresent(b::setName);
        entityMemo.ifPresent(s -> b.setMemo(s));
        initialSupply.ifPresent(b::setInitialSupply);
        maxSupply.ifPresent(b::setMaxSupply);
        decimals.ifPresent(b::setDecimals);
        freezeDefault.ifPresent(b::setFreezeDefault);
        adminKey.ifPresent(k -> b.setAdminKey(spec.registry().getKey(k)));
        freezeKey.ifPresent(k -> b.setFreezeKey(spec.registry().getKey(k)));
        supplyKey.ifPresent(k -> b.setSupplyKey(spec.registry().getKey(k)));
        feeScheduleKey.ifPresent(k -> b.setFeeScheduleKey(spec.registry().getKey(k)));
        pauseKey.ifPresent(k -> b.setPauseKey(spec.registry().getKey(k)));
        if (autoRenewAccount.isPresent()) {
            var id = TxnUtils.asId(autoRenewAccount.get(), spec);
            b.setAutoRenewAccount(id);
            long secs = autoRenewPeriod.orElse(spec.setup().defaultAutoRenewPeriod().getSeconds());
            b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(secs).build());
        }
        if (autoRenewPeriod.isEmpty()) {
            expiry.ifPresent(t -> b.setExpiry(Timestamp.newBuilder().setSeconds(t).build()));
        }
        wipeKey.ifPresent(k -> b.setWipeKey(spec.registry().getKey(k)));
        kycKey.ifPresent(k -> b.setKycKey(spec.registry().getKey(k)));
        treasury.ifPresent(a -> {
            var treasuryId = TxnUtils.asId(a, spec);
            b.setTreasury(treasuryId);
        });
        if (!feeScheduleSuppliers.isEmpty()) {
            for (var supplier : feeScheduleSuppliers) {
                b.addCustomFees(supplier.apply(spec));
            }
        }
    });
    return b -> b.setTokenCreation(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Duration(com.hederahashgraph.api.proto.java.Duration) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TOKEN_FUNGIBLE_COMMON_WITH_CUSTOM_FEES(com.hederahashgraph.api.proto.java.SubType.TOKEN_FUNGIBLE_COMMON_WITH_CUSTOM_FEES) OptionalLong(java.util.OptionalLong) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TOKEN_NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.SubType.TOKEN_NON_FUNGIBLE_UNIQUE) TOKEN_FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.SubType.TOKEN_FUNGIBLE_COMMON) SubType(com.hederahashgraph.api.proto.java.SubType) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) CustomFee(com.hederahashgraph.api.proto.java.CustomFee) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TokenOpsUsage(com.hedera.services.usage.token.TokenOpsUsage) TOKEN_OPS_USAGE_UTILS(com.hedera.services.usage.token.TokenOpsUsageUtils.TOKEN_OPS_USAGE_UTILS) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) TOKEN_NON_FUNGIBLE_UNIQUE_WITH_CUSTOM_FEES(com.hederahashgraph.api.proto.java.SubType.TOKEN_NON_FUNGIBLE_UNIQUE_WITH_CUSTOM_FEES) TokenType(com.hederahashgraph.api.proto.java.TokenType) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody)

Aggregations

TokenCreateTransactionBody (com.hederahashgraph.api.proto.java.TokenCreateTransactionBody)3 MoreObjects (com.google.common.base.MoreObjects)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 Token (com.hedera.mirror.common.domain.token.Token)1 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)1 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)1 TokenId (com.hedera.mirror.common.domain.token.TokenId)1 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnFactory.bannerWith (com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 CommonUtils (com.hedera.services.legacy.proto.utils.CommonUtils)1 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)1 TokenOpsUsage (com.hedera.services.usage.token.TokenOpsUsage)1