github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_delete_transaction.go (about)

     1  package hedera
     2  
     3  /*-
     4   *
     5   * Hedera Go SDK
     6   *
     7   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
     8   *
     9   * Licensed under the Apache License, Version 2.0 (the "License");
    10   * you may not use this file except in compliance with the License.
    11   * You may obtain a copy of the License at
    12   *
    13   *      http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   *
    21   */
    22  
    23  import (
    24  	"github.com/hashgraph/hedera-protobufs-go/services"
    25  
    26  	"time"
    27  )
    28  
    29  // TopicDeleteTransaction is for deleting a topic on HCS.
    30  type TopicDeleteTransaction struct {
    31  	Transaction
    32  	topicID *TopicID
    33  }
    34  
    35  // NewTopicDeleteTransaction creates a TopicDeleteTransaction which can be used to construct
    36  // and execute a Consensus Delete Topic Transaction.
    37  func NewTopicDeleteTransaction() *TopicDeleteTransaction {
    38  	tx := TopicDeleteTransaction{
    39  		Transaction: _NewTransaction(),
    40  	}
    41  
    42  	tx._SetDefaultMaxTransactionFee(NewHbar(2))
    43  
    44  	return &tx
    45  }
    46  
    47  func _TopicDeleteTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *TopicDeleteTransaction {
    48  	return &TopicDeleteTransaction{
    49  		Transaction: tx,
    50  		topicID:     _TopicIDFromProtobuf(pb.GetConsensusDeleteTopic().GetTopicID()),
    51  	}
    52  }
    53  
    54  // SetTopicID sets the topic IDentifier.
    55  func (tx *TopicDeleteTransaction) SetTopicID(topicID TopicID) *TopicDeleteTransaction {
    56  	tx._RequireNotFrozen()
    57  	tx.topicID = &topicID
    58  	return tx
    59  }
    60  
    61  // GetTopicID returns the topic IDentifier.
    62  func (tx *TopicDeleteTransaction) GetTopicID() TopicID {
    63  	if tx.topicID == nil {
    64  		return TopicID{}
    65  	}
    66  
    67  	return *tx.topicID
    68  }
    69  
    70  // ---- Required Interfaces ---- //
    71  
    72  // Sign uses the provided privateKey to sign the transaction.
    73  func (tx *TopicDeleteTransaction) Sign(privateKey PrivateKey) *TopicDeleteTransaction {
    74  	tx.Transaction.Sign(privateKey)
    75  	return tx
    76  }
    77  
    78  // SignWithOperator signs the transaction with client's operator privateKey.
    79  func (tx *TopicDeleteTransaction) SignWithOperator(client *Client) (*TopicDeleteTransaction, error) {
    80  	_, err := tx.Transaction.signWithOperator(client, tx)
    81  	if err != nil {
    82  		return nil, err
    83  	}
    84  	return tx, nil
    85  }
    86  
    87  // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map
    88  // with the publicKey as the map key.
    89  func (tx *TopicDeleteTransaction) SignWith(
    90  	publicKey PublicKey,
    91  	signer TransactionSigner,
    92  ) *TopicDeleteTransaction {
    93  	tx.Transaction.SignWith(publicKey, signer)
    94  	return tx
    95  }
    96  
    97  // AddSignature adds a signature to the transaction.
    98  func (tx *TopicDeleteTransaction) AddSignature(publicKey PublicKey, signature []byte) *TopicDeleteTransaction {
    99  	tx.Transaction.AddSignature(publicKey, signature)
   100  	return tx
   101  }
   102  
   103  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
   104  func (tx *TopicDeleteTransaction) SetGrpcDeadline(deadline *time.Duration) *TopicDeleteTransaction {
   105  	tx.Transaction.SetGrpcDeadline(deadline)
   106  	return tx
   107  }
   108  
   109  func (tx *TopicDeleteTransaction) Freeze() (*TopicDeleteTransaction, error) {
   110  	return tx.FreezeWith(nil)
   111  }
   112  
   113  func (tx *TopicDeleteTransaction) FreezeWith(client *Client) (*TopicDeleteTransaction, error) {
   114  	_, err := tx.Transaction.freezeWith(client, tx)
   115  	return tx, err
   116  }
   117  
   118  // SetMaxTransactionFee sets the max transaction fee for this TopicDeleteTransaction.
   119  func (tx *TopicDeleteTransaction) SetMaxTransactionFee(fee Hbar) *TopicDeleteTransaction {
   120  	tx.Transaction.SetMaxTransactionFee(fee)
   121  	return tx
   122  }
   123  
   124  // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received
   125  func (tx *TopicDeleteTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *TopicDeleteTransaction {
   126  	tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID)
   127  	return tx
   128  }
   129  
   130  // SetTransactionMemo sets the memo for this TopicDeleteTransaction.
   131  func (tx *TopicDeleteTransaction) SetTransactionMemo(memo string) *TopicDeleteTransaction {
   132  	tx.Transaction.SetTransactionMemo(memo)
   133  	return tx
   134  }
   135  
   136  // SetTransactionValidDuration sets the valid duration for this TopicDeleteTransaction.
   137  func (tx *TopicDeleteTransaction) SetTransactionValidDuration(duration time.Duration) *TopicDeleteTransaction {
   138  	tx.Transaction.SetTransactionValidDuration(duration)
   139  	return tx
   140  }
   141  
   142  // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not
   143  func (tx *TopicDeleteTransaction) ToBytes() ([]byte, error) {
   144  	bytes, err := tx.Transaction.toBytes(tx)
   145  	if err != nil {
   146  		return nil, err
   147  	}
   148  	return bytes, nil
   149  }
   150  
   151  // SetTransactionID sets the TransactionID for this TopicDeleteTransaction.
   152  func (tx *TopicDeleteTransaction) SetTransactionID(transactionID TransactionID) *TopicDeleteTransaction {
   153  	tx.Transaction.SetTransactionID(transactionID)
   154  	return tx
   155  }
   156  
   157  // SetNodeAccountIDs sets the _Node AccountID for this TopicDeleteTransaction.
   158  func (tx *TopicDeleteTransaction) SetNodeAccountIDs(nodeID []AccountID) *TopicDeleteTransaction {
   159  	tx.Transaction.SetNodeAccountIDs(nodeID)
   160  	return tx
   161  }
   162  
   163  // SetMaxRetry sets the max number of errors before execution will fail.
   164  func (tx *TopicDeleteTransaction) SetMaxRetry(count int) *TopicDeleteTransaction {
   165  	tx.Transaction.SetMaxRetry(count)
   166  	return tx
   167  }
   168  
   169  // SetMaxBackoff The maximum amount of time to wait between retries.
   170  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   171  func (tx *TopicDeleteTransaction) SetMaxBackoff(max time.Duration) *TopicDeleteTransaction {
   172  	tx.Transaction.SetMaxBackoff(max)
   173  	return tx
   174  }
   175  
   176  // SetMinBackoff sets the minimum amount of time to wait between retries.
   177  func (tx *TopicDeleteTransaction) SetMinBackoff(min time.Duration) *TopicDeleteTransaction {
   178  	tx.Transaction.SetMinBackoff(min)
   179  	return tx
   180  }
   181  
   182  func (tx *TopicDeleteTransaction) SetLogLevel(level LogLevel) *TopicDeleteTransaction {
   183  	tx.Transaction.SetLogLevel(level)
   184  	return tx
   185  }
   186  
   187  func (tx *TopicDeleteTransaction) Execute(client *Client) (TransactionResponse, error) {
   188  	return tx.Transaction.execute(client, tx)
   189  }
   190  
   191  func (tx *TopicDeleteTransaction) Schedule() (*ScheduleCreateTransaction, error) {
   192  	return tx.Transaction.schedule(tx)
   193  }
   194  
   195  // ----------- Overridden functions ----------------
   196  
   197  func (tx *TopicDeleteTransaction) getName() string {
   198  	return "TopicDeleteTransaction"
   199  }
   200  
   201  func (tx *TopicDeleteTransaction) validateNetworkOnIDs(client *Client) error {
   202  	if client == nil || !client.autoValidateChecksums {
   203  		return nil
   204  	}
   205  
   206  	if tx.topicID != nil {
   207  		if err := tx.topicID.ValidateChecksum(client); err != nil {
   208  			return err
   209  		}
   210  	}
   211  
   212  	return nil
   213  }
   214  
   215  func (tx *TopicDeleteTransaction) build() *services.TransactionBody {
   216  	return &services.TransactionBody{
   217  		TransactionFee:           tx.transactionFee,
   218  		Memo:                     tx.Transaction.memo,
   219  		TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
   220  		TransactionID:            tx.transactionID._ToProtobuf(),
   221  		Data: &services.TransactionBody_ConsensusDeleteTopic{
   222  			ConsensusDeleteTopic: tx.buildProtoBody(),
   223  		},
   224  	}
   225  }
   226  
   227  func (tx *TopicDeleteTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) {
   228  	return &services.SchedulableTransactionBody{
   229  		TransactionFee: tx.transactionFee,
   230  		Memo:           tx.Transaction.memo,
   231  		Data: &services.SchedulableTransactionBody_ConsensusDeleteTopic{
   232  			ConsensusDeleteTopic: tx.buildProtoBody(),
   233  		},
   234  	}, nil
   235  }
   236  
   237  func (tx *TopicDeleteTransaction) buildProtoBody() *services.ConsensusDeleteTopicTransactionBody {
   238  	body := &services.ConsensusDeleteTopicTransactionBody{}
   239  	if tx.topicID != nil {
   240  		body.TopicID = tx.topicID._ToProtobuf()
   241  	}
   242  
   243  	return body
   244  }
   245  
   246  func (tx *TopicDeleteTransaction) getMethod(channel *_Channel) _Method {
   247  	return _Method{
   248  		transaction: channel._GetTopic().DeleteTopic,
   249  	}
   250  }
   251  func (tx *TopicDeleteTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
   252  	return tx.buildScheduled()
   253  }