com.hedera.hashgraph.sdk.TopicDeleteTransaction Maven / Gradle / Ivy
Show all versions of sdk-full Show documentation
/*-
*
* Hedera Java SDK
*
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.hedera.hashgraph.sdk;
import com.google.protobuf.InvalidProtocolBufferException;
import com.hedera.hashgraph.sdk.proto.ConsensusDeleteTopicTransactionBody;
import com.hedera.hashgraph.sdk.proto.ConsensusServiceGrpc;
import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import io.grpc.MethodDescriptor;
import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.Objects;
/**
* Delete a topic.
*
* No more transactions or queries on the topic will succeed.
*
* If an {@code adminKey} is set, this transaction must be signed by that key.
* If there is no {@code adminKey}, this transaction will fail with {@link Status#UNAUTHORIZED}.
*/
public final class TopicDeleteTransaction extends Transaction {
@Nullable
private TopicId topicId = null;
/**
* Constructor.
*/
public TopicDeleteTransaction() {
}
/**
* Constructor.
*
* @param txs Compound list of transaction id's list of (AccountId, Transaction)
* records
* @throws InvalidProtocolBufferException when there is an issue with the protobuf
*/
TopicDeleteTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException {
super(txs);
initFromTransactionBody();
}
/**
* Constructor.
*
* @param txBody protobuf TransactionBody
*/
TopicDeleteTransaction(com.hedera.hashgraph.sdk.proto.TransactionBody txBody) {
super(txBody);
initFromTransactionBody();
}
/**
* Extract the topic id.
*
* @return the topic id
*/
@Nullable
public TopicId getTopicId() {
return topicId;
}
/**
* Set the topic ID to delete.
*
* @param topicId The TopicId to be set
* @return {@code this}
*/
public TopicDeleteTransaction setTopicId(TopicId topicId) {
Objects.requireNonNull(topicId);
requireNotFrozen();
this.topicId = topicId;
return this;
}
/**
* Initialize from the transaction body.
*/
void initFromTransactionBody() {
var body = sourceTransactionBody.getConsensusDeleteTopic();
if (body.hasTopicID()) {
topicId = TopicId.fromProtobuf(body.getTopicID());
}
}
/**
* Build the transaction body.
*
* @return {@link
* com.hedera.hashgraph.sdk.proto.ConsensusDeleteTopicTransactionBody}
*/
ConsensusDeleteTopicTransactionBody.Builder build() {
var builder = ConsensusDeleteTopicTransactionBody.newBuilder();
if (topicId != null) {
builder.setTopicID(topicId.toProtobuf());
}
return builder;
}
@Override
void validateChecksums(Client client) throws BadEntityIdException {
if (topicId != null) {
topicId.validateChecksum(client);
}
}
@Override
MethodDescriptor getMethodDescriptor() {
return ConsensusServiceGrpc.getDeleteTopicMethod();
}
@Override
void onFreeze(TransactionBody.Builder bodyBuilder) {
bodyBuilder.setConsensusDeleteTopic(build());
}
@Override
void onScheduled(SchedulableTransactionBody.Builder scheduled) {
scheduled.setConsensusDeleteTopic(build());
}
}