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