use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class AbstractDownloaderTest method loadAddressBook.
protected static AddressBook loadAddressBook(String filename) throws IOException {
Path addressBookPath = ResourceUtils.getFile(String.format("classpath:addressbook/%s", filename)).toPath();
byte[] addressBookBytes = Files.readAllBytes(addressBookPath);
EntityId entityId = EntityId.of(0, 0, 102, EntityType.FILE);
long now = Instant.now().getEpochSecond();
return AddressBookServiceImpl.buildAddressBook(new FileData(now, addressBookBytes, entityId, TransactionType.FILECREATE.getProtoId()));
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class MissingAddressBooksMigrationTest method createAndStoreFileData.
private FileData createAndStoreFileData(byte[] contents, long consensusTimeStamp, boolean is102, TransactionType transactionType) {
EntityId entityId = is102 ? AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID : AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID;
FileData fileData = new FileData(consensusTimeStamp, contents, entityId, transactionType.getProtoId());
return fileDataRepository.save(fileData);
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method update.
private void update(byte[] contents, long consensusTimeStamp, boolean is102) {
FileData fileData = createFileData(contents, consensusTimeStamp, is102, TransactionType.FILEUPDATE);
addressBookService.update(fileData);
fileDataRepository.save(fileData);
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImpl method parse.
/**
* Parses provided fileData object into an AddressBook object if valid and stores into db. Also updates previous
* address book endConsensusTimestamp based on new address book's startConsensusTimestamp.
*
* @param fileData file data with timestamp, contents, entityId and transaction type for parsing
* @return Parsed AddressBook from fileData object
*/
private AddressBook parse(FileData fileData) {
if (addressBookRepository.existsById(getAddressBookStartConsensusTimestamp(fileData))) {
// skip as address book already exists
log.info("Address book from fileData {} already exists, skip parsing", fileData);
return null;
}
byte[] addressBookBytes = null;
if (fileData.transactionTypeIsAppend()) {
// concatenate bytes from partial address book file data in db
addressBookBytes = combinePreviousFileDataContents(fileData);
} else {
addressBookBytes = fileData.getFileData();
}
var addressBook = buildAddressBook(new FileData(fileData.getConsensusTimestamp(), addressBookBytes, fileData.getEntityId(), fileData.getTransactionType()));
if (addressBook != null) {
addressBook = addressBookRepository.save(addressBook);
log.info("Saved new address book to db: {}", addressBook);
// update previous addressBook
updatePreviousAddressBook(fileData);
}
return addressBook;
}
use of com.hedera.mirror.common.domain.file.FileData in project hedera-mirror-node by hashgraph.
the class FileDataRepositoryTest method findFilesOfTransactionTypesInRange.
@Test
void findFilesOfTransactionTypesInRange() {
List<FileData> fileDataList = new ArrayList<>();
fileDataList.add(fileData(1, 123, TransactionType.FILECREATE.getProtoId()));
FileData fileData = fileData(2, ADDRESS_BOOK_102.getId(), TransactionType.FILEUPDATE.getProtoId());
fileDataList.add(fileData);
fileDataList.add(fileData(3, ADDRESS_BOOK_102.getId(), TransactionType.FILEAPPEND.getProtoId()));
fileDataList.add(fileData(4, ADDRESS_BOOK_102.getId(), TransactionType.FILEAPPEND.getProtoId()));
fileDataList.add(fileData(5, ADDRESS_BOOK_102.getId(), TransactionType.FILEAPPEND.getProtoId()));
fileDataList.add(fileData(6, 123, TransactionType.FILEUPDATE.getProtoId()));
fileDataList.add(fileData(7, 123, TransactionType.FILEAPPEND.getProtoId()));
fileDataRepository.saveAll(fileDataList);
List<Integer> transactionTypes = List.of(TransactionType.FILECREATE.getProtoId(), TransactionType.FILEUPDATE.getProtoId());
Assertions.assertThat(fileDataRepository.findLatestMatchingFile(5, ADDRESS_BOOK_102.getId(), transactionTypes)).get().isNotNull().isEqualTo(fileData);
}
Aggregations