@@ -29,28 +29,34 @@ func (ctx CLIContext) GetNode() (rpcclient.Client, error) {
2929 return ctx .Client , nil
3030}
3131
32- // Query performs a query for information about the connected node.
33- func (ctx CLIContext ) Query (path string , data cmn.HexBytes ) (res []byte , err error ) {
32+ // Query performs a query to a Tendermint node with the provided path.
33+ // It returns the result and height of the query upon success
34+ // or an error if the query fails.
35+ func (ctx CLIContext ) Query (path string , data cmn.HexBytes ) ([]byte , int64 , error ) {
3436 return ctx .query (path , data )
3537}
3638
37- // Query information about the connected node with a data payload
38- func (ctx CLIContext ) QueryWithData (path string , data []byte ) (res []byte , err error ) {
39+ // QueryWithData performs a query to a Tendermint node with the provided path
40+ // and a data payload. It returns the result and height of the query upon success
41+ // or an error if the query fails.
42+ func (ctx CLIContext ) QueryWithData (path string , data []byte ) ([]byte , int64 , error ) {
3943 return ctx .query (path , data )
4044}
4145
42- // QueryStore performs a query from a Tendermint node with the provided key and
43- // store name.
44- func (ctx CLIContext ) QueryStore (key cmn.HexBytes , storeName string ) (res []byte , err error ) {
46+ // QueryStore performs a query to a Tendermint node with the provided key and
47+ // store name. It returns the result and height of the query upon success
48+ // or an error if the query fails.
49+ func (ctx CLIContext ) QueryStore (key cmn.HexBytes , storeName string ) ([]byte , int64 , error ) {
4550 return ctx .queryStore (key , storeName , "key" )
4651}
4752
48- // QuerySubspace performs a query from a Tendermint node with the provided
49- // store name and subspace.
50- func (ctx CLIContext ) QuerySubspace (subspace []byte , storeName string ) (res []sdk.KVPair , err error ) {
51- resRaw , err := ctx .queryStore (subspace , storeName , "subspace" )
53+ // QuerySubspace performs a query to a Tendermint node with the provided
54+ // store name and subspace. It returns key value pair and height of the query
55+ // upon success or an error if the query fails.
56+ func (ctx CLIContext ) QuerySubspace (subspace []byte , storeName string ) (res []sdk.KVPair , height int64 , err error ) {
57+ resRaw , height , err := ctx .queryStore (subspace , storeName , "subspace" )
5258 if err != nil {
53- return res , err
59+ return res , height , err
5460 }
5561
5662 ctx .Codec .MustUnmarshalBinaryLengthPrefixed (resRaw , & res )
@@ -134,20 +140,21 @@ func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) {
134140
135141 route := fmt .Sprintf ("custom/%s/%s" , ctx .AccountStore , authtypes .QueryAccount )
136142
137- res , err := ctx .QueryWithData (route , bz )
143+ res , _ , err := ctx .query (route , bz )
138144 if err != nil {
139145 return nil , err
140146 }
141147
142148 return res , nil
143149}
144150
145- // query performs a query from a Tendermint node with the provided store name
146- // and path.
147- func (ctx CLIContext ) query (path string , key cmn.HexBytes ) (res []byte , err error ) {
151+ // query performs a query to a Tendermint node with the provided store name
152+ // and path. It returns the result and height of the query upon success
153+ // or an error if the query fails.
154+ func (ctx CLIContext ) query (path string , key cmn.HexBytes ) (res []byte , height int64 , err error ) {
148155 node , err := ctx .GetNode ()
149156 if err != nil {
150- return res , err
157+ return res , height , err
151158 }
152159
153160 opts := rpcclient.ABCIQueryOptions {
@@ -157,25 +164,25 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro
157164
158165 result , err := node .ABCIQueryWithOptions (path , key , opts )
159166 if err != nil {
160- return res , err
167+ return res , height , err
161168 }
162169
163170 resp := result .Response
164171 if ! resp .IsOK () {
165- return res , errors .New (resp .Log )
172+ return res , height , errors .New (resp .Log )
166173 }
167174
168175 // data from trusted node or subspace query doesn't need verification
169176 if ctx .TrustNode || ! isQueryStoreWithProof (path ) {
170- return resp .Value , nil
177+ return resp .Value , resp . Height , nil
171178 }
172179
173180 err = ctx .verifyProof (path , resp )
174181 if err != nil {
175- return nil , err
182+ return res , height , err
176183 }
177184
178- return resp .Value , nil
185+ return resp .Value , resp . Height , nil
179186}
180187
181188// Verify verifies the consensus proof at given height.
@@ -231,9 +238,10 @@ func (ctx CLIContext) verifyProof(queryPath string, resp abci.ResponseQuery) err
231238 return nil
232239}
233240
234- // queryStore performs a query from a Tendermint node with the provided a store
235- // name and path.
236- func (ctx CLIContext ) queryStore (key cmn.HexBytes , storeName , endPath string ) ([]byte , error ) {
241+ // queryStore performs a query to a Tendermint node with the provided a store
242+ // name and path. It returns the result and height of the query upon success
243+ // or an error if the query fails.
244+ func (ctx CLIContext ) queryStore (key cmn.HexBytes , storeName , endPath string ) ([]byte , int64 , error ) {
237245 path := fmt .Sprintf ("/store/%s/%s" , storeName , endPath )
238246 return ctx .query (path , key )
239247}
0 commit comments