Search in sources :

Example 6 with Nft

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;
}
Also used : NftId(com.hedera.mirror.common.domain.token.NftId) Nft(com.hedera.mirror.common.domain.token.Nft)

Example 7 with 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);
}
Also used : Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Example 8 with Nft

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);
}
Also used : Nft(com.hedera.mirror.common.domain.token.Nft)

Example 9 with 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);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) Nft(com.hedera.mirror.common.domain.token.Nft)

Example 10 with 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);
            }
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) HashMap(java.util.HashMap) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) Nft(com.hedera.mirror.common.domain.token.Nft)

Aggregations

Nft (com.hedera.mirror.common.domain.token.Nft)20 EntityId (com.hedera.mirror.common.domain.entity.EntityId)12 Test (org.junit.jupiter.api.Test)12 ByteString (com.google.protobuf.ByteString)8 NftId (com.hedera.mirror.common.domain.token.NftId)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Token (com.hedera.mirror.common.domain.token.Token)5 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)5 Contract (com.hedera.mirror.common.domain.contract.Contract)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 ContractRepository (com.hedera.mirror.importer.repository.ContractRepository)3 CryptoAllowanceRepository (com.hedera.mirror.importer.repository.CryptoAllowanceRepository)3 NftAllowanceRepository (com.hedera.mirror.importer.repository.NftAllowanceRepository)3 NftRepository (com.hedera.mirror.importer.repository.NftRepository)3 HashMap (java.util.HashMap)3 BoolValue (com.google.protobuf.BoolValue)2 Int32Value (com.google.protobuf.Int32Value)2 StringValue (com.google.protobuf.StringValue)2 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2