use of com.hederahashgraph.api.proto.java.FileUpdateTransactionBody in project hedera-services by hashgraph.
the class HapiFileUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
Optional<Key> wacl = useBadlyEncodedWacl ? Optional.of(badlyEncodedWacl()) : (useEmptyWacl ? Optional.of(emptyWacl()) : newWaclKey.map(spec.registry()::getKey));
if (newContentsPath.isPresent()) {
newContents = Optional.of(ByteString.copyFrom(Files.toByteArray(new File(newContentsPath.get()))));
} else if (contentFn.isPresent()) {
newContents = Optional.of(contentFn.get().apply(spec));
} else if (propOverrides.isPresent() || propDeletions.isPresent()) {
if (propOverrides.isEmpty()) {
propOverrides = Optional.of(Collections.emptyMap());
}
ServicesConfigurationList defaults = readBaseProps(spec);
ServicesConfigurationList.Builder list = ServicesConfigurationList.newBuilder();
Map<String, String> overrides = propOverrides.get();
Map<String, String> defaultPairs = defaults.getNameValueList().stream().collect(Collectors.toMap(Setting::getName, Setting::getValue));
Set<String> keys = new HashSet<>();
defaults.getNameValueList().stream().map(Setting::getName).filter(key -> !propDeletions.orElse(EMPTY_SET).contains(key)).forEach(keys::add);
overrides.keySet().stream().forEach(keys::add);
keys.forEach(key -> {
if (overrides.containsKey(key)) {
list.addNameValue(asSetting(key, overrides.get(key)));
} else {
list.addNameValue(asSetting(key, defaultPairs.get(key)));
}
});
newContents = Optional.of(list.build().toByteString());
}
long nl = -1;
if (expiryExtension.isPresent()) {
try {
var oldExpiry = spec.registry().getTimestamp(file).getSeconds();
nl = oldExpiry - Instant.now().getEpochSecond() + expiryExtension.getAsLong();
} catch (Exception ignore) {
}
} else if (lifetimeSecs.isPresent()) {
nl = lifetimeSecs.get();
}
final OptionalLong newLifetime = (nl == -1) ? OptionalLong.empty() : OptionalLong.of(nl);
var fid = TxnUtils.asFileId(file, spec);
FileUpdateTransactionBody opBody = spec.txns().<FileUpdateTransactionBody, FileUpdateTransactionBody.Builder>body(FileUpdateTransactionBody.class, builder -> {
builder.setFileID(fid);
newMemo.ifPresent(s -> builder.setMemo(StringValue.newBuilder().setValue(s).build()));
wacl.ifPresent(k -> builder.setKeys(k.getKeyList()));
newContents.ifPresent(b -> builder.setContents(b));
newLifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
});
preUpdateCb.ifPresent(cb -> cb.accept(fid));
return builder -> builder.setFileUpdate(opBody);
}
use of com.hederahashgraph.api.proto.java.FileUpdateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerFileTest method fileUpdateKeysToExisting.
@Test
void fileUpdateKeysToExisting() {
// first create the file
Transaction fileCreateTransaction = fileCreateTransaction();
TransactionBody createTransactionBody = getTransactionBody(fileCreateTransaction);
TransactionRecord recordCreate = transactionRecord(createTransactionBody);
parseRecordItemAndCommit(new RecordItem(fileCreateTransaction, recordCreate));
// now update
Transaction transaction = fileUpdateKeysTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = transactionRecord(transactionBody);
FileUpdateTransactionBody fileUpdateTransactionBody = transactionBody.getFileUpdate();
parseRecordItemAndCommit(new RecordItem(transaction, record));
Entity dbFileEntity = getTransactionEntity(record.getConsensusTimestamp());
assertAll(// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
() -> assertRowCountOnTwoFileTransactions(), () -> assertTransactionAndRecord(transactionBody, record), // Additional entity checks
() -> assertFalse(dbFileEntity.getDeleted()), () -> assertNotNull(dbFileEntity.getExpirationTimestamp()), () -> assertArrayEquals(fileUpdateTransactionBody.getKeys().toByteArray(), dbFileEntity.getKey()), () -> assertNull(dbFileEntity.getAutoRenewPeriod()), () -> assertNull(dbFileEntity.getProxyAccountId()));
}
use of com.hederahashgraph.api.proto.java.FileUpdateTransactionBody 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()));
}
use of com.hederahashgraph.api.proto.java.FileUpdateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerFileTest method fileUpdateKeysToNew.
@Test
void fileUpdateKeysToNew() {
Transaction transaction = fileUpdateKeysTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
FileUpdateTransactionBody fileUpdateTransactionBody = transactionBody.getFileUpdate();
TransactionRecord record = transactionRecord(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
Entity dbFileEntity = getTransactionEntity(record.getConsensusTimestamp());
assertAll(// TODO: Review row count in fileDataRepository with issue #294, probably should be 0
() -> assertRowCountOnSuccess(FILE_ID), () -> assertTransactionAndRecord(transactionBody, record), // Additional entity checks
() -> assertFalse(dbFileEntity.getDeleted()), () -> assertNull(dbFileEntity.getExpirationTimestamp()), () -> assertArrayEquals(fileUpdateTransactionBody.getKeys().toByteArray(), dbFileEntity.getKey()), () -> assertNull(dbFileEntity.getAutoRenewPeriod()), () -> assertNull(dbFileEntity.getProxyAccountId()));
}
use of com.hederahashgraph.api.proto.java.FileUpdateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerFileTest method fileUpdateAllToNewSystem.
@Test
void fileUpdateAllToNewSystem() {
FileID fileID = FileID.newBuilder().setShardNum(0).setRealmNum(0).setFileNum(10).build();
Transaction transaction = fileUpdateAllTransaction(fileID, FILE_CONTENTS);
TransactionBody transactionBody = getTransactionBody(transaction);
FileUpdateTransactionBody fileUpdateTransactionBody = transactionBody.getFileUpdate();
TransactionRecord record = transactionRecord(transactionBody, fileID);
entityProperties.getPersist().setFiles(true);
entityProperties.getPersist().setSystemFiles(true);
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertRowCountOnSuccess(fileID), () -> assertTransactionAndRecord(transactionBody, record), () -> assertFileEntityAndData(fileUpdateTransactionBody, record.getConsensusTimestamp()));
}
Aggregations