Search in sources :

Example 1 with FileUpdateTransactionBody

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);
}
Also used : StringValue(com.google.protobuf.StringValue) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) EMPTY_MAP(java.util.Collections.EMPTY_MAP) EMPTY_SET(java.util.Collections.EMPTY_SET) Map(java.util.Map) KeyList(com.hederahashgraph.api.proto.java.KeyList) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ONE_HBAR(com.hedera.services.bdd.suites.HapiApiSuite.ONE_HBAR) ByteString(com.google.protobuf.ByteString) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ExchangeRateSet(com.hederahashgraph.api.proto.java.ExchangeRateSet) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiGetFileInfo(com.hedera.services.bdd.spec.queries.file.HapiGetFileInfo) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Function(java.util.function.Function) Setting(com.hederahashgraph.api.proto.java.Setting) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) ExtantFileContext(com.hedera.services.usage.file.ExtantFileContext) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MoreObjects(com.google.common.base.MoreObjects) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) File(java.io.File) HapiGetFileContents(com.hedera.services.bdd.spec.queries.file.HapiGetFileContents) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) Assertions(org.junit.jupiter.api.Assertions) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Setting(com.hederahashgraph.api.proto.java.Setting) ByteString(com.google.protobuf.ByteString) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) OptionalLong(java.util.OptionalLong) File(java.io.File) Key(com.hederahashgraph.api.proto.java.Key) HashSet(java.util.HashSet)

Example 2 with FileUpdateTransactionBody

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()));
}
Also used : FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) Entity(com.hedera.mirror.common.domain.entity.Entity) 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) 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)

Example 3 with FileUpdateTransactionBody

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

Example 4 with FileUpdateTransactionBody

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()));
}
Also used : FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) Entity(com.hedera.mirror.common.domain.entity.Entity) 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) 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)

Example 5 with FileUpdateTransactionBody

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()));
}
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) FileID(com.hederahashgraph.api.proto.java.FileID) 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

FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)7 Transaction (com.hederahashgraph.api.proto.java.Transaction)7 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)7 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)6 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)6 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)6 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 Entity (com.hedera.mirror.common.domain.entity.Entity)2 FileID (com.hederahashgraph.api.proto.java.FileID)2 MoreObjects (com.google.common.base.MoreObjects)1 Files (com.google.common.io.Files)1 ByteString (com.google.protobuf.ByteString)1 StringValue (com.google.protobuf.StringValue)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)1 QueryVerbs.getFileContents (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents)1 QueryVerbs.getFileInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo)1