Search in sources :

Example 86 with EntityId

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

the class EntityRecordItemListener method insertAssessedCustomFees.

private void insertAssessedCustomFees(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        for (var protoAssessedCustomFee : recordItem.getRecord().getAssessedCustomFeesList()) {
            EntityId collectorAccountId = EntityId.of(protoAssessedCustomFee.getFeeCollectorAccountId());
            // the effective payers must also appear in the *transfer lists of this transaction and the
            // corresponding EntityIds should have been added to EntityListener, so skip it here.
            List<EntityId> payerEntityIds = protoAssessedCustomFee.getEffectivePayerAccountIdList().stream().map(EntityId::of).collect(Collectors.toList());
            AssessedCustomFee assessedCustomFee = new AssessedCustomFee();
            assessedCustomFee.setAmount(protoAssessedCustomFee.getAmount());
            assessedCustomFee.setEffectivePayerEntityIds(payerEntityIds);
            assessedCustomFee.setId(new AssessedCustomFee.Id(collectorAccountId, consensusTimestamp));
            assessedCustomFee.setTokenId(EntityId.of(protoAssessedCustomFee.getTokenId()));
            assessedCustomFee.setPayerAccountId(recordItem.getPayerAccountId());
            entityListener.onAssessedCustomFee(assessedCustomFee);
        }
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee)

Example 87 with EntityId

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

the class EntityRecordItemListener method insertTokenBurn.

private void insertTokenBurn(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        TokenBurnTransactionBody tokenBurnTransactionBody = recordItem.getTransactionBody().getTokenBurn();
        EntityId tokenId = EntityId.of(tokenBurnTransactionBody.getToken());
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        updateTokenSupply(tokenId, recordItem.getRecord().getReceipt().getNewTotalSupply(), consensusTimestamp);
        tokenBurnTransactionBody.getSerialNumbersList().forEach(serialNumber -> updateNftDeleteStatus(consensusTimestamp, serialNumber, tokenId));
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody)

Example 88 with EntityId

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

the class EntityRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionBody body = recordItem.getTransactionBody();
    int transactionTypeValue = recordItem.getTransactionType();
    TransactionType transactionType = TransactionType.of(transactionTypeValue);
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    long consensusTimestamp = DomainUtils.timeStampInNanos(txRecord.getConsensusTimestamp());
    EntityId entityId;
    try {
        entityId = transactionHandler.getEntity(recordItem);
    } catch (InvalidEntityException e) {
        // transaction can have invalid topic/contract/file id
        log.warn("Invalid entity encountered for consensusTimestamp {} : {}", consensusTimestamp, e.getMessage());
        entityId = null;
    }
    log.debug("Processing {} transaction {} for entity {}", transactionType, consensusTimestamp, entityId);
    // to:do - exclude Freeze from Filter transaction type
    TransactionFilterFields transactionFilterFields = new TransactionFilterFields(entityId, transactionType);
    if (!transactionFilter.test(transactionFilterFields)) {
        log.debug("Ignoring transaction. consensusTimestamp={}, transactionType={}, entityId={}", consensusTimestamp, transactionType, entityId);
        return;
    }
    Transaction transaction = buildTransaction(consensusTimestamp, recordItem);
    transaction.setEntityId(entityId);
    transactionHandler.updateTransaction(transaction, recordItem);
    if (txRecord.hasTransferList() && entityProperties.getPersist().isCryptoTransferAmounts()) {
        insertTransferList(recordItem);
    }
    // insert staking reward transfers even on failure
    insertStakingRewardTransfers(recordItem);
    // handle scheduled transaction, even on failure
    if (transaction.isScheduled()) {
        onScheduledTransaction(recordItem);
    }
    if (recordItem.isSuccessful()) {
        if (entityProperties.getPersist().getTransactionSignatures().contains(transactionType)) {
            insertTransactionSignatures(transaction.getEntityId(), recordItem.getConsensusTimestamp(), recordItem.getSignatureMap().getSigPairList());
        }
        // Only add non-fee transfers on success as the data is assured to be valid
        processNonFeeTransfers(consensusTimestamp, recordItem);
        if (body.hasConsensusSubmitMessage()) {
            insertConsensusTopicMessage(recordItem);
        } else if (body.hasCryptoAddLiveHash()) {
            insertCryptoAddLiveHash(consensusTimestamp, body.getCryptoAddLiveHash());
        } else if (body.hasFileAppend()) {
            insertFileAppend(consensusTimestamp, body.getFileAppend(), transactionTypeValue);
        } else if (body.hasFileCreate()) {
            insertFileData(consensusTimestamp, DomainUtils.toBytes(body.getFileCreate().getContents()), txRecord.getReceipt().getFileID(), transactionTypeValue);
        } else if (body.hasFileUpdate()) {
            insertFileUpdate(consensusTimestamp, body.getFileUpdate(), transactionTypeValue);
        } else if (body.hasTokenAssociate()) {
            insertTokenAssociate(recordItem);
        } else if (body.hasTokenBurn()) {
            insertTokenBurn(recordItem);
        } else if (body.hasTokenCreation()) {
            insertTokenCreate(recordItem);
        } else if (body.hasTokenDissociate()) {
            insertTokenDissociate(recordItem);
        } else if (body.hasTokenFeeScheduleUpdate()) {
            insertTokenFeeScheduleUpdate(recordItem);
        } else if (body.hasTokenFreeze()) {
            insertTokenAccountFreezeBody(recordItem);
        } else if (body.hasTokenGrantKyc()) {
            insertTokenAccountGrantKyc(recordItem);
        } else if (body.hasTokenMint()) {
            insertTokenMint(recordItem);
        } else if (body.hasTokenPause()) {
            insertTokenPause(recordItem);
        } else if (body.hasTokenRevokeKyc()) {
            insertTokenAccountRevokeKyc(recordItem);
        } else if (body.hasTokenUnfreeze()) {
            insertTokenAccountUnfreeze(recordItem);
        } else if (body.hasTokenUnpause()) {
            insertTokenUnpause(recordItem);
        } else if (body.hasTokenUpdate()) {
            insertTokenUpdate(recordItem);
        } else if (body.hasTokenWipe()) {
            insertTokenAccountWipe(recordItem);
        }
        // Record token transfers can be populated for multiple transaction types
        insertTokenTransfers(recordItem);
        insertAssessedCustomFees(recordItem);
        insertAutomaticTokenAssociations(recordItem);
    }
    contractResultService.process(recordItem, transaction);
    entityListener.onTransaction(transaction);
    log.debug("Storing transaction: {}", transaction);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) TokenRevokeKycTransactionBody(com.hederahashgraph.api.proto.java.TokenRevokeKycTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TokenPauseTransactionBody(com.hederahashgraph.api.proto.java.TokenPauseTransactionBody) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) TokenGrantKycTransactionBody(com.hederahashgraph.api.proto.java.TokenGrantKycTransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenUnfreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenUnfreezeAccountTransactionBody) TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) TokenDissociateTransactionBody(com.hederahashgraph.api.proto.java.TokenDissociateTransactionBody) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) TokenFreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenFreezeAccountTransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) TransactionFilterFields(com.hedera.mirror.importer.domain.TransactionFilterFields) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException)

Example 89 with EntityId

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

the class EntityRecordItemListener method insertTokenAccountFreezeBody.

private void insertTokenAccountFreezeBody(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        TokenFreezeAccountTransactionBody transactionBody = recordItem.getTransactionBody().getTokenFreeze();
        EntityId tokenId = EntityId.of(transactionBody.getToken());
        EntityId accountId = EntityId.of(transactionBody.getAccount());
        TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, recordItem.getConsensusTimestamp());
        tokenAccount.setFreezeStatus(TokenFreezeStatusEnum.FROZEN);
        entityListener.onTokenAccount(tokenAccount);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenFreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenFreezeAccountTransactionBody)

Example 90 with EntityId

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

the class EntityRecordItemListener method insertTokenAccountGrantKyc.

private void insertTokenAccountGrantKyc(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        TokenGrantKycTransactionBody transactionBody = recordItem.getTransactionBody().getTokenGrantKyc();
        EntityId tokenId = EntityId.of(transactionBody.getToken());
        EntityId accountId = EntityId.of(transactionBody.getAccount());
        TokenAccount tokenAccount = new TokenAccount(tokenId, accountId, recordItem.getConsensusTimestamp());
        tokenAccount.setKycStatus(TokenKycStatusEnum.GRANTED);
        entityListener.onTokenAccount(tokenAccount);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) TokenGrantKycTransactionBody(com.hederahashgraph.api.proto.java.TokenGrantKycTransactionBody)

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