use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertTokenAccountRevokeKyc.
private void insertTokenAccountRevokeKyc(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
TokenRevokeKycTransactionBody tokenRevokeKycTransactionBody = recordItem.getTransactionBody().getTokenRevokeKyc();
EntityId tokenId = EntityId.of(tokenRevokeKycTransactionBody.getToken());
EntityId accountId = EntityId.of(tokenRevokeKycTransactionBody.getAccount());
TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, recordItem.getConsensusTimestamp());
tokenAccount.setKycStatus(TokenKycStatusEnum.REVOKED);
entityListener.onTokenAccount(tokenAccount);
}
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertAutomaticTokenAssociations.
private void insertAutomaticTokenAssociations(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
if (recordItem.getTransactionBody().hasTokenCreation()) {
// automatic token associations for token create transactions are handled in insertTokenCreate
return;
}
long consensusTimestamp = recordItem.getConsensusTimestamp();
recordItem.getRecord().getAutomaticTokenAssociationsList().forEach(tokenAssociation -> {
// the only other transaction which creates auto associations is crypto transfer. The accounts and
// tokens in the associations should have been added to EntityListener when inserting the corresponding
// token transfers, so no need to duplicate the logic here
EntityId accountId = EntityId.of(tokenAssociation.getAccountId());
EntityId tokenId = EntityId.of(tokenAssociation.getTokenId());
TokenAccount tokenAccount = getAssociatedTokenAccount(accountId, true, consensusTimestamp, tokenId);
entityListener.onTokenAccount(tokenAccount);
});
}
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class BatchUpserterTest method getTokenAccount.
private TokenAccount getTokenAccount(String tokenId, String accountId, Long createdTimestamp, Boolean associated, Long modifiedTimestamp, TokenFreezeStatusEnum freezeStatus, TokenKycStatusEnum kycStatus) {
TokenAccount tokenAccount = new TokenAccount(EntityId.of(tokenId, TOKEN), EntityId.of(accountId, ACCOUNT), modifiedTimestamp);
tokenAccount.setAssociated(associated);
tokenAccount.setAutomaticAssociation(false);
tokenAccount.setCreatedTimestamp(createdTimestamp);
tokenAccount.setFreezeStatus(freezeStatus);
tokenAccount.setKycStatus(kycStatus);
return tokenAccount;
}
use of com.hedera.mirror.common.domain.token.TokenAccount 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);
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class SupportDeletedTokenDissociateMigrationTest method tokenAccount.
private TokenAccount tokenAccount(EntityId accountId, boolean associated, long createdTimestamp, long modifiedTimestamp, EntityId tokenId) {
TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, modifiedTimestamp);
tokenAccount.setAssociated(associated);
tokenAccount.setAutomaticAssociation(false);
tokenAccount.setCreatedTimestamp(createdTimestamp);
tokenAccount.setFreezeStatus(TokenFreezeStatusEnum.NOT_APPLICABLE);
tokenAccount.setKycStatus(TokenKycStatusEnum.NOT_APPLICABLE);
return tokenAccount;
}
Aggregations