Search in sources :

Example 26 with EntityId

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) Test(org.junit.jupiter.api.Test)

Example 27 with EntityId

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

Example 28 with EntityId

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

Example 29 with EntityId

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));
    }
}
Also used : TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 30 with EntityId

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);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13