Search in sources :

Example 31 with EntityId

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

the class EntityRecordItemListener method insertTokenFeeScheduleUpdate.

private void insertTokenFeeScheduleUpdate(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        TokenFeeScheduleUpdateTransactionBody transactionBody = recordItem.getTransactionBody().getTokenFeeScheduleUpdate();
        EntityId tokenId = EntityId.of(transactionBody.getTokenId());
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        insertCustomFees(transactionBody.getCustomFeesList(), consensusTimestamp, false, tokenId);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody)

Example 32 with EntityId

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

the class EntityRecordItemListener method insertTokenCreate.

private void insertTokenCreate(RecordItem recordItem) {
    if (!entityProperties.getPersist().isTokens()) {
        return;
    }
    // pull token details from TokenCreation body and TokenId from receipt
    TokenCreateTransactionBody tokenCreateTransactionBody = recordItem.getTransactionBody().getTokenCreation();
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    EntityId tokenId = EntityId.of(recordItem.getRecord().getReceipt().getTokenID());
    EntityId treasury = EntityId.of(tokenCreateTransactionBody.getTreasury());
    Token token = new Token();
    token.setCreatedTimestamp(consensusTimestamp);
    token.setDecimals(tokenCreateTransactionBody.getDecimals());
    token.setFreezeDefault(tokenCreateTransactionBody.getFreezeDefault());
    token.setInitialSupply(tokenCreateTransactionBody.getInitialSupply());
    token.setMaxSupply(tokenCreateTransactionBody.getMaxSupply());
    token.setModifiedTimestamp(consensusTimestamp);
    token.setName(tokenCreateTransactionBody.getName());
    token.setSupplyType(TokenSupplyTypeEnum.fromId(tokenCreateTransactionBody.getSupplyTypeValue()));
    token.setSymbol(tokenCreateTransactionBody.getSymbol());
    token.setTokenId(new TokenId(tokenId));
    token.setTotalSupply(tokenCreateTransactionBody.getInitialSupply());
    token.setTreasuryAccountId(treasury);
    token.setType(TokenTypeEnum.fromId(tokenCreateTransactionBody.getTokenTypeValue()));
    if (tokenCreateTransactionBody.hasFeeScheduleKey()) {
        token.setFeeScheduleKey(tokenCreateTransactionBody.getFeeScheduleKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasFreezeKey()) {
        token.setFreezeKey(tokenCreateTransactionBody.getFreezeKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasKycKey()) {
        token.setKycKey(tokenCreateTransactionBody.getKycKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasPauseKey()) {
        token.setPauseKey(tokenCreateTransactionBody.getPauseKey().toByteArray());
        token.setPauseStatus(TokenPauseStatusEnum.UNPAUSED);
    } else {
        token.setPauseStatus(TokenPauseStatusEnum.NOT_APPLICABLE);
    }
    if (tokenCreateTransactionBody.hasSupplyKey()) {
        token.setSupplyKey(tokenCreateTransactionBody.getSupplyKey().toByteArray());
    }
    if (tokenCreateTransactionBody.hasWipeKey()) {
        token.setWipeKey(tokenCreateTransactionBody.getWipeKey().toByteArray());
    }
    Set<EntityId> autoAssociatedAccounts = insertCustomFees(tokenCreateTransactionBody.getCustomFeesList(), consensusTimestamp, true, tokenId);
    autoAssociatedAccounts.add(treasury);
    if (recordItem.getRecord().getAutomaticTokenAssociationsCount() > 0) {
        // automatic_token_associations does not exist prior to services 0.18.0
        autoAssociatedAccounts.clear();
        recordItem.getRecord().getAutomaticTokenAssociationsList().stream().map(TokenAssociation::getAccountId).map(EntityId::of).forEach(autoAssociatedAccounts::add);
    }
    TokenFreezeStatusEnum freezeStatus = token.getFreezeKey() != null ? TokenFreezeStatusEnum.UNFROZEN : TokenFreezeStatusEnum.NOT_APPLICABLE;
    TokenKycStatusEnum kycStatus = token.getKycKey() != null ? TokenKycStatusEnum.GRANTED : TokenKycStatusEnum.NOT_APPLICABLE;
    autoAssociatedAccounts.forEach(account -> {
        TokenAccount tokenAccount = getAssociatedTokenAccount(account, false, consensusTimestamp, freezeStatus, kycStatus, tokenId);
        entityListener.onTokenAccount(tokenAccount);
    });
    entityListener.onToken(token);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenAssociation(com.hederahashgraph.api.proto.java.TokenAssociation) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)

Example 33 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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 34 with EntityId

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

the class EntityRecordItemListener method insertTransferList.

private void insertTransferList(RecordItem recordItem) {
    long consensusTimestamp = recordItem.getConsensusTimestamp();
    var transferList = recordItem.getRecord().getTransferList();
    EntityId payerAccountId = recordItem.getPayerAccountId();
    var body = recordItem.getTransactionBody();
    boolean failedTransfer = !recordItem.isSuccessful() && body.hasCryptoTransfer();
    for (int i = 0; i < transferList.getAccountAmountsCount(); ++i) {
        var aa = transferList.getAccountAmounts(i);
        var account = EntityId.of(aa.getAccountID());
        CryptoTransfer cryptoTransfer = new CryptoTransfer();
        cryptoTransfer.setAmount(aa.getAmount());
        cryptoTransfer.setConsensusTimestamp(consensusTimestamp);
        cryptoTransfer.setEntityId(account.getId());
        cryptoTransfer.setIsApproval(false);
        cryptoTransfer.setPayerAccountId(payerAccountId);
        AccountAmount accountAmountInsideBody = null;
        if (cryptoTransfer.getAmount() < 0 || failedTransfer) {
            accountAmountInsideBody = findAccountAmount(aa, body);
        }
        if (accountAmountInsideBody != null) {
            cryptoTransfer.setIsApproval(accountAmountInsideBody.getIsApproval());
            if (failedTransfer) {
                cryptoTransfer.setErrata(ErrataType.DELETE);
            }
        }
        entityListener.onCryptoTransfer(cryptoTransfer);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 35 with EntityId

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

the class EntityRecordItemListener method insertTokenAssociate.

private void insertTokenAssociate(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        TokenAssociateTransactionBody transactionBody = recordItem.getTransactionBody().getTokenAssociate();
        EntityId accountId = EntityId.of(transactionBody.getAccount());
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        transactionBody.getTokensList().forEach(token -> {
            EntityId tokenId = EntityId.of(token);
            TokenAccount tokenAccount = getAssociatedTokenAccount(accountId, false, consensusTimestamp, tokenId);
            entityListener.onTokenAccount(tokenAccount);
        });
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody)

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