Search in sources :

Example 6 with TokenAllowance

use of com.hedera.mirror.common.domain.entity.TokenAllowance in project hedera-mirror-node by hashgraph.

the class AbstractAllowanceTransactionHandler method updateTransaction.

@Override
public void updateTransaction(Transaction transaction, RecordItem recordItem) {
    long consensusTimestamp = transaction.getConsensusTimestamp();
    var payerAccountId = recordItem.getPayerAccountId();
    for (var cryptoApproval : getCryptoAllowances(recordItem)) {
        CryptoAllowance cryptoAllowance = new CryptoAllowance();
        cryptoAllowance.setAmount(cryptoApproval.getAmount());
        cryptoAllowance.setOwner(EntityId.of(cryptoApproval.getOwner()).getId());
        cryptoAllowance.setPayerAccountId(payerAccountId);
        cryptoAllowance.setSpender(EntityId.of(cryptoApproval.getSpender()).getId());
        cryptoAllowance.setTimestampLower(consensusTimestamp);
        entityListener.onCryptoAllowance(cryptoAllowance);
    }
    for (var nftApproval : getNftAllowances(recordItem)) {
        var approvedForAll = nftApproval.hasApprovedForAll() && nftApproval.getApprovedForAll().getValue();
        NftAllowance nftAllowance = new NftAllowance();
        nftAllowance.setApprovedForAll(approvedForAll);
        nftAllowance.setOwner(EntityId.of(nftApproval.getOwner()).getId());
        nftAllowance.setPayerAccountId(payerAccountId);
        nftAllowance.setSerialNumbers(nftApproval.getSerialNumbersList());
        nftAllowance.setSpender(EntityId.of(nftApproval.getSpender()).getId());
        nftAllowance.setTokenId(EntityId.of(nftApproval.getTokenId()).getId());
        nftAllowance.setTimestampLower(consensusTimestamp);
        entityListener.onNftAllowance(nftAllowance);
    }
    for (var tokenApproval : getTokenAllowances(recordItem)) {
        TokenAllowance tokenAllowance = new TokenAllowance();
        tokenAllowance.setAmount(tokenApproval.getAmount());
        tokenAllowance.setOwner(EntityId.of(tokenApproval.getOwner()).getId());
        tokenAllowance.setPayerAccountId(payerAccountId);
        tokenAllowance.setSpender(EntityId.of(tokenApproval.getSpender()).getId());
        tokenAllowance.setTokenId(EntityId.of(tokenApproval.getTokenId()).getId());
        tokenAllowance.setTimestampLower(consensusTimestamp);
        entityListener.onTokenAllowance(tokenAllowance);
    }
}
Also used : CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance)

Example 7 with TokenAllowance

use of com.hedera.mirror.common.domain.entity.TokenAllowance in project hedera-mirror-node by hashgraph.

the class BatchUpserterTest method tokenAllowance.

@Test
void tokenAllowance() {
    TokenAllowance tokenAllowance1 = domainBuilder.tokenAllowance().get();
    TokenAllowance tokenAllowance2 = domainBuilder.tokenAllowance().get();
    TokenAllowance tokenAllowance3 = domainBuilder.tokenAllowance().get();
    var tokenAllowance = List.of(tokenAllowance1, tokenAllowance2, tokenAllowance3);
    persist(batchPersister, tokenAllowance);
    assertThat(tokenAllowanceRepository.findAll()).containsExactlyInAnyOrderElementsOf(tokenAllowance);
}
Also used : TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 8 with TokenAllowance

use of com.hedera.mirror.common.domain.entity.TokenAllowance in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onTokenAllowance.

@Test
void onTokenAllowance() {
    // given
    TokenAllowance tokenAllowance1 = domainBuilder.tokenAllowance().get();
    TokenAllowance tokenAllowance2 = domainBuilder.tokenAllowance().get();
    // when
    sqlEntityListener.onTokenAllowance(tokenAllowance1);
    sqlEntityListener.onTokenAllowance(tokenAllowance2);
    completeFileAndCommit();
    // then
    assertThat(entityRepository.count()).isZero();
    assertThat(tokenAllowanceRepository.findAll()).containsExactlyInAnyOrder(tokenAllowance1, tokenAllowance2);
    assertThat(findHistory(TokenAllowance.class, "payer_account_id, spender, token_id")).isEmpty();
}
Also used : TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TokenAllowance (com.hedera.mirror.common.domain.entity.TokenAllowance)8 Test (org.junit.jupiter.api.Test)5 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)3 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 NftAllowance (com.hedera.mirror.common.domain.entity.NftAllowance)2 ByteString (com.google.protobuf.ByteString)1 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)1 SCHEDULE (com.hedera.mirror.common.domain.entity.EntityType.SCHEDULE)1 TOKEN (com.hedera.mirror.common.domain.entity.EntityType.TOKEN)1 Schedule (com.hedera.mirror.common.domain.schedule.Schedule)1 Nft (com.hedera.mirror.common.domain.token.Nft)1 NftId (com.hedera.mirror.common.domain.token.NftId)1