/
token_info_query.go
172 lines (141 loc) · 4.58 KB
/
token_info_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package hedera
/*-
*
* Hedera Go 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.
*
*/
import (
"time"
"github.com/hashgraph/hedera-protobufs-go/services"
)
// TokenInfoQuery Used get information about Token instance
type TokenInfoQuery struct {
Query
tokenID *TokenID
}
// NewTokenInfoQuery creates a TokenInfoQuery which is used get information about Token instance
func NewTokenInfoQuery() *TokenInfoQuery {
header := services.QueryHeader{}
return &TokenInfoQuery{
Query: _NewQuery(true, &header),
}
}
// When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
func (q *TokenInfoQuery) SetGrpcDeadline(deadline *time.Duration) *TokenInfoQuery {
q.Query.SetGrpcDeadline(deadline)
return q
}
// SetTokenID Sets the topic to retrieve info about (the parameters and running state of).
func (q *TokenInfoQuery) SetTokenID(tokenID TokenID) *TokenInfoQuery {
q.tokenID = &tokenID
return q
}
// GetTokenID returns the TokenID for this TokenInfoQuery
func (q *TokenInfoQuery) GetTokenID() TokenID {
if q.tokenID == nil {
return TokenID{}
}
return *q.tokenID
}
func (q *TokenInfoQuery) GetCost(client *Client) (Hbar, error) {
return q.Query.getCost(client, q)
}
// Execute executes the TopicInfoQuery using the provided client
func (q *TokenInfoQuery) Execute(client *Client) (TokenInfo, error) {
resp, err := q.Query.execute(client, q)
if err != nil {
return TokenInfo{}, err
}
info := _TokenInfoFromProtobuf(resp.GetTokenGetInfo().TokenInfo)
return info, nil
}
// SetMaxQueryPayment sets the maximum payment allowed for this Query.
func (q *TokenInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *TokenInfoQuery {
q.Query.SetMaxQueryPayment(maxPayment)
return q
}
// SetQueryPayment sets the payment amount for this Query.
func (q *TokenInfoQuery) SetQueryPayment(paymentAmount Hbar) *TokenInfoQuery {
q.Query.SetQueryPayment(paymentAmount)
return q
}
// SetNodeAccountIDs sets the _Node AccountID for this TokenInfoQuery.
func (q *TokenInfoQuery) SetNodeAccountIDs(accountID []AccountID) *TokenInfoQuery {
q.Query.SetNodeAccountIDs(accountID)
return q
}
// SetMaxRetry sets the max number of errors before execution will fail.
func (q *TokenInfoQuery) SetMaxRetry(count int) *TokenInfoQuery {
q.Query.SetMaxRetry(count)
return q
}
// SetMaxBackoff The maximum amount of time to wait between retries.
// Every retry attempt will increase the wait time exponentially until it reaches this time.
func (q *TokenInfoQuery) SetMaxBackoff(max time.Duration) *TokenInfoQuery {
q.Query.SetMaxBackoff(max)
return q
}
// SetMinBackoff sets the minimum amount of time to wait between retries.
func (q *TokenInfoQuery) SetMinBackoff(min time.Duration) *TokenInfoQuery {
q.Query.SetMinBackoff(min)
return q
}
// SetPaymentTransactionID assigns the payment transaction id.
func (q *TokenInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *TokenInfoQuery {
q.paymentTransactionIDs._Clear()._Push(transactionID)._SetLocked(true)
return q
}
func (q *TokenInfoQuery) SetLogLevel(level LogLevel) *TokenInfoQuery {
q.Query.SetLogLevel(level)
return q
}
// ---------- Parent functions specific implementation ----------
func (q *TokenInfoQuery) getMethod(channel *_Channel) _Method {
return _Method{
query: channel._GetToken().GetTokenInfo,
}
}
func (q *TokenInfoQuery) getName() string {
return "TokenInfoQuery"
}
func (q *TokenInfoQuery) buildQuery() *services.Query {
body := &services.TokenGetInfoQuery{
Header: q.pbHeader,
}
if q.tokenID != nil {
body.Token = q.tokenID._ToProtobuf()
}
return &services.Query{
Query: &services.Query_TokenGetInfo{
TokenGetInfo: body,
},
}
}
func (q *TokenInfoQuery) validateNetworkOnIDs(client *Client) error {
if client == nil || !client.autoValidateChecksums {
return nil
}
if q.tokenID != nil {
if err := q.tokenID.ValidateChecksum(client); err != nil {
return err
}
}
return nil
}
func (q *TokenInfoQuery) getQueryResponse(response *services.Response) queryResponse {
return response.GetTokenGetInfo()
}