Search in sources :

Example 1 with TopicUpdateTransaction

use of com.hedera.hashgraph.sdk.TopicUpdateTransaction in project hedera-sdk-java by hashgraph.

the class TopicWithAdminKeyExample method updateTopicAdminKeyAndMemo.

private void updateTopicAdminKeyAndMemo() throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
    // Generate the new keys that are part of the adminKey's thresholdKey.
    // 4 ED25519 keys part of a 3-of-4 threshold key.
    PrivateKey[] newAdminKeys = new PrivateKey[4];
    J8Arrays.setAll(newAdminKeys, i -> PrivateKey.generate());
    KeyList thresholdKey = KeyList.withThreshold(3);
    Collections.addAll(thresholdKey, newAdminKeys);
    Transaction<?> transaction = new TopicUpdateTransaction().setTopicId(topicId).setTopicMemo("updated demo topic").setAdminKey(thresholdKey).freezeWith(hapiClient);
    // Sign with the initial adminKey. 2 of the 3 keys already part of the topic's adminKey.
    J8Arrays.stream(initialAdminKeys, 0, 2).forEach(k -> {
        System.out.println("Signing ConsensusTopicUpdateTransaction with initial admin key " + k);
        transaction.sign(k);
    });
    // Sign with the new adminKey. 3 of 4 keys already part of the topic's adminKey.
    J8Arrays.stream(newAdminKeys, 0, 3).forEach(k -> {
        System.out.println("Signing ConsensusTopicUpdateTransaction with new admin key " + k);
        transaction.sign(k);
    });
    TransactionResponse transactionResponse = transaction.execute(hapiClient);
    // Retrieve results post-consensus.
    transactionResponse.getReceipt(hapiClient);
    System.out.println("Updated topic " + topicId + " with 3-of-4 threshold key as adminKey");
    TopicInfo topicInfo = new TopicInfoQuery().setTopicId(topicId).execute(hapiClient);
    System.out.println(topicInfo);
}
Also used : TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) TopicInfoQuery(com.hedera.hashgraph.sdk.TopicInfoQuery) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) KeyList(com.hedera.hashgraph.sdk.KeyList) TopicInfo(com.hedera.hashgraph.sdk.TopicInfo)

Example 2 with TopicUpdateTransaction

use of com.hedera.hashgraph.sdk.TopicUpdateTransaction in project hedera-mirror-node by hashgraph.

the class TopicClient method updateTopic.

public NetworkTransactionResponse updateTopic(TopicId topicId) {
    String memo = getMemo("Update Topic");
    TopicUpdateTransaction consensusTopicUpdateTransaction = new TopicUpdateTransaction().setTopicId(topicId).setTopicMemo(memo).setAutoRenewPeriod(autoRenewPeriod).clearAdminKey().clearSubmitKey().clearAutoRenewAccountId().setMaxTransactionFee(sdkClient.getMaxTransactionFee()).setTransactionMemo(memo);
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(consensusTopicUpdateTransaction);
    log.debug("Updated topic '{}'.", topicId);
    return networkTransactionResponse;
}
Also used : TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)

Example 3 with TopicUpdateTransaction

use of com.hedera.hashgraph.sdk.TopicUpdateTransaction in project hedera-mirror-node by hashgraph.

the class ConsensusUpdateTopicTransactionSupplierTest method createWithCustomData.

@Test
void createWithCustomData() {
    PublicKey key = PrivateKey.generate().getPublicKey();
    Duration autoRenewPeriod = Duration.ofSeconds(1);
    ConsensusUpdateTopicTransactionSupplier consensusUpdateTopicTransactionSupplier = new ConsensusUpdateTopicTransactionSupplier();
    consensusUpdateTopicTransactionSupplier.setAdminKey(key.toString());
    consensusUpdateTopicTransactionSupplier.setAutoRenewAccountId("0.0.2");
    consensusUpdateTopicTransactionSupplier.setAutoRenewPeriod(autoRenewPeriod);
    consensusUpdateTopicTransactionSupplier.setMaxTransactionFee(1);
    consensusUpdateTopicTransactionSupplier.setTopicId(TOPIC_ID.toString());
    TopicUpdateTransaction actual = consensusUpdateTopicTransactionSupplier.get();
    assertThat(actual).returns(key, TopicUpdateTransaction::getAdminKey).returns(AccountId.fromString("0.0.2"), TopicUpdateTransaction::getAutoRenewAccountId).returns(autoRenewPeriod, TopicUpdateTransaction::getAutoRenewPeriod).returns(ONE_TINYBAR, TopicUpdateTransaction::getMaxTransactionFee).returns(key, TopicUpdateTransaction::getSubmitKey).returns(TOPIC_ID, TopicUpdateTransaction::getTopicId).extracting(TopicUpdateTransaction::getTopicMemo, STRING).contains("Mirror node updated test topic");
}
Also used : TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) PublicKey(com.hedera.hashgraph.sdk.PublicKey) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 4 with TopicUpdateTransaction

use of com.hedera.hashgraph.sdk.TopicUpdateTransaction in project hedera-mirror-node by hashgraph.

the class ConsensusUpdateTopicTransactionSupplierTest method createWithMinimumData.

@Test
void createWithMinimumData() {
    ConsensusUpdateTopicTransactionSupplier consensusUpdateTopicTransactionSupplier = new ConsensusUpdateTopicTransactionSupplier();
    consensusUpdateTopicTransactionSupplier.setTopicId(TOPIC_ID.toString());
    TopicUpdateTransaction actual = consensusUpdateTopicTransactionSupplier.get();
    assertThat(actual).returns(null, TopicUpdateTransaction::getAdminKey).returns(null, TopicUpdateTransaction::getAutoRenewAccountId).returns(null, TopicUpdateTransaction::getAutoRenewPeriod).returns(MAX_TRANSACTION_FEE_HBAR, TopicUpdateTransaction::getMaxTransactionFee).returns(null, TopicUpdateTransaction::getSubmitKey).returns(TOPIC_ID, TopicUpdateTransaction::getTopicId).extracting(TopicUpdateTransaction::getTopicMemo, STRING).contains("Mirror node updated test topic");
}
Also used : TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 5 with TopicUpdateTransaction

use of com.hedera.hashgraph.sdk.TopicUpdateTransaction in project hedera-mirror-node by hashgraph.

the class ConsensusUpdateTopicTransactionSupplier method get.

@Override
public TopicUpdateTransaction get() {
    TopicUpdateTransaction topicUpdateTransaction = new TopicUpdateTransaction().setMaxTransactionFee(Hbar.fromTinybars(maxTransactionFee)).setTopicId(TopicId.fromString(topicId)).setTopicMemo(Utility.getMemo("Mirror node updated test topic"));
    if (adminKey != null) {
        PublicKey key = PublicKey.fromString(adminKey);
        topicUpdateTransaction.setAdminKey(key).setSubmitKey(key);
    }
    if (autoRenewAccountId != null) {
        topicUpdateTransaction.setAutoRenewAccountId(AccountId.fromString(autoRenewAccountId)).setAutoRenewPeriod(autoRenewPeriod);
    }
    return topicUpdateTransaction;
}
Also used : TopicUpdateTransaction(com.hedera.hashgraph.sdk.TopicUpdateTransaction) PublicKey(com.hedera.hashgraph.sdk.PublicKey)

Aggregations

TopicUpdateTransaction (com.hedera.hashgraph.sdk.TopicUpdateTransaction)6 Test (org.junit.jupiter.api.Test)3 PublicKey (com.hedera.hashgraph.sdk.PublicKey)2 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)2 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 KeyList (com.hedera.hashgraph.sdk.KeyList)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TopicCreateTransaction (com.hedera.hashgraph.sdk.TopicCreateTransaction)1 TopicDeleteTransaction (com.hedera.hashgraph.sdk.TopicDeleteTransaction)1 TopicInfo (com.hedera.hashgraph.sdk.TopicInfo)1 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1 Duration (java.time.Duration)1 DisplayName (org.junit.jupiter.api.DisplayName)1