use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onFileData.
@Test
void onFileData() {
// given
FileData expectedFileData = new FileData(11L, Strings.toByteArray("file data"), EntityId.of(0, 0, 111, EntityType.FILE), TransactionType.CONSENSUSSUBMITMESSAGE.getProtoId());
// when
sqlEntityListener.onFileData(expectedFileData);
completeFileAndCommit();
// then
assertThat(fileDataRepository.findAll()).containsExactlyInAnyOrder(expectedFileData);
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class PubSubRecordItemListenerTest method testNetworkAddressBookUpdate.
@Test
void testNetworkAddressBookUpdate() throws Exception {
// given
byte[] fileContents = UPDATED.toByteArray();
var fileUpdate = FileUpdateTransactionBody.newBuilder().setFileID(ADDRESS_BOOK_FILE_ID).setContents(ByteString.copyFrom(fileContents)).build();
Transaction transaction = buildTransaction(builder -> builder.setFileUpdate(fileUpdate));
// when
doReturn(EntityId.of(ADDRESS_BOOK_FILE_ID)).when(transactionHandler).getEntity(any());
pubSubRecordItemListener.onItem(new RecordItem(transaction, DEFAULT_RECORD));
// then
FileData fileData = new FileData(100L, fileContents, EntityId.of(ADDRESS_BOOK_FILE_ID), TransactionType.FILEUPDATE.getProtoId());
verify(addressBookService).update(fileData);
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class FileDataRepositoryTest method fileData.
private FileData fileData(long consensusTimestamp, long fileId, int transactionType) {
FileData fileData = new FileData();
fileData.setConsensusTimestamp(consensusTimestamp);
fileData.setFileData("some file data".getBytes());
fileData.setEntityId(EntityId.of(0, 0, fileId, EntityType.FILE));
fileData.setTransactionType(transactionType);
return fileData;
}
use of com.hedera.mirror.common.domain.file.FileData 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);
}
}
use of com.hedera.mirror.common.domain.file.FileData 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);
}
}
Aggregations