github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_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 // TokenInfoQuery Used get information about Token instance 30 type TokenInfoQuery struct { 31 Query 32 tokenID *TokenID 33 } 34 35 // NewTokenInfoQuery creates a TokenInfoQuery which is used get information about Token instance 36 func NewTokenInfoQuery() *TokenInfoQuery { 37 header := services.QueryHeader{} 38 return &TokenInfoQuery{ 39 Query: _NewQuery(true, &header), 40 } 41 } 42 43 // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.) 44 func (q *TokenInfoQuery) SetGrpcDeadline(deadline *time.Duration) *TokenInfoQuery { 45 q.Query.SetGrpcDeadline(deadline) 46 return q 47 } 48 49 // SetTokenID Sets the topic to retrieve info about (the parameters and running state of). 50 func (q *TokenInfoQuery) SetTokenID(tokenID TokenID) *TokenInfoQuery { 51 q.tokenID = &tokenID 52 return q 53 } 54 55 // GetTokenID returns the TokenID for this TokenInfoQuery 56 func (q *TokenInfoQuery) GetTokenID() TokenID { 57 if q.tokenID == nil { 58 return TokenID{} 59 } 60 61 return *q.tokenID 62 } 63 64 func (q *TokenInfoQuery) GetCost(client *Client) (Hbar, error) { 65 return q.Query.getCost(client, q) 66 } 67 68 // Execute executes the TopicInfoQuery using the provided client 69 func (q *TokenInfoQuery) Execute(client *Client) (TokenInfo, error) { 70 resp, err := q.Query.execute(client, q) 71 72 if err != nil { 73 return TokenInfo{}, err 74 } 75 76 info := _TokenInfoFromProtobuf(resp.GetTokenGetInfo().TokenInfo) 77 78 return info, nil 79 } 80 81 // SetMaxQueryPayment sets the maximum payment allowed for this Query. 82 func (q *TokenInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *TokenInfoQuery { 83 q.Query.SetMaxQueryPayment(maxPayment) 84 return q 85 } 86 87 // SetQueryPayment sets the payment amount for this Query. 88 func (q *TokenInfoQuery) SetQueryPayment(paymentAmount Hbar) *TokenInfoQuery { 89 q.Query.SetQueryPayment(paymentAmount) 90 return q 91 } 92 93 // SetNodeAccountIDs sets the _Node AccountID for this TokenInfoQuery. 94 func (q *TokenInfoQuery) SetNodeAccountIDs(accountID []AccountID) *TokenInfoQuery { 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 *TokenInfoQuery) SetMaxRetry(count int) *TokenInfoQuery { 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 *TokenInfoQuery) SetMaxBackoff(max time.Duration) *TokenInfoQuery { 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 *TokenInfoQuery) SetMinBackoff(min time.Duration) *TokenInfoQuery { 114 q.Query.SetMinBackoff(min) 115 return q 116 } 117 118 // SetPaymentTransactionID assigns the payment transaction id. 119 func (q *TokenInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *TokenInfoQuery { 120 q.paymentTransactionIDs._Clear()._Push(transactionID)._SetLocked(true) 121 return q 122 } 123 124 func (q *TokenInfoQuery) SetLogLevel(level LogLevel) *TokenInfoQuery { 125 q.Query.SetLogLevel(level) 126 return q 127 } 128 129 // ---------- Parent functions specific implementation ---------- 130 131 func (q *TokenInfoQuery) getMethod(channel *_Channel) _Method { 132 return _Method{ 133 query: channel._GetToken().GetTokenInfo, 134 } 135 } 136 137 func (q *TokenInfoQuery) getName() string { 138 return "TokenInfoQuery" 139 } 140 141 func (q *TokenInfoQuery) buildQuery() *services.Query { 142 body := &services.TokenGetInfoQuery{ 143 Header: q.pbHeader, 144 } 145 if q.tokenID != nil { 146 body.Token = q.tokenID._ToProtobuf() 147 } 148 149 return &services.Query{ 150 Query: &services.Query_TokenGetInfo{ 151 TokenGetInfo: body, 152 }, 153 } 154 } 155 156 func (q *TokenInfoQuery) validateNetworkOnIDs(client *Client) error { 157 if client == nil || !client.autoValidateChecksums { 158 return nil 159 } 160 161 if q.tokenID != nil { 162 if err := q.tokenID.ValidateChecksum(client); err != nil { 163 return err 164 } 165 } 166 167 return nil 168 } 169 170 func (q *TokenInfoQuery) getQueryResponse(response *services.Response) queryResponse { 171 return response.GetTokenGetInfo() 172 }