-
Notifications
You must be signed in to change notification settings - Fork 66
/
account_info_query.go
174 lines (143 loc) · 4.84 KB
/
account_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
173
174
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-sdk-go/v2/proto/services"
)
// AccountInfoQuery
// Get all the information about an account, including the balance. This does not get the list of
// account records.
type AccountInfoQuery struct {
Query
accountID *AccountID
}
// NewAccountInfoQuery
// Creates an AccountInfoQuery which retrieves all the information about an account, including the balance. This does not get the list of
// account records.
func NewAccountInfoQuery() *AccountInfoQuery {
header := services.QueryHeader{}
return &AccountInfoQuery{
Query: _NewQuery(true, &header),
}
}
func (q *AccountInfoQuery) GetCost(client *Client) (Hbar, error) {
return q.Query.getCost(client, q)
}
// Execute executes the Query with the provided client
func (q *AccountInfoQuery) Execute(client *Client) (AccountInfo, error) {
resp, err := q.execute(client, q)
if err != nil {
return AccountInfo{}, err
}
return _AccountInfoFromProtobuf(resp.GetCryptoGetInfo().AccountInfo)
}
// SetGrpcDeadline When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
func (q *AccountInfoQuery) SetGrpcDeadline(deadline *time.Duration) *AccountInfoQuery {
q.Query.SetGrpcDeadline(deadline)
return q
}
// SetAccountID sets the AccountID for this AccountInfoQuery.
func (q *AccountInfoQuery) SetAccountID(accountID AccountID) *AccountInfoQuery {
q.accountID = &accountID
return q
}
// GetAccountID returns the AccountID for this AccountInfoQuery.
func (q *AccountInfoQuery) GetAccountID() AccountID {
if q.accountID == nil {
return AccountID{}
}
return *q.accountID
}
// SetNodeAccountIDs sets the _Node AccountID for this AccountInfoQuery.
func (q *AccountInfoQuery) SetNodeAccountIDs(accountID []AccountID) *AccountInfoQuery {
q.Query.SetNodeAccountIDs(accountID)
return q
}
// SetQueryPayment sets the Hbar payment to pay the _Node a fee for handling this query
func (q *AccountInfoQuery) SetQueryPayment(queryPayment Hbar) *AccountInfoQuery {
q.queryPayment = queryPayment
return q
}
// SetMaxQueryPayment sets the maximum payment allowable for this query.
func (q *AccountInfoQuery) SetMaxQueryPayment(queryMaxPayment Hbar) *AccountInfoQuery {
q.maxQueryPayment = queryMaxPayment
return q
}
// SetMaxRetry sets the max number of errors before execution will fail.
func (q *AccountInfoQuery) SetMaxRetry(count int) *AccountInfoQuery {
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 *AccountInfoQuery) SetMaxBackoff(max time.Duration) *AccountInfoQuery {
q.Query.SetMaxBackoff(max)
return q
}
// SetMinBackoff sets the minimum amount of time to wait between retries.
func (q *AccountInfoQuery) SetMinBackoff(min time.Duration) *AccountInfoQuery {
q.Query.SetMinBackoff(min)
return q
}
// SetPaymentTransactionID assigns the payment transaction id.
func (q *AccountInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *AccountInfoQuery {
q.Query.SetPaymentTransactionID(transactionID)
return q
}
func (q *AccountInfoQuery) SetLogLevel(level LogLevel) *AccountInfoQuery {
q.Query.SetLogLevel(level)
return q
}
// ---------- Parent functions specific implementation ----------
func (q *AccountInfoQuery) getMethod(channel *_Channel) _Method {
return _Method{
query: channel._GetCrypto().GetAccountInfo,
}
}
func (q *AccountInfoQuery) getName() string {
return "AccountInfoQuery"
}
func (q *AccountInfoQuery) buildQuery() *services.Query {
pbQuery := services.Query_CryptoGetInfo{
CryptoGetInfo: &services.CryptoGetInfoQuery{
Header: q.pbHeader,
},
}
if q.accountID != nil {
pbQuery.CryptoGetInfo.AccountID = q.accountID._ToProtobuf()
}
return &services.Query{
Query: &pbQuery,
}
}
func (q *AccountInfoQuery) validateNetworkOnIDs(client *Client) error {
if client == nil || !client.autoValidateChecksums {
return nil
}
if q.accountID != nil {
if err := q.accountID.ValidateChecksum(client); err != nil {
return err
}
}
return nil
}
func (q *AccountInfoQuery) getQueryResponse(response *services.Response) queryResponse {
return response.GetCryptoGetInfo()
}