use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertTokenPause.
private void insertTokenPause(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
long consensusTimestamp = recordItem.getConsensusTimestamp();
TokenPauseTransactionBody transactionBody = recordItem.getTransactionBody().getTokenPause();
Token token = Token.of(EntityId.of(transactionBody.getToken()));
token.setPauseStatus(TokenPauseStatusEnum.PAUSED);
updateToken(token, consensusTimestamp);
}
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class BatchUpserterTest method getToken.
@SneakyThrows
private Token getToken(String tokenId, String treasuryAccountId, Long createdTimestamp, Boolean freezeDefault, Key freezeKey, Key kycKey, Key pauseKey) {
var instr = "0011223344556677889900aabbccddeeff0011223344556677889900aabbccddeeff";
var hexKey = Key.newBuilder().setEd25519(ByteString.copyFrom(Hex.decodeHex(instr))).build().toByteArray();
Token token = new Token();
token.setCreatedTimestamp(createdTimestamp);
token.setDecimals(1000);
token.setFreezeDefault(freezeDefault);
token.setFreezeKey(freezeKey != null ? freezeKey.toByteArray() : null);
token.setInitialSupply(1_000_000_000L);
token.setKycKey(kycKey != null ? kycKey.toByteArray() : null);
token.setPauseKey(pauseKey != null ? pauseKey.toByteArray() : null);
token.setPauseStatus(pauseKey != null ? TokenPauseStatusEnum.UNPAUSED : TokenPauseStatusEnum.NOT_APPLICABLE);
token.setMaxSupply(1_000_000_000L);
token.setModifiedTimestamp(3L);
token.setName("FOO COIN TOKEN" + tokenId);
token.setSupplyKey(hexKey);
token.setSupplyType(TokenSupplyTypeEnum.INFINITE);
token.setSymbol("FOOTOK" + tokenId);
token.setTokenId(new TokenId(EntityId.of(tokenId, TOKEN)));
token.setTreasuryAccountId(EntityId.of(treasuryAccountId, ACCOUNT));
token.setType(TokenTypeEnum.FUNGIBLE_COMMON);
token.setWipeKey(hexKey);
return token;
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class BatchUpserterTest method tokenDissociateTransfer.
@Test
void tokenDissociateTransfer() {
// given
EntityId accountId = EntityId.of("0.0.215", ACCOUNT);
EntityId accountId2 = EntityId.of("0.0.216", ACCOUNT);
Token nftClass1 = getDeletedNftClass(10L, 25L, EntityId.of("0.0.100", TOKEN));
Token nftClass2 = getDeletedNftClass(11L, 24L, EntityId.of("0.0.101", TOKEN));
EntityId tokenId1 = nftClass1.getTokenId().getTokenId();
// already deleted, result of wipe
Nft nft1 = getNft(tokenId1, accountId, 1L, 11L, 16L, true);
Nft nft2 = getNft(tokenId1, accountId, 2L, 11L, 11L, false);
Nft nft3 = getNft(tokenId1, accountId, 3L, 12L, 12L, false);
// different account
Nft nft4 = getNft(tokenId1, accountId2, 4L, 18L, 18L, false);
Nft nft5 = getNft(nftClass2.getTokenId().getTokenId(), accountId, 1L, 15L, 15L, false);
nftRepository.saveAll(List.of(nft1, nft2, nft3, nft4, nft5));
tokenRepository.saveAll(List.of(nftClass1, nftClass2));
long consensusTimestamp = 30L;
EntityId ftId = EntityId.of("0.0.217", TOKEN);
EntityId payerId = EntityId.of("0.0.2002", ACCOUNT);
TokenTransfer fungibleTokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(-10).id(new TokenTransfer.Id(consensusTimestamp, ftId, accountId)).isApproval(false).payerAccountId(payerId).tokenDissociate(true)).get();
TokenTransfer nonFungibleTokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(-2).id(new TokenTransfer.Id(consensusTimestamp, tokenId1, accountId)).isApproval(false).payerAccountId(payerId).tokenDissociate(true)).get();
List<TokenTransfer> tokenTransfers = List.of(fungibleTokenTransfer, nonFungibleTokenTransfer);
// when
persist(tokenDissociateTransferBatchUpserter, tokenTransfers);
// then
assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, getNft(tokenId1, accountId, 2L, 11L, 30L, true), getNft(tokenId1, accountId, 3L, 12L, 30L, true), nft4, nft5);
NftTransfer serial2Transfer = getNftTransfer(tokenId1, accountId, 2L, consensusTimestamp);
serial2Transfer.setPayerAccountId(payerId);
NftTransfer serial3Transfer = getNftTransfer(tokenId1, accountId, 3L, consensusTimestamp);
serial3Transfer.setPayerAccountId(payerId);
assertThat(nftTransferRepository.findAll()).containsExactlyInAnyOrder(serial2Transfer, serial3Transfer);
assertThat(tokenTransferRepository.findAll()).usingElementComparatorIgnoringFields("tokenDissociate").containsOnly(fungibleTokenTransfer);
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNftDomainTransfer.
@Test
void onNftDomainTransfer() {
// create token first
EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
EntityId accountId3 = EntityId.of("0.0.5", ACCOUNT);
EntityId accountId4 = EntityId.of("0.0.6", ACCOUNT);
String metadata1 = "nft1";
String metadata2 = "nft2";
// save token entities first
Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
sqlEntityListener.onToken(token1);
sqlEntityListener.onToken(token2);
// create nfts
// mint transfer combined
Nft nft1Combined = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
// mint transfer combined
Nft nft2Combined = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
sqlEntityListener.onNft(nft1Combined);
sqlEntityListener.onNft(nft2Combined);
completeFileAndCommit();
assertEquals(2, nftRepository.count());
// nft w transfers
// transfer
sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId3, null, null, null, 5L));
// transfer
sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId4, null, null, null, 6L));
completeFileAndCommit();
// transfer
Nft nft1 = getNft(tokenId1, 1L, accountId3, 3L, false, metadata1, 5L);
// transfer
Nft nft2 = getNft(tokenId2, 1L, accountId4, 4L, false, metadata2, 6L);
assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2);
}
use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenConsecutiveNegativeTotalSupply.
@Test
void onTokenConsecutiveNegativeTotalSupply() {
// given
EntityId tokenId = EntityId.of("0.0.3", TOKEN);
EntityId accountId = EntityId.of("0.0.500", ACCOUNT);
// save token
Token token = getToken(tokenId, accountId, 1L, 1L);
sqlEntityListener.onToken(token);
completeFileAndCommit();
// when
// two dissociate of the deleted token, both with negative amount
Token update = getTokenUpdate(tokenId, 5);
update.setTotalSupply(-10L);
sqlEntityListener.onToken(update);
update = getTokenUpdate(tokenId, 6);
update.setTotalSupply(-15L);
sqlEntityListener.onToken(update);
completeFileAndCommit();
// then
token.setTotalSupply(token.getTotalSupply() - 25);
token.setModifiedTimestamp(6);
assertThat(tokenRepository.findAll()).containsExactlyInAnyOrder(token);
}
Aggregations