Search in sources :

Example 1 with TopicInfo

use of com.hedera.hashgraph.sdk.TopicInfo 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 TopicInfo

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

the class TopicFeature method verifyTopicOnNetwork.

@Then("the network should successfully observe the topic")
public void verifyTopicOnNetwork() {
    TopicInfo topicInfo = topicClient.getTopicInfo(consensusTopicId);
    assertNotNull(topicInfo, "topicInfo is null");
    assertNotEquals("", topicInfo.topicMemo, "topicMemo is not empty");
    assertThat(topicInfo.sequenceNumber).isGreaterThanOrEqualTo(messageSubscribeCount);
}
Also used : TopicInfo(com.hedera.hashgraph.sdk.TopicInfo) Then(io.cucumber.java.en.Then)

Aggregations

TopicInfo (com.hedera.hashgraph.sdk.TopicInfo)2 KeyList (com.hedera.hashgraph.sdk.KeyList)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TopicInfoQuery (com.hedera.hashgraph.sdk.TopicInfoQuery)1 TopicUpdateTransaction (com.hedera.hashgraph.sdk.TopicUpdateTransaction)1 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)1 Then (io.cucumber.java.en.Then)1