use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class TokenTransferRepositoryTest method findById.
@Test
void findById() {
EntityId tokenId = EntityId.of(0L, 1L, 20L, TOKEN);
EntityId accountId = EntityId.of(0L, 1L, 7L, ACCOUNT);
EntityId payerAccountId = EntityId.of(0L, 1L, 500L, ACCOUNT);
long amount = 40L;
TokenTransfer tokenTransfer = domainBuilder.tokenTransfer().customize(t -> t.amount(amount).id(new TokenTransfer.Id(1L, tokenId, accountId)).payerAccountId(payerAccountId).tokenDissociate(false)).get();
tokenTransferRepository.save(tokenTransfer);
assertThat(tokenTransferRepository.findById(tokenTransfer.getId())).get().isEqualTo(tokenTransfer);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class NftRepositoryTest method updateAccountIdMissingNft.
@Test
void updateAccountIdMissingNft() {
NftId nftId = new NftId(1L, EntityId.of("0.0.1", EntityType.TOKEN));
EntityId accountId = EntityId.of("0.0.10", EntityType.ACCOUNT);
nftRepository.transferNftOwnership(nftId, accountId, 3L);
assertThat(nftRepository.findById(nftId)).isNotPresent();
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertNonFungibleTokenTransfers.
private void insertNonFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<com.hederahashgraph.api.proto.java.NftTransfer> nftTransfersList) {
for (NftTransfer nftTransfer : nftTransfersList) {
long serialNumber = nftTransfer.getSerialNumber();
if (serialNumber == NftTransferId.WILDCARD_SERIAL_NUMBER) {
// treasury change
return;
}
EntityId receiverId = EntityId.of(nftTransfer.getReceiverAccountID());
EntityId senderId = EntityId.of(nftTransfer.getSenderAccountID());
var nftTransferDomain = new com.hedera.mirror.common.domain.token.NftTransfer();
nftTransferDomain.setId(new NftTransferId(consensusTimestamp, serialNumber, entityTokenId));
nftTransferDomain.setIsApproval(false);
nftTransferDomain.setReceiverAccountId(receiverId);
nftTransferDomain.setSenderAccountId(senderId);
nftTransferDomain.setPayerAccountId(payerAccountId);
var nftTransferInsideBody = findNftTransferInsideBody(nftTransfer, tokenId, body);
if (nftTransferInsideBody != null) {
nftTransferDomain.setIsApproval(nftTransferInsideBody.getIsApproval());
}
entityListener.onNftTransfer(nftTransferDomain);
if (!EntityId.isEmpty(receiverId)) {
transferNftOwnership(consensusTimestamp, serialNumber, entityTokenId, receiverId);
}
}
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertTokenAccountWipe.
private void insertTokenAccountWipe(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
TokenWipeAccountTransactionBody tokenWipeAccountTransactionBody = recordItem.getTransactionBody().getTokenWipe();
EntityId tokenId = EntityId.of(tokenWipeAccountTransactionBody.getToken());
long consensusTimestamp = recordItem.getConsensusTimestamp();
updateTokenSupply(tokenId, recordItem.getRecord().getReceipt().getNewTotalSupply(), consensusTimestamp);
tokenWipeAccountTransactionBody.getSerialNumbersList().forEach(serialNumber -> updateNftDeleteStatus(consensusTimestamp, serialNumber, tokenId));
}
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertFungibleTokenTransfers.
private void insertFungibleTokenTransfers(long consensusTimestamp, TransactionBody body, boolean isTokenDissociate, TokenID tokenId, EntityId entityTokenId, EntityId payerAccountId, List<AccountAmount> tokenTransfers) {
for (AccountAmount accountAmount : tokenTransfers) {
EntityId accountId = EntityId.of(accountAmount.getAccountID());
long amount = accountAmount.getAmount();
TokenTransfer tokenTransfer = new TokenTransfer();
tokenTransfer.setAmount(amount);
tokenTransfer.setId(new TokenTransfer.Id(consensusTimestamp, entityTokenId, accountId));
tokenTransfer.setIsApproval(false);
tokenTransfer.setPayerAccountId(payerAccountId);
tokenTransfer.setTokenDissociate(isTokenDissociate);
// then again set is_approval=true
if (amount < 0) {
// Is the accountAmount from the record also inside a body's transfer list for the given tokenId?
AccountAmount accountAmountInsideTransferList = findAccountAmount(accountAmount::equals, tokenId, body);
if (accountAmountInsideTransferList == null) {
// Is there any account amount inside the body's transfer list for the given tokenId
// with the same accountId as the accountAmount from the record?
AccountAmount accountAmountWithSameIdInsideBody = findAccountAmount(aa -> aa.getAccountID().equals(accountAmount.getAccountID()) && aa.getIsApproval(), tokenId, body);
if (accountAmountWithSameIdInsideBody != null) {
tokenTransfer.setIsApproval(true);
}
} else {
tokenTransfer.setIsApproval(accountAmountInsideTransferList.getIsApproval());
}
}
entityListener.onTokenTransfer(tokenTransfer);
if (isTokenDissociate) {
// token transfers in token dissociate are for deleted tokens and the amount is negative to
// bring the account's balance of the token to 0. Set the totalSupply of the token object to the
// negative amount, later in the pipeline the token total supply will be reduced accordingly
Token token = Token.of(entityTokenId);
token.setModifiedTimestamp(consensusTimestamp);
token.setTotalSupply(accountAmount.getAmount());
entityListener.onToken(token);
}
}
}
Aggregations