Search in sources :

Example 16 with Token

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

the class SupportDeletedTokenDissociateMigrationTest method token.

private Token token(long createdTimestamp, EntityId tokenId, TokenTypeEnum tokenType) {
    Token token = Token.of(tokenId);
    token.setCreatedTimestamp(createdTimestamp);
    token.setDecimals(0);
    token.setFreezeDefault(false);
    token.setInitialSupply(0L);
    token.setModifiedTimestamp(createdTimestamp);
    token.setName("foo");
    token.setSupplyType(TokenSupplyTypeEnum.INFINITE);
    token.setSymbol("bar");
    token.setTotalSupply(1_000_000L);
    token.setTreasuryAccountId(TREASURY);
    token.setType(tokenType);
    String sql = "insert into token (created_timestamp, decimals, freeze_default, initial_supply, " + "modified_timestamp, name, supply_type, symbol, token_id, total_supply, treasury_account_id, type) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    Object[] arguments = new Object[] { token.getCreatedTimestamp(), token.getDecimals(), token.getFreezeDefault(), token.getInitialSupply(), token.getModifiedTimestamp(), token.getName(), token.getSupplyType(), token.getSymbol(), token.getTokenId().getTokenId().getId(), token.getTotalSupply(), token.getTreasuryAccountId().getId(), token.getType() };
    int[] argumentTypes = new int[] { Types.BIGINT, Types.BIGINT, Types.BOOLEAN, Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.OTHER, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.OTHER };
    jdbcOperations.update(sql, arguments, argumentTypes);
    return token;
}
Also used : Token(com.hedera.mirror.common.domain.token.Token)

Example 17 with Token

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

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

the class SupportDeletedTokenDissociateMigrationTest method verify.

@Test
void verify() {
    // given
    // entities
    // - 2 ft classes
    // - deleted, account1's token dissociate includes token transfer
    // - still alive
    // - 3 nft classes
    // - deleted, account1's token dissociate doesn't include token transfer, account2's includes
    // - deleted, account1's token dissociate doesn't include token transfer, account2's dissociate happened
    // before token deletion
    // - still alive
    EntityId account1 = EntityId.of("0.0.210", ACCOUNT);
    EntityId account2 = EntityId.of("0.0.211", ACCOUNT);
    EntityId ftId1 = EntityId.of("0.0.500", TOKEN);
    EntityId ftId2 = EntityId.of("0.0.501", TOKEN);
    EntityId nftId1 = EntityId.of("0.0.502", TOKEN);
    EntityId nftId2 = EntityId.of("0.0.503", TOKEN);
    EntityId nftId3 = EntityId.of("0.0.504", TOKEN);
    Token ftClass1 = token(10L, ftId1, FUNGIBLE_COMMON);
    Token ftClass2 = token(15L, ftId2, FUNGIBLE_COMMON);
    Token nftClass1 = token(20L, nftId1, NON_FUNGIBLE_UNIQUE);
    Token nftClass2 = token(25L, nftId2, NON_FUNGIBLE_UNIQUE);
    Token nftClass3 = token(30L, nftId3, NON_FUNGIBLE_UNIQUE);
    MigrationEntity ft1Entity = entity(ftClass1, true, 50L);
    MigrationEntity ft2Entity = entity(ftClass2);
    MigrationEntity nft1Entity = entity(nftClass1, true, 55L);
    MigrationEntity nft2Entity = entity(nftClass2, true, 60L);
    MigrationEntity nft3Entity = entity(nftClass3);
    persistEntities(List.of(ft1Entity, ft2Entity, nft1Entity, nft2Entity, nft3Entity));
    long account1Ft1DissociateTimestamp = 70;
    long account1Nft1DissociateTimestamp = 75;
    long account2Nft1DissociateTimestamp = 80;
    long account1Nft2DissociateTimestamp = 85;
    // happened before token deletion
    long account2Nft2DissociateTimestamp = 55;
    List<TokenAccount> tokenAccounts = List.of(tokenAccount(account1, true, 12L, 12L, ftId1), tokenAccount(account1, false, 12L, account1Ft1DissociateTimestamp, ftId1), tokenAccount(account2, true, 15L, 15L, ftId1), tokenAccount(account1, true, 20L, 20L, ftId2), tokenAccount(account1, true, 23L, 23L, nftId1), tokenAccount(account1, false, 23L, account1Nft1DissociateTimestamp, nftId1), tokenAccount(account2, true, 25L, 25L, nftId1), tokenAccount(account2, false, 25L, account2Nft1DissociateTimestamp, nftId1), tokenAccount(account1, true, 27L, 27L, nftId2), tokenAccount(account1, false, 27L, account1Nft2DissociateTimestamp, nftId2), tokenAccount(account2, true, 29L, 29L, nftId2), tokenAccount(account2, false, 29L, account2Nft2DissociateTimestamp, nftId2));
    tokenAccountRepository.saveAll(tokenAccounts);
    // token dissociate transactions
    List<Transaction> transactions = List.of(tokenDissociateTransaction(account1Ft1DissociateTimestamp, account1), tokenDissociateTransaction(account1Nft1DissociateTimestamp, account1), tokenDissociateTransaction(account2Nft1DissociateTimestamp, account2), tokenDissociateTransaction(account1Nft2DissociateTimestamp, account1), tokenDissociateTransaction(account2Nft2DissociateTimestamp, account2));
    persistTransactions(transactions);
    // transfers
    persistTokenTransfers(List.of(new TokenTransfer(account1Ft1DissociateTimestamp, -10, ftId1, account1), new TokenTransfer(account2Nft1DissociateTimestamp, -1, nftId1, account2)));
    // nfts
    // - 2 for <account1, nftId1>, 1 already deleted before dissociate, the other without dissociate transfer
    // - 2 for <account1, nftId2>, 1 already deleted before dissociate, the other without dissociate transfer
    // - 2 for <account2, nftId1>, 1 already deleted before dissociate, the other with dissociate transfer
    // - 1 for <account2, nftId2>, already deleted, account2 dissociated nftId2 before nft class deletion
    // - 1 for <account1, nftId3>
    // - 1 for <account2, nftId3>
    persistNfts(List.of(nft(account1, 25L, true, 27L, 1L, nftId1), nft(account1, 25L, false, 25L, 2L, nftId1), nft(account1, 30L, true, 35L, 1L, nftId2), nft(account1, 30L, false, 30L, 2L, nftId2), nft(account1, 40L, false, 40L, 1L, nftId3), nft(account2, 28L, true, 32L, 3L, nftId1), nft(account2, 28L, false, 28L, 4L, nftId1), nft(account2, 33L, true, 37L, 3L, nftId2), nft(account2, 45L, false, 45L, 2L, nftId3)));
    // nft transfers from nft class treasury update
    persistNftTransfers(List.of(nftTransfer(40L, NEW_TREASURY, TREASURY, NftTransferId.WILDCARD_SERIAL_NUMBER, nftId3)));
    // expected token changes
    ftClass1.setTotalSupply(ftClass1.getTotalSupply() - 10);
    ftClass1.setModifiedTimestamp(account1Ft1DissociateTimestamp);
    // 1 nft wiped from explicit token transfer of the token dissociate, 1 wiped from a previous token dissociate
    // without explicit token transfer
    nftClass1.setTotalSupply(nftClass1.getTotalSupply() - 2);
    nftClass1.setModifiedTimestamp(account2Nft1DissociateTimestamp);
    nftClass2.setTotalSupply(nftClass2.getTotalSupply() - 1);
    nftClass2.setModifiedTimestamp(account1Nft2DissociateTimestamp);
    // when
    migrate();
    // then
    assertThat(findAllNfts()).containsExactlyInAnyOrder(nft(account1, 25L, true, 27L, 1L, nftId1), nft(account1, 25L, true, account1Nft1DissociateTimestamp, 2L, nftId1), nft(account1, 30L, true, 35L, 1L, nftId2), nft(account1, 30L, true, account1Nft2DissociateTimestamp, 2L, nftId2), nft(account1, 40L, false, 40L, 1L, nftId3), nft(account2, 28L, true, 32L, 3L, nftId1), nft(account2, 28L, true, account2Nft1DissociateTimestamp, 4L, nftId1), nft(account2, 33L, true, 37L, 3L, nftId2), nft(account2, 45L, false, 45L, 2L, nftId3));
    // expect new nft transfers from token dissociate of deleted nft class
    // expect nft transfers for nft treasury update removed
    assertThat(findAllNftTransfers()).usingElementComparatorIgnoringFields("payerAccountId").containsExactlyInAnyOrder(nftTransfer(account1Nft1DissociateTimestamp, null, account1, 2L, nftId1), nftTransfer(account1Nft2DissociateTimestamp, null, account1, 2L, nftId2), nftTransfer(account2Nft1DissociateTimestamp, null, account2, 4L, nftId1));
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(tokenAccounts);
    assertThat(findAllTokens()).usingElementComparatorIgnoringFields("pauseKey", "pauseStatus").containsExactlyInAnyOrder(ftClass1, ftClass2, nftClass1, nftClass2, nftClass3);
    // the token transfer for nft should have been removed
    assertThat(findAllTokenTransfers()).usingElementComparatorIgnoringFields("payerAccountId").containsExactlyInAnyOrder(new TokenTransfer(account1Ft1DissociateTimestamp, -10, ftId1, account1));
    assertThat(findAllTransactions()).containsExactlyInAnyOrderElementsOf(transactions);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 19 with Token

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

Example 20 with Token

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

Token (com.hedera.mirror.common.domain.token.Token)33 Test (org.junit.jupiter.api.Test)20 EntityId (com.hedera.mirror.common.domain.entity.EntityId)18 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)9 ByteString (com.google.protobuf.ByteString)6 Nft (com.hedera.mirror.common.domain.token.Nft)6 TokenId (com.hedera.mirror.common.domain.token.TokenId)6 TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)3 SneakyThrows (lombok.SneakyThrows)3 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)2 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)2 ArrayList (java.util.ArrayList)2 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)1