Search in sources :

Example 1 with ImporterException

use of com.hedera.mirror.importer.exception.ImporterException 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)

Example 2 with ImporterException

use of com.hedera.mirror.importer.exception.ImporterException in project hedera-mirror-node by hashgraph.

the class AbstractPreV5RecordFileReader method read.

@Override
public RecordFile read(@NonNull StreamFileData streamFileData) {
    String filename = streamFileData.getFilename();
    try (RecordFileDigest digest = getRecordFileDigest(streamFileData.getInputStream());
        ValidatedDataInputStream vdis = new ValidatedDataInputStream(digest.getDigestInputStream(), filename)) {
        RecordFile recordFile = new RecordFile();
        recordFile.setBytes(streamFileData.getBytes());
        recordFile.setLoadStart(Instant.now().getEpochSecond());
        recordFile.setName(filename);
        recordFile.setDigestAlgorithm(DIGEST_ALGORITHM);
        readHeader(vdis, recordFile);
        readBody(vdis, digest, recordFile);
        return recordFile;
    } catch (ImporterException e) {
        throw e;
    } catch (Exception e) {
        throw new StreamFileReaderException("Error reading record file " + filename, e);
    }
}
Also used : ImporterException(com.hedera.mirror.importer.exception.ImporterException) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ValidatedDataInputStream(com.hedera.mirror.importer.reader.ValidatedDataInputStream) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ImporterException(com.hedera.mirror.importer.exception.ImporterException)

Aggregations

ImporterException (com.hedera.mirror.importer.exception.ImporterException)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 FileData (com.hedera.mirror.common.domain.file.FileData)1 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)1 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)1 InvalidEntityException (com.hedera.mirror.common.exception.InvalidEntityException)1 ParserException (com.hedera.mirror.importer.exception.ParserException)1 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)1 PubSubMessage (com.hedera.mirror.importer.parser.domain.PubSubMessage)1 TransactionHandler (com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler)1 ValidatedDataInputStream (com.hedera.mirror.importer.reader.ValidatedDataInputStream)1 FileID (com.hederahashgraph.api.proto.java.FileID)1 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 MessageTimeoutException (org.springframework.integration.MessageTimeoutException)1