use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.
the class NftRepositoryTest method nft.
private Nft nft(String tokenId, long serialNumber, long consensusTimestamp) {
Nft nft = new Nft();
nft.setAccountId(EntityId.of("0.0.1", EntityType.ACCOUNT));
nft.setCreatedTimestamp(consensusTimestamp);
nft.setId(new NftId(serialNumber, EntityId.of(tokenId, EntityType.TOKEN)));
nft.setMetadata(new byte[] { 1 });
nft.setModifiedTimestamp(consensusTimestamp);
return nft;
}
use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.
the class NftRepositoryTest method updateDeleted.
@Test
void updateDeleted() {
Nft savedNft = nftRepository.save(nft("0.0.3", 2, 2));
nftRepository.burnOrWipeNft(savedNft.getId(), 3L);
savedNft.setDeleted(true);
savedNft.setModifiedTimestamp(3L);
assertThat(nftRepository.findById(savedNft.getId())).contains(savedNft);
}
use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method updateNftDeleteStatus.
private void updateNftDeleteStatus(long modifiedTimeStamp, long serialNumber, EntityId tokenId) {
Nft nft = new Nft(serialNumber, tokenId);
nft.setDeleted(true);
nft.setModifiedTimestamp(modifiedTimeStamp);
entityListener.onNft(nft);
}
use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListener method insertTokenMint.
private void insertTokenMint(RecordItem recordItem) {
if (entityProperties.getPersist().isTokens()) {
TokenMintTransactionBody tokenMintTransactionBody = recordItem.getTransactionBody().getTokenMint();
long consensusTimestamp = recordItem.getConsensusTimestamp();
EntityId tokenId = EntityId.of(tokenMintTransactionBody.getToken());
updateTokenSupply(tokenId, recordItem.getRecord().getReceipt().getNewTotalSupply(), consensusTimestamp);
List<Long> serialNumbers = recordItem.getRecord().getReceipt().getSerialNumbersList();
for (int i = 0; i < serialNumbers.size(); i++) {
Nft nft = new Nft(serialNumbers.get(i), tokenId);
nft.setCreatedTimestamp(consensusTimestamp);
nft.setDeleted(false);
nft.setMetadata(DomainUtils.toBytes(tokenMintTransactionBody.getMetadata(i)));
nft.setModifiedTimestamp(consensusTimestamp);
entityListener.onNft(nft);
}
}
}
use of com.hedera.mirror.common.domain.token.Nft in project hedera-mirror-node by hashgraph.
the class CryptoApproveAllowanceTransactionHandler method parseNftAllowances.
private void parseNftAllowances(List<com.hederahashgraph.api.proto.java.NftAllowance> nftAllowances, RecordItem recordItem) {
var consensusTimestamp = recordItem.getConsensusTimestamp();
var payerAccountId = recordItem.getPayerAccountId();
var nftAllowanceState = new HashMap<NftAllowance.Id, NftAllowance>();
var nftSerialAllowanceState = new HashMap<NftId, Nft>();
// iterate the nft allowance list in reverse order and honor the last allowance for either
// the same owner, spender, and token for approved for all allowances, or the last serial allowance for
// the same owner, spender, token, and serial
var iterator = nftAllowances.listIterator(nftAllowances.size());
while (iterator.hasPrevious()) {
var nftApproval = iterator.previous();
EntityId ownerAccountId = getOwnerAccountId(nftApproval.getOwner(), payerAccountId);
if (ownerAccountId == EntityId.EMPTY) {
// and the partialDataAction is SKIP
continue;
}
EntityId spender = EntityId.of(nftApproval.getSpender());
EntityId tokenId = EntityId.of(nftApproval.getTokenId());
if (nftApproval.hasApprovedForAll()) {
var approvedForAll = nftApproval.getApprovedForAll().getValue();
NftAllowance nftAllowance = new NftAllowance();
nftAllowance.setApprovedForAll(approvedForAll);
nftAllowance.setOwner(ownerAccountId.getId());
nftAllowance.setPayerAccountId(payerAccountId);
nftAllowance.setSpender(spender.getId());
nftAllowance.setTokenId(tokenId.getId());
nftAllowance.setTimestampLower(consensusTimestamp);
if (nftAllowanceState.putIfAbsent(nftAllowance.getId(), nftAllowance) == null) {
entityListener.onNftAllowance(nftAllowance);
}
}
EntityId delegatingSpender = EntityId.of(nftApproval.getDelegatingSpender());
for (var serialNumber : nftApproval.getSerialNumbersList()) {
// services allows the same serial number of a nft token appears in multiple nft allowances to
// different spenders. The last spender will be granted such allowance.
Nft nft = new Nft(serialNumber, tokenId);
nft.setAccountId(ownerAccountId);
nft.setDelegatingSpender(delegatingSpender);
nft.setModifiedTimestamp(consensusTimestamp);
nft.setSpender(spender);
if (nftSerialAllowanceState.putIfAbsent(nft.getId(), nft) == null) {
entityListener.onNft(nft);
}
}
}
}
Aggregations