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);
}
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()));
}
Aggregations