Search in sources :

Example 1 with FileData

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

Example 2 with FileData

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);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) FileData(com.hedera.mirror.common.domain.file.FileData) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

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

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

Example 5 with 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);
    }
}
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)

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