github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_info_query.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  	"time"
    25  
    26  	"github.com/hashgraph/hedera-protobufs-go/services"
    27  )
    28  
    29  // TopicInfo is the Query for retrieving information about a topic stored on the Hedera network.
    30  type TopicInfoQuery struct {
    31  	Query
    32  	topicID *TopicID
    33  }
    34  
    35  // NewTopicInfoQuery creates a TopicInfoQuery query which can be used to construct and execute a
    36  //
    37  //	Get Topic Info Query.
    38  func NewTopicInfoQuery() *TopicInfoQuery {
    39  	header := services.QueryHeader{}
    40  	return &TopicInfoQuery{
    41  		Query: _NewQuery(true, &header),
    42  	}
    43  }
    44  
    45  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
    46  func (q *TopicInfoQuery) SetGrpcDeadline(deadline *time.Duration) *TopicInfoQuery {
    47  	q.Query.SetGrpcDeadline(deadline)
    48  	return q
    49  }
    50  
    51  // SetTopicID sets the topic to retrieve info about (the parameters and running state of).
    52  func (q *TopicInfoQuery) SetTopicID(topicID TopicID) *TopicInfoQuery {
    53  	q.topicID = &topicID
    54  	return q
    55  }
    56  
    57  // GetTopicID returns the TopicID for this TopicInfoQuery
    58  func (q *TopicInfoQuery) GetTopicID() TopicID {
    59  	if q.topicID == nil {
    60  		return TopicID{}
    61  	}
    62  
    63  	return *q.topicID
    64  }
    65  
    66  func (q *TopicInfoQuery) GetCost(client *Client) (Hbar, error) {
    67  	return q.Query.getCost(client, q)
    68  }
    69  
    70  // Execute executes the TopicInfoQuery using the provided client
    71  func (q *TopicInfoQuery) Execute(client *Client) (TopicInfo, error) {
    72  	resp, err := q.Query.execute(client, q)
    73  
    74  	if err != nil {
    75  		return TopicInfo{}, err
    76  	}
    77  
    78  	return _TopicInfoFromProtobuf(resp.GetConsensusGetTopicInfo().TopicInfo)
    79  }
    80  
    81  // SetMaxQueryPayment sets the maximum payment allowed for this Query.
    82  func (q *TopicInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *TopicInfoQuery {
    83  	q.Query.SetMaxQueryPayment(maxPayment)
    84  	return q
    85  }
    86  
    87  // SetQueryPayment sets the payment amount for this Query.
    88  func (q *TopicInfoQuery) SetQueryPayment(paymentAmount Hbar) *TopicInfoQuery {
    89  	q.Query.SetQueryPayment(paymentAmount)
    90  	return q
    91  }
    92  
    93  // SetNodeAccountIDs sets the _Node AccountID for this TopicInfoQuery.
    94  func (q *TopicInfoQuery) SetNodeAccountIDs(accountID []AccountID) *TopicInfoQuery {
    95  	q.Query.SetNodeAccountIDs(accountID)
    96  	return q
    97  }
    98  
    99  // SetMaxRetry sets the max number of errors before execution will fail.
   100  func (q *TopicInfoQuery) SetMaxRetry(count int) *TopicInfoQuery {
   101  	q.Query.SetMaxRetry(count)
   102  	return q
   103  }
   104  
   105  // SetMaxBackoff The maximum amount of time to wait between retries.
   106  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   107  func (q *TopicInfoQuery) SetMaxBackoff(max time.Duration) *TopicInfoQuery {
   108  	q.Query.SetMaxBackoff(max)
   109  	return q
   110  }
   111  
   112  // SetMinBackoff sets the minimum amount of time to wait between retries.
   113  func (q *TopicInfoQuery) SetMinBackoff(min time.Duration) *TopicInfoQuery {
   114  	q.Query.SetMinBackoff(min)
   115  	return q
   116  }
   117  
   118  func (q *TopicInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *TopicInfoQuery {
   119  	q.paymentTransactionIDs._Clear()._Push(transactionID)._SetLocked(true)
   120  	return q
   121  }
   122  
   123  func (q *TopicInfoQuery) SetLogLevel(level LogLevel) *TopicInfoQuery {
   124  	q.Query.SetLogLevel(level)
   125  	return q
   126  }
   127  
   128  // ---------- Parent functions specific implementation ----------
   129  
   130  func (q *TopicInfoQuery) getMethod(channel *_Channel) _Method {
   131  	return _Method{
   132  		query: channel._GetTopic().GetTopicInfo,
   133  	}
   134  }
   135  
   136  func (q *TopicInfoQuery) getName() string {
   137  	return "TopicInfoQuery"
   138  }
   139  
   140  func (q *TopicInfoQuery) buildQuery() *services.Query {
   141  	body := &services.ConsensusGetTopicInfoQuery{
   142  		Header: q.pbHeader,
   143  	}
   144  
   145  	if q.topicID != nil {
   146  		body.TopicID = q.topicID._ToProtobuf()
   147  	}
   148  
   149  	return &services.Query{
   150  		Query: &services.Query_ConsensusGetTopicInfo{
   151  			ConsensusGetTopicInfo: body,
   152  		},
   153  	}
   154  }
   155  
   156  func (q *TopicInfoQuery) validateNetworkOnIDs(client *Client) error {
   157  	if client == nil || !client.autoValidateChecksums {
   158  		return nil
   159  	}
   160  
   161  	if q.topicID != nil {
   162  		if err := q.topicID.ValidateChecksum(client); err != nil {
   163  			return err
   164  		}
   165  	}
   166  
   167  	return nil
   168  }
   169  
   170  func (q *TopicInfoQuery) getQueryResponse(response *services.Response) queryResponse {
   171  	return response.GetConsensusGetTopicInfo()
   172  }