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);
}
}
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);
}
}
Aggregations