Search in sources :

Example 1 with FileAppendTransactionBody

use of com.hederahashgraph.api.proto.java.FileAppendTransactionBody in project hedera-services by hashgraph.

the class HapiFileAppend method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (contentsSupplier.isPresent()) {
        contents = Optional.of(contentsSupplier.get().get());
    } else if (path.isPresent()) {
        contents = Optional.of(Files.toByteArray(new File(path.get())));
    }
    var fid = TxnUtils.asFileId(file, spec);
    FileAppendTransactionBody opBody = spec.txns().<FileAppendTransactionBody, FileAppendTransactionBody.Builder>body(FileAppendTransactionBody.class, builder -> {
        builder.setFileID(fid);
        contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
    });
    preAppendCb.ifPresent(cb -> cb.accept(fid));
    return b -> b.setFileAppend(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FileAppendMeta(com.hedera.services.usage.file.FileAppendMeta) Function(java.util.function.Function) Supplier(java.util.function.Supplier) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) File(java.io.File) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TxnUtils.currExpiry(com.hedera.services.bdd.spec.transactions.TxnUtils.currExpiry) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) File(java.io.File)

Example 2 with FileAppendTransactionBody

use of com.hederahashgraph.api.proto.java.FileAppendTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerFileTest method fileAppendToAddressBook.

@Test
void fileAppendToAddressBook() throws IOException {
    entityProperties.getPersist().setFiles(true);
    entityProperties.getPersist().setSystemFiles(true);
    byte[] addressBook = FileUtils.readFileToByteArray(addressBookLarge);
    byte[] addressBookUpdate = Arrays.copyOf(addressBook, 6144);
    byte[] addressBookAppend = Arrays.copyOfRange(addressBook, 6144, addressBook.length);
    // Initial address book update
    Transaction transactionUpdate = fileUpdateAllTransaction(ADDRESS_BOOK_FILEID, addressBookUpdate);
    TransactionBody transactionBodyUpdate = getTransactionBody(transactionUpdate);
    FileUpdateTransactionBody fileUpdateTransactionBody = transactionBodyUpdate.getFileUpdate();
    TransactionRecord recordUpdate = transactionRecord(transactionBodyUpdate, ADDRESS_BOOK_FILEID);
    // Address book append
    Transaction transactionAppend = fileAppendTransaction(ADDRESS_BOOK_FILEID, addressBookAppend);
    TransactionBody transactionBodyAppend = getTransactionBody(transactionAppend);
    FileAppendTransactionBody fileAppendTransactionBody = transactionBodyAppend.getFileAppend();
    TransactionRecord recordAppend = transactionRecord(transactionBodyAppend, ADDRESS_BOOK_FILEID);
    parseRecordItemAndCommit(new RecordItem(transactionUpdate, recordUpdate));
    parseRecordItemAndCommit(new RecordItem(transactionAppend, recordAppend));
    // verify current address book is updated
    AddressBook newAddressBook = addressBookService.getCurrent();
    assertAll(() -> assertThat(newAddressBook.getStartConsensusTimestamp()).isEqualTo(DomainUtils.timeStampInNanos(recordAppend.getConsensusTimestamp()) + 1), () -> assertThat(newAddressBook.getEntries()).describedAs("Should overwrite address book with new update").hasSize(13), () -> assertArrayEquals(addressBook, newAddressBook.getFileData()));
    assertAll(() -> assertRowCountOnAddressBookTransactions(), () -> assertTransactionAndRecord(transactionBodyUpdate, recordUpdate), () -> assertTransactionAndRecord(transactionBodyAppend, recordAppend), () -> assertFileData(fileAppendTransactionBody.getContents(), recordAppend.getConsensusTimestamp()), () -> assertFileData(fileUpdateTransactionBody.getContents(), recordUpdate.getConsensusTimestamp()), () -> assertAddressBookData(addressBook, recordAppend.getConsensusTimestamp()), () -> assertEquals(13 + TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT, addressBookEntryRepository.count()), () -> assertEquals(2, addressBookRepository.count()), // update and append
    () -> assertEquals(2, fileDataRepository.count()));
}
Also used : FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 MoreObjects (com.google.common.base.MoreObjects)1 Files (com.google.common.io.Files)1 ByteString (com.google.protobuf.ByteString)1 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.currExpiry (com.hedera.services.bdd.spec.transactions.TxnUtils.currExpiry)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1 FileAppendMeta (com.hedera.services.usage.file.FileAppendMeta)1 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)1 FeeData (com.hederahashgraph.api.proto.java.FeeData)1 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)1