Search in sources :

Example 36 with EntityId

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

the class EntityRecordItemListener method insertTokenAccountRevokeKyc.

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

Example 37 with EntityId

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

the class EntityRecordItemListener method insertAutomaticTokenAssociations.

private void insertAutomaticTokenAssociations(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        if (recordItem.getTransactionBody().hasTokenCreation()) {
            // automatic token associations for token create transactions are handled in insertTokenCreate
            return;
        }
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        recordItem.getRecord().getAutomaticTokenAssociationsList().forEach(tokenAssociation -> {
            // the only other transaction which creates auto associations is crypto transfer. The accounts and
            // tokens in the associations should have been added to EntityListener when inserting the corresponding
            // token transfers, so no need to duplicate the logic here
            EntityId accountId = EntityId.of(tokenAssociation.getAccountId());
            EntityId tokenId = EntityId.of(tokenAssociation.getTokenId());
            TokenAccount tokenAccount = getAssociatedTokenAccount(accountId, true, consensusTimestamp, tokenId);
            entityListener.onTokenAccount(tokenAccount);
        });
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount)

Example 38 with EntityId

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

the class EntityRecordItemListener method insertFileData.

private void insertFileData(long consensusTimestamp, byte[] contents, FileID fileID, int transactionTypeValue) {
    EntityId entityId = EntityId.of(fileID);
    FileData fileData = new FileData(consensusTimestamp, contents, entityId, transactionTypeValue);
    // We always store file data for address books since they're used by the address book service
    if (addressBookService.isAddressBook(entityId)) {
        fileDataRepository.save(fileData);
        addressBookService.update(fileData);
    } else if (entityProperties.getPersist().isFiles() || (entityProperties.getPersist().isSystemFiles() && entityId.getEntityNum() < 1000)) {
        entityListener.onFileData(fileData);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) FileData(com.hedera.mirror.common.domain.file.FileData)

Example 39 with EntityId

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

the class EntityRecordItemListener method insertCustomFees.

/**
 * Inserts custom fees. Returns the list of collectors automatically associated with the newly created token if the
 * custom fees are from a token create transaction
 *
 * @param customFeeList      protobuf custom fee list
 * @param consensusTimestamp consensus timestamp of the corresponding transaction
 * @param isTokenCreate      if the transaction with the custom fees is a token create
 * @param tokenId            the token id the custom fees are attached to
 * @return A list of collectors automatically associated with the token if it's a token create transaction
 */
private Set<EntityId> insertCustomFees(List<com.hederahashgraph.api.proto.java.CustomFee> customFeeList, long consensusTimestamp, boolean isTokenCreate, EntityId tokenId) {
    Set<EntityId> autoAssociatedAccounts = new HashSet<>();
    CustomFee.Id id = new CustomFee.Id(consensusTimestamp, tokenId);
    for (var protoCustomFee : customFeeList) {
        EntityId collector = EntityId.of(protoCustomFee.getFeeCollectorAccountId());
        CustomFee customFee = new CustomFee();
        customFee.setId(id);
        customFee.setCollectorAccountId(collector);
        var feeCase = protoCustomFee.getFeeCase();
        boolean chargedInAttachedToken;
        switch(feeCase) {
            case FIXED_FEE:
                chargedInAttachedToken = parseFixedFee(customFee, protoCustomFee.getFixedFee(), tokenId);
                break;
            case FRACTIONAL_FEE:
                // only FT can have fractional fee
                parseFractionalFee(customFee, protoCustomFee.getFractionalFee());
                chargedInAttachedToken = true;
                break;
            case ROYALTY_FEE:
                // only NFT can have royalty fee, and fee can't be paid in NFT. Thus though royalty fee has a
                // fixed fee fallback, the denominating token of the fixed fee can't be the NFT itself
                parseRoyaltyFee(customFee, protoCustomFee.getRoyaltyFee(), tokenId);
                chargedInAttachedToken = false;
                break;
            default:
                log.error("Invalid CustomFee FeeCase {}", feeCase);
                throw new InvalidDatasetException(String.format("Invalid CustomFee FeeCase %s", feeCase));
        }
        if (isTokenCreate && chargedInAttachedToken) {
            // if it's from a token create transaction, and the fee is charged in the attached token, the attached
            // token and the collector should have been auto associated
            autoAssociatedAccounts.add(collector);
        }
        entityListener.onCustomFee(customFee);
    }
    if (customFeeList.isEmpty()) {
        // for empty custom fees, add a single row with only the timestamp and tokenId.
        CustomFee customFee = new CustomFee();
        customFee.setId(id);
        entityListener.onCustomFee(customFee);
    }
    return autoAssociatedAccounts;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) CustomFee(com.hedera.mirror.common.domain.transaction.CustomFee) AssessedCustomFee(com.hedera.mirror.common.domain.transaction.AssessedCustomFee) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenId(com.hedera.mirror.common.domain.token.TokenId) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) HashSet(java.util.HashSet)

Example 40 with EntityId

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

the class PubSubRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionBody body = recordItem.getTransactionBody();
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionType transactionType = TransactionType.of(recordItem.getTransactionType());
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body));
    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;
    }
    PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entityId, recordItem);
    try {
        sendPubSubMessage(pubSubMessage);
    } catch (Exception e) {
        // greater than that of last correctly sent txn.
        throw new ParserException("Error sending transaction to pubsub", e);
    }
    log.debug("Published transaction : {}", consensusTimestamp);
    if (addressBookService.isAddressBook(entityId)) {
        FileID fileID = null;
        byte[] fileBytes = null;
        if (body.hasFileAppend()) {
            fileID = body.getFileAppend().getFileID();
            fileBytes = body.getFileAppend().getContents().toByteArray();
        } else if (body.hasFileCreate()) {
            fileID = txRecord.getReceipt().getFileID();
            fileBytes = body.getFileCreate().getContents().toByteArray();
        } else if (body.hasFileUpdate()) {
            fileID = body.getFileUpdate().getFileID();
            fileBytes = body.getFileUpdate().getContents().toByteArray();
        }
        FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem.getTransactionType());
        fileDataRepository.save(fileData);
        addressBookService.update(fileData);
    }
}
Also used : ParserException(com.hedera.mirror.importer.exception.ParserException) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) MessageTimeoutException(org.springframework.integration.MessageTimeoutException) ParserException(com.hedera.mirror.importer.exception.ParserException) ImporterException(com.hedera.mirror.importer.exception.ImporterException) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) PubSubMessage(com.hedera.mirror.importer.parser.domain.PubSubMessage) FileID(com.hederahashgraph.api.proto.java.FileID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) FileData(com.hedera.mirror.common.domain.file.FileData)

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