1
1
package client
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
6
7
"github.com/gnolang/gno/gno.land/pkg/gnoland"
@@ -49,38 +50,38 @@ func (h *Client) CreateBatch() common.Batch {
49
50
return & Batch {batch : h .conn .NewBatch ()}
50
51
}
51
52
52
- func (h * Client ) ExecuteABCIQuery (path string , data []byte ) (* core_types.ResultABCIQuery , error ) {
53
- return h .conn .ABCIQuery (path , data )
53
+ func (h * Client ) ExecuteABCIQuery (ctx context. Context , path string , data []byte ) (* core_types.ResultABCIQuery , error ) {
54
+ return h .conn .ABCIQuery (ctx , path , data )
54
55
}
55
56
56
- func (h * Client ) GetLatestBlockHeight () (int64 , error ) {
57
- status , err := h .conn .Status ()
57
+ func (h * Client ) GetLatestBlockHeight (ctx context. Context ) (int64 , error ) {
58
+ status , err := h .conn .Status (ctx , nil )
58
59
if err != nil {
59
60
return 0 , fmt .Errorf ("unable to fetch status, %w" , err )
60
61
}
61
62
62
63
return status .SyncInfo .LatestBlockHeight , nil
63
64
}
64
65
65
- func (h * Client ) GetBlock (height * int64 ) (* core_types.ResultBlock , error ) {
66
- return h .conn .Block (height )
66
+ func (h * Client ) GetBlock (ctx context. Context , height * int64 ) (* core_types.ResultBlock , error ) {
67
+ return h .conn .Block (ctx , height )
67
68
}
68
69
69
- func (h * Client ) GetBlockResults (height * int64 ) (* core_types.ResultBlockResults , error ) {
70
- return h .conn .BlockResults (height )
70
+ func (h * Client ) GetBlockResults (ctx context. Context , height * int64 ) (* core_types.ResultBlockResults , error ) {
71
+ return h .conn .BlockResults (ctx , height )
71
72
}
72
73
73
- func (h * Client ) GetConsensusParams (height * int64 ) (* core_types.ResultConsensusParams , error ) {
74
- return h .conn .ConsensusParams (height )
74
+ func (h * Client ) GetConsensusParams (ctx context. Context , height * int64 ) (* core_types.ResultConsensusParams , error ) {
75
+ return h .conn .ConsensusParams (ctx , height )
75
76
}
76
77
77
- func (h * Client ) BroadcastTransaction (tx * std.Tx ) error {
78
+ func (h * Client ) BroadcastTransaction (ctx context. Context , tx * std.Tx ) error {
78
79
marshalledTx , err := amino .Marshal (tx )
79
80
if err != nil {
80
81
return fmt .Errorf ("unable to marshal transaction, %w" , err )
81
82
}
82
83
83
- res , err := h .conn .BroadcastTxCommit (marshalledTx )
84
+ res , err := h .conn .BroadcastTxCommit (ctx , marshalledTx )
84
85
if err != nil {
85
86
return fmt .Errorf ("unable to broadcast transaction, %w" , err )
86
87
}
@@ -96,8 +97,9 @@ func (h *Client) BroadcastTransaction(tx *std.Tx) error {
96
97
return nil
97
98
}
98
99
99
- func (h * Client ) GetAccount (address string ) (* gnoland.GnoAccount , error ) {
100
+ func (h * Client ) GetAccount (ctx context. Context , address string ) (* gnoland.GnoAccount , error ) {
100
101
queryResult , err := h .conn .ABCIQuery (
102
+ ctx ,
101
103
fmt .Sprintf ("auth/accounts/%s" , address ),
102
104
[]byte {},
103
105
)
@@ -117,8 +119,8 @@ func (h *Client) GetAccount(address string) (*gnoland.GnoAccount, error) {
117
119
return & acc , nil
118
120
}
119
121
120
- func (h * Client ) GetBlockGasUsed (height int64 ) (int64 , error ) {
121
- blockRes , err := h .conn .BlockResults (& height )
122
+ func (h * Client ) GetBlockGasUsed (ctx context. Context , height int64 ) (int64 , error ) {
123
+ blockRes , err := h .conn .BlockResults (ctx , & height )
122
124
if err != nil {
123
125
return 0 , fmt .Errorf ("unable to fetch block results, %w" , err )
124
126
}
@@ -131,16 +133,16 @@ func (h *Client) GetBlockGasUsed(height int64) (int64, error) {
131
133
return gasUsed , nil
132
134
}
133
135
134
- func (h * Client ) GetBlockGasLimit (height int64 ) (int64 , error ) {
135
- consensusParams , err := h .conn .ConsensusParams (& height )
136
+ func (h * Client ) GetBlockGasLimit (ctx context. Context , height int64 ) (int64 , error ) {
137
+ consensusParams , err := h .conn .ConsensusParams (ctx , & height )
136
138
if err != nil {
137
139
return 0 , fmt .Errorf ("unable to fetch block info, %w" , err )
138
140
}
139
141
140
142
return consensusParams .ConsensusParams .Block .MaxGas , nil
141
143
}
142
144
143
- func (h * Client ) EstimateGas (tx * std.Tx ) (int64 , error ) {
145
+ func (h * Client ) EstimateGas (ctx context. Context , tx * std.Tx ) (int64 , error ) {
144
146
// Prepare the transaction.
145
147
// The transaction needs to be amino-binary encoded
146
148
// in order to be estimated
@@ -150,7 +152,7 @@ func (h *Client) EstimateGas(tx *std.Tx) (int64, error) {
150
152
}
151
153
152
154
// Perform the simulation query
153
- resp , err := h .conn .ABCIQuery (simulatePath , encodedTx )
155
+ resp , err := h .conn .ABCIQuery (ctx , simulatePath , encodedTx )
154
156
if err != nil {
155
157
return 0 , fmt .Errorf ("unable to perform ABCI query: %w" , err )
156
158
}
@@ -174,11 +176,11 @@ func (h *Client) EstimateGas(tx *std.Tx) (int64, error) {
174
176
return deliverTx .GasUsed , nil
175
177
}
176
178
177
- func (h * Client ) FetchGasPrice () (std.GasPrice , error ) {
179
+ func (h * Client ) FetchGasPrice (ctx context. Context ) (std.GasPrice , error ) {
178
180
// Perform auth/gasprice
179
181
gp := std.GasPrice {}
180
182
181
- qres , err := h .conn .ABCIQuery (gaspricePath , []byte {})
183
+ qres , err := h .conn .ABCIQuery (ctx , gaspricePath , []byte {})
182
184
if err != nil {
183
185
return gp , err
184
186
}
0 commit comments