-
Notifications
You must be signed in to change notification settings - Fork 66
/
contract_info_query.go
160 lines (127 loc) · 4.25 KB
/
contract_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
package hiero
// SPDX-License-Identifier: Apache-2.0
import (
"time"
"github.com/hiero-ledger/hiero-sdk-go/v2/proto/services"
)
// ContractInfoQuery retrieves information about a smart contract instance. This includes the account that it uses, the
// file containing its bytecode, and the time when it will expire.
type ContractInfoQuery struct {
Query
contractID *ContractID
}
// NewContractInfoQuery creates a ContractInfoQuery query which can be used to construct and execute a
// Contract Get Info Query.
func NewContractInfoQuery() *ContractInfoQuery {
header := services.QueryHeader{}
query := _NewQuery(true, &header)
return &ContractInfoQuery{
Query: query,
}
}
// When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
func (q *ContractInfoQuery) SetGrpcDeadline(deadline *time.Duration) *ContractInfoQuery {
q.Query.SetGrpcDeadline(deadline)
return q
}
// SetContractID sets the contract for which information is requested
func (q *ContractInfoQuery) SetContractID(contractID ContractID) *ContractInfoQuery {
q.contractID = &contractID
return q
}
func (q *ContractInfoQuery) GetContractID() ContractID {
if q.contractID == nil {
return ContractID{}
}
return *q.contractID
}
func (q *ContractInfoQuery) GetCost(client *Client) (Hbar, error) {
return q.Query.getCost(client, q)
}
// Execute executes the Query with the provided client
func (q *ContractInfoQuery) Execute(client *Client) (ContractInfo, error) {
resp, err := q.Query.execute(client, q)
if err != nil {
return ContractInfo{}, err
}
info, err := _ContractInfoFromProtobuf(resp.GetContractGetInfo().ContractInfo)
if err != nil {
return ContractInfo{}, err
}
return info, nil
}
// SetMaxQueryPayment sets the maximum payment allowed for this Query.
func (q *ContractInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *ContractInfoQuery {
q.Query.SetMaxQueryPayment(maxPayment)
return q
}
// SetQueryPayment sets the payment amount for this Query.
func (q *ContractInfoQuery) SetQueryPayment(paymentAmount Hbar) *ContractInfoQuery {
q.Query.SetQueryPayment(paymentAmount)
return q
}
// SetNodeAccountIDs sets the _Node AccountID for this ContractInfoQuery.
func (q *ContractInfoQuery) SetNodeAccountIDs(accountID []AccountID) *ContractInfoQuery {
q.Query.SetNodeAccountIDs(accountID)
return q
}
// SetMaxRetry sets the max number of errors before execution will fail.
func (q *ContractInfoQuery) SetMaxRetry(count int) *ContractInfoQuery {
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 *ContractInfoQuery) SetMaxBackoff(max time.Duration) *ContractInfoQuery {
q.Query.SetMaxBackoff(max)
return q
}
// SetMinBackoff sets the minimum amount of time to wait between retries.
func (q *ContractInfoQuery) SetMinBackoff(min time.Duration) *ContractInfoQuery {
q.Query.SetMinBackoff(min)
return q
}
func (q *ContractInfoQuery) SetPaymentTransactionID(transactionID TransactionID) *ContractInfoQuery {
q.Query.SetPaymentTransactionID(transactionID)
return q
}
func (q *ContractInfoQuery) SetLogLevel(level LogLevel) *ContractInfoQuery {
q.Query.SetLogLevel(level)
return q
}
// ---------- Parent functions specific implementation ----------
func (q *ContractInfoQuery) getMethod(channel *_Channel) _Method {
return _Method{
query: channel._GetContract().GetContractInfo,
}
}
func (q *ContractInfoQuery) getName() string {
return "ContractInfoQuery"
}
func (q *ContractInfoQuery) buildQuery() *services.Query {
pb := services.Query_ContractGetInfo{
ContractGetInfo: &services.ContractGetInfoQuery{
Header: q.pbHeader,
},
}
if q.contractID != nil {
pb.ContractGetInfo.ContractID = q.contractID._ToProtobuf()
}
return &services.Query{
Query: &pb,
}
}
func (q *ContractInfoQuery) validateNetworkOnIDs(client *Client) error {
if client == nil || !client.autoValidateChecksums {
return nil
}
if q.contractID != nil {
if err := q.contractID.ValidateChecksum(client); err != nil {
return err
}
}
return nil
}
func (q *ContractInfoQuery) getQueryResponse(response *services.Response) queryResponse {
return response.GetContractGetInfo()
}