Search in sources :

Example 11 with FileData

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()));
}
Also used : Path(java.nio.file.Path) EntityId(com.hedera.mirror.common.domain.entity.EntityId) FileData(com.hedera.mirror.common.domain.file.FileData)

Example 12 with FileData

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) FileData(com.hedera.mirror.common.domain.file.FileData)

Example 13 with 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);
}
Also used : FileData(com.hedera.mirror.common.domain.file.FileData)

Example 14 with 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;
}
Also used : FileData(com.hedera.mirror.common.domain.file.FileData)

Example 15 with FileData

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);
}
Also used : ArrayList(java.util.ArrayList) FileData(com.hedera.mirror.common.domain.file.FileData) Test(org.junit.jupiter.api.Test)

Aggregations

FileData (com.hedera.mirror.common.domain.file.FileData)17 EntityId (com.hedera.mirror.common.domain.entity.EntityId)5 Test (org.junit.jupiter.api.Test)4 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)2 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)2 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)2 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)1 InvalidEntityException (com.hedera.mirror.common.exception.InvalidEntityException)1 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)1 ImporterException (com.hedera.mirror.importer.exception.ImporterException)1 ParserException (com.hedera.mirror.importer.exception.ParserException)1 PubSubMessage (com.hedera.mirror.importer.parser.domain.PubSubMessage)1 TransactionHandler (com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler)1 FileID (com.hederahashgraph.api.proto.java.FileID)1 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1