Search in sources :

Example 1 with TokenFreezeStatusEnum

use of com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum 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)

Aggregations

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 TokenAssociation (com.hederahashgraph.api.proto.java.TokenAssociation)1 TokenCreateTransactionBody (com.hederahashgraph.api.proto.java.TokenCreateTransactionBody)1