Search in sources :

Example 21 with TokenAccount

use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.

the class SqlEntityListener method onTokenAccount.

@Override
public void onTokenAccount(TokenAccount tokenAccount) throws ImporterException {
    if (tokenAccounts.containsKey(tokenAccount.getId())) {
        log.warn("Skipping duplicate token account association: {}", tokenAccount);
        return;
    }
    var key = new TokenAccountKey(tokenAccount.getId().getTokenId(), tokenAccount.getId().getAccountId());
    TokenAccount merged = tokenAccountState.merge(key, tokenAccount, this::mergeTokenAccount);
    tokenAccounts.put(merged.getId(), merged);
}
Also used : TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenAccountKey(com.hedera.mirror.common.domain.token.TokenAccountKey)

Example 22 with TokenAccount

use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenCreateWithNfts.

@ParameterizedTest(name = "{0}")
@MethodSource("provideTokenCreateNftArguments")
void tokenCreateWithNfts(String name, List<CustomFee> customFees, boolean freezeDefault, boolean freezeKey, boolean kycKey, boolean pauseKey, List<TokenAccount> expectedTokenAccounts) {
    // given
    Entity expected = createEntity(DOMAIN_TOKEN_ID, TOKEN_REF_KEY, PAYER.getAccountNum(), AUTO_RENEW_PERIOD, false, EXPIRY_NS, TOKEN_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
    List<EntityId> autoAssociatedAccounts = expectedTokenAccounts.stream().map(TokenAccount::getId).map(TokenAccountId::getAccountId).collect(Collectors.toList());
    // when
    createTokenEntity(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, freezeDefault, freezeKey, kycKey, pauseKey, customFees, autoAssociatedAccounts);
    // then
    assertEquals(1L, entityRepository.count());
    assertEntity(expected);
    // verify token
    TokenPauseStatusEnum pauseStatus = pauseKey ? TokenPauseStatusEnum.UNPAUSED : TokenPauseStatusEnum.NOT_APPLICABLE;
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, CREATE_TIMESTAMP, SYMBOL, 0, pauseStatus);
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expectedTokenAccounts);
    assertCustomFeesInDb(customFees);
    assertThat(tokenTransferRepository.count()).isZero();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 23 with TokenAccount

use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTokenTest method tokenTransfer.

void tokenTransfer(List<AssessedCustomFee> assessedCustomFees, List<com.hederahashgraph.api.proto.java.AssessedCustomFee> protoAssessedCustomFees, boolean hasAutoTokenAssociations, boolean isPrecompile) {
    // given
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    TokenID tokenId2 = TokenID.newBuilder().setTokenNum(7).build();
    String symbol2 = "MIRROR";
    createTokenEntity(tokenId2, FUNGIBLE_COMMON, symbol2, 10L, false, false, false);
    AccountID accountId = AccountID.newBuilder().setAccountNum(1).build();
    // token transfer
    Transaction transaction = tokenTransferTransaction();
    TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-1000).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(1000).build()).build();
    TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenId2).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(333).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
    List<TokenTransferList> transferLists = List.of(transferList1, transferList2);
    // token treasury associations <TOKEN_ID, PAYER> and <tokenId2, PAYER> are created in the token create
    // transaction and they are not auto associations; the two token transfers' <token, recipient> pairs are
    // <TOKEN_ID, accountId> and <tokenId2, PAYER>, since <tokenId2, PAYER> already exists, only
    // <TOKEN_ID accountId> will be auto associated
    var autoTokenAssociation = TokenAssociation.newBuilder().setAccountId(accountId).setTokenId(TOKEN_ID).build();
    var autoTokenAccount = new TokenAccount(EntityId.of(TOKEN_ID), EntityId.of(accountId), TRANSFER_TIMESTAMP);
    autoTokenAccount.setAssociated(true);
    autoTokenAccount.setAutomaticAssociation(true);
    autoTokenAccount.setCreatedTimestamp(TRANSFER_TIMESTAMP);
    autoTokenAccount.setFreezeStatus(TokenFreezeStatusEnum.NOT_APPLICABLE);
    autoTokenAccount.setKycStatus(TokenKycStatusEnum.NOT_APPLICABLE);
    List<TokenAccount> expectedAutoAssociatedTokenAccounts = hasAutoTokenAssociations ? List.of(autoTokenAccount) : Collections.emptyList();
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(TRANSFER_TIMESTAMP, transaction, builder -> {
        builder.addAllTokenTransferLists(transferLists).addAllAssessedCustomFees(protoAssessedCustomFees);
        if (hasAutoTokenAssociations) {
            builder.addAutomaticTokenAssociations(autoTokenAssociation);
        }
        if (isPrecompile) {
            buildContractFunctionResult(builder.getContractCallResultBuilder());
            contractFunctionResultAtomic.set(builder.getContractCallResult());
        }
    });
    // then
    assertTokenTransferInRepository(TOKEN_ID, PAYER, TRANSFER_TIMESTAMP, -1000);
    assertTokenTransferInRepository(TOKEN_ID, accountId, TRANSFER_TIMESTAMP, 1000);
    assertTokenTransferInRepository(tokenId2, PAYER, TRANSFER_TIMESTAMP, 333);
    assertTokenTransferInRepository(tokenId2, accountId, TRANSFER_TIMESTAMP, -333);
    assertAssessedCustomFeesInDb(assessedCustomFees);
    assertThat(tokenAccountRepository.findAll()).filteredOn(TokenAccount::getAutomaticAssociation).containsExactlyInAnyOrderElementsOf(expectedAutoAssociatedTokenAccounts);
    if (isPrecompile) {
        assertContractResult(TRANSFER_TIMESTAMP, contractFunctionResultAtomic.get());
    }
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 24 with TokenAccount

use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method getTokenAccount.

private TokenAccount getTokenAccount(EntityId tokenId, EntityId accountId, Long createdTimestamp, long modifiedTimeStamp, Boolean associated, Boolean autoAssociated, TokenFreezeStatusEnum freezeStatus, TokenKycStatusEnum kycStatus) {
    TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, modifiedTimeStamp);
    tokenAccount.setAssociated(associated);
    tokenAccount.setAutomaticAssociation(autoAssociated);
    tokenAccount.setFreezeStatus(freezeStatus);
    tokenAccount.setKycStatus(kycStatus);
    tokenAccount.setCreatedTimestamp(createdTimestamp);
    return tokenAccount;
}
Also used : TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount)

Example 25 with TokenAccount

use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onTokenAccountDissociate.

@Test
void onTokenAccountDissociate() {
    EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
    // save token entities first
    Token token1 = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
    sqlEntityListener.onToken(token1);
    completeFileAndCommit();
    EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
    TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE);
    TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 10L, false, null, null, null);
    // when
    sqlEntityListener.onTokenAccount(associate);
    sqlEntityListener.onTokenAccount(dissociate);
    sqlEntityListener.onTokenAccount(dissociate);
    completeFileAndCommit();
    // then
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrder(associate, getTokenAccount(tokenId1, accountId1, 5L, 10L, false, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)27 EntityId (com.hedera.mirror.common.domain.entity.EntityId)18 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Token (com.hedera.mirror.common.domain.token.Token)8 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)8 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 TokenAccountKey (com.hedera.mirror.common.domain.token.TokenAccountKey)1 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)1 TokenId (com.hedera.mirror.common.domain.token.TokenId)1 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)1 TokenPauseStatusEnum (com.hedera.mirror.common.domain.token.TokenPauseStatusEnum)1 TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)1 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)1 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)1 TokenAssociateTransactionBody (com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody)1