Search in sources :

Example 1 with TokenId

use of com.hedera.mirror.common.domain.token.TokenId 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 2 with TokenId

use of com.hedera.mirror.common.domain.token.TokenId in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method insertCustomFees.

/**
 * Inserts custom fees. Returns the list of collectors automatically associated with the newly created token if the
 * custom fees are from a token create transaction
 *
 * @param customFeeList      protobuf custom fee list
 * @param consensusTimestamp consensus timestamp of the corresponding transaction
 * @param isTokenCreate      if the transaction with the custom fees is a token create
 * @param tokenId            the token id the custom fees are attached to
 * @return A list of collectors automatically associated with the token if it's a token create transaction
 */
private Set<EntityId> insertCustomFees(List<com.hederahashgraph.api.proto.java.CustomFee> customFeeList, long consensusTimestamp, boolean isTokenCreate, EntityId tokenId) {
    Set<EntityId> autoAssociatedAccounts = new HashSet<>();
    CustomFee.Id id = new CustomFee.Id(consensusTimestamp, tokenId);
    for (var protoCustomFee : customFeeList) {
        EntityId collector = EntityId.of(protoCustomFee.getFeeCollectorAccountId());
        CustomFee customFee = new CustomFee();
        customFee.setId(id);
        customFee.setCollectorAccountId(collector);
        var feeCase = protoCustomFee.getFeeCase();
        boolean chargedInAttachedToken;
        switch(feeCase) {
            case FIXED_FEE:
                chargedInAttachedToken = parseFixedFee(customFee, protoCustomFee.getFixedFee(), tokenId);
                break;
            case FRACTIONAL_FEE:
                // only FT can have fractional fee
                parseFractionalFee(customFee, protoCustomFee.getFractionalFee());
                chargedInAttachedToken = true;
                break;
            case ROYALTY_FEE:
                // only NFT can have royalty fee, and fee can't be paid in NFT. Thus though royalty fee has a
                // fixed fee fallback, the denominating token of the fixed fee can't be the NFT itself
                parseRoyaltyFee(customFee, protoCustomFee.getRoyaltyFee(), tokenId);
                chargedInAttachedToken = false;
                break;
            default:
                log.error("Invalid CustomFee FeeCase {}", feeCase);
                throw new InvalidDatasetException(String.format("Invalid CustomFee FeeCase %s", feeCase));
        }
        if (isTokenCreate && chargedInAttachedToken) {
            // if it's from a token create transaction, and the fee is charged in the attached token, the attached
            // token and the collector should have been auto associated
            autoAssociatedAccounts.add(collector);
        }
        entityListener.onCustomFee(customFee);
    }
    if (customFeeList.isEmpty()) {
        // for empty custom fees, add a single row with only the timestamp and tokenId.
        CustomFee customFee = new CustomFee();
        customFee.setId(id);
        entityListener.onCustomFee(customFee);
    }
    return autoAssociatedAccounts;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CustomFee(com.hedera.mirror.common.domain.transaction.CustomFee) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenId(com.hedera.mirror.common.domain.token.TokenId) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) HashSet(java.util.HashSet)

Example 3 with TokenId

use of com.hedera.mirror.common.domain.token.TokenId in project hedera-mirror-node by hashgraph.

the class DomainBuilder method token.

public DomainWrapper<Token, Token.TokenBuilder> token() {
    long timestamp = timestamp();
    var builder = Token.builder().createdTimestamp(timestamp).decimals(1000).feeScheduleKey(key()).freezeDefault(false).freezeKey(key()).initialSupply(1_000_000_000L).kycKey(key()).modifiedTimestamp(timestamp).name("Hbars").pauseKey(key()).pauseStatus(TokenPauseStatusEnum.UNPAUSED).supplyKey(key()).symbol("HBAR").tokenId(new TokenId(entityId(TOKEN))).treasuryAccountId(entityId(ACCOUNT)).wipeKey(key());
    return new DomainWrapperImpl<>(builder, builder::build);
}
Also used : TokenId(com.hedera.mirror.common.domain.token.TokenId)

Example 4 with TokenId

use of com.hedera.mirror.common.domain.token.TokenId in project hedera-mirror-node by hashgraph.

the class SupportDeletedTokenDissociateMigrationTest method findAllTokens.

private List<Token> findAllTokens() {
    return jdbcOperations.query("select * from token", (rs, rowNum) -> {
        Token token = new Token();
        token.setCreatedTimestamp(rs.getLong("created_timestamp"));
        token.setDecimals(rs.getInt("decimals"));
        token.setFreezeDefault(rs.getBoolean("freeze_default"));
        token.setInitialSupply(rs.getLong("initial_supply"));
        token.setModifiedTimestamp(rs.getLong("modified_timestamp"));
        token.setName(rs.getString("name"));
        token.setSupplyType(TokenSupplyTypeEnum.valueOf(rs.getString("supply_type")));
        token.setSymbol(rs.getString("symbol"));
        token.setTokenId(new TokenId(EntityIdEndec.decode(rs.getLong("token_id"), TOKEN)));
        token.setTotalSupply(rs.getLong("total_supply"));
        token.setTreasuryAccountId(EntityIdEndec.decode(rs.getLong("treasury_account_id"), EntityType.TOKEN));
        token.setType(TokenTypeEnum.valueOf(rs.getString("type")));
        return token;
    });
}
Also used : Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId)

Example 5 with TokenId

use of com.hedera.mirror.common.domain.token.TokenId in project hedera-mirror-node by hashgraph.

the class TokenRepositoryTest method token.

@SneakyThrows
private Token token(long consensusTimestamp) {
    var hexKey = Key.newBuilder().setEd25519(ByteString.copyFrom(Hex.decodeHex(key))).build().toByteArray();
    Token token = new Token();
    token.setCreatedTimestamp(consensusTimestamp);
    token.setDecimals(1000);
    token.setFreezeDefault(false);
    token.setFreezeKey(hexKey);
    token.setInitialSupply(INITIAL_SUPPLY);
    token.setKycKey(hexKey);
    token.setModifiedTimestamp(consensusTimestamp);
    token.setName("FOO COIN TOKEN");
    token.setPauseKey(hexKey);
    token.setPauseStatus(TokenPauseStatusEnum.PAUSED);
    token.setSupplyKey(hexKey);
    token.setSupplyType(TokenSupplyTypeEnum.INFINITE);
    token.setSymbol("FOOTOK");
    token.setTokenId(new TokenId(FOO_COIN_ID));
    token.setTotalSupply(INITIAL_SUPPLY);
    token.setTreasuryAccountId(treasuryAccount);
    token.setType(TokenTypeEnum.FUNGIBLE_COMMON);
    token.setWipeKey(hexKey);
    return token;
}
Also used : Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) SneakyThrows(lombok.SneakyThrows)

Aggregations

TokenId (com.hedera.mirror.common.domain.token.TokenId)8 Token (com.hedera.mirror.common.domain.token.Token)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)2 AssessedCustomFee (com.hedera.mirror.common.domain.transaction.AssessedCustomFee)2 CustomFee (com.hedera.mirror.common.domain.transaction.CustomFee)2 SneakyThrows (lombok.SneakyThrows)2 NftId (com.hedera.mirror.common.domain.token.NftId)1 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)1 TokenAccountId (com.hedera.mirror.common.domain.token.TokenAccountId)1 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)1 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)1 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)1 TokenAssociation (com.hederahashgraph.api.proto.java.TokenAssociation)1 TokenCreateTransactionBody (com.hederahashgraph.api.proto.java.TokenCreateTransactionBody)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1