@@ -226,32 +226,45 @@ $ %s query block --%s=%s <hash>
226226` ,
227227 version .AppName , auth .FlagType , auth .TypeHeight ,
228228 version .AppName , auth .FlagType , auth .TypeHash )),
229- Args : cobra .ExactArgs (1 ),
229+ Args : cobra .MaximumNArgs (1 ),
230230 RunE : func (cmd * cobra.Command , args []string ) error {
231231 clientCtx , err := client .GetClientQueryContext (cmd )
232232 if err != nil {
233233 return err
234234 }
235235
236236 typ , _ := cmd .Flags ().GetString (auth .FlagType )
237+ if len (args ) == 0 {
238+ // do not break default v0.50 behavior of block hash
239+ // if no args are provided, set the type to height
240+ typ = auth .TypeHeight
241+ }
237242
238243 switch typ {
239244 case auth .TypeHeight :
240-
241- if args [0 ] == "" {
242- return fmt .Errorf ("argument should be a block height" )
245+ var (
246+ err error
247+ height int64
248+ )
249+ heightStr := ""
250+ if len (args ) > 0 {
251+ heightStr = args [0 ]
243252 }
244253
245- // optional height
246- var height * int64
247- if len (args ) > 0 {
248- height , err = parseOptionalHeight (args [0 ])
254+ if heightStr == "" {
255+ cmd .Println ("Falling back to latest block height:" )
256+ height , err = rpc .GetChainHeight (clientCtx )
257+ if err != nil {
258+ return fmt .Errorf ("failed to get chain height: %w" , err )
259+ }
260+ } else {
261+ height , err = strconv .ParseInt (heightStr , 10 , 64 )
249262 if err != nil {
250- return err
263+ return fmt . Errorf ( "failed to parse block height: %w" , err )
251264 }
252265 }
253266
254- output , err := rpc .GetBlockByHeight (clientCtx , height )
267+ output , err := rpc .GetBlockByHeight (clientCtx , & height )
255268 if err != nil {
256269 return err
257270 }
@@ -311,15 +324,21 @@ func QueryBlockResultsCmd() *cobra.Command {
311324 }
312325
313326 // optional height
314- var height * int64
327+ var height int64
315328 if len (args ) > 0 {
316- height , err = parseOptionalHeight (args [0 ])
329+ height , err = strconv . ParseInt (args [0 ], 10 , 64 )
317330 if err != nil {
318331 return err
319332 }
333+ } else {
334+ cmd .Println ("Falling back to latest block height:" )
335+ height , err = rpc .GetChainHeight (clientCtx )
336+ if err != nil {
337+ return fmt .Errorf ("failed to get chain height: %w" , err )
338+ }
320339 }
321340
322- blockRes , err := node .BlockResults (context .Background (), height )
341+ blockRes , err := node .BlockResults (context .Background (), & height )
323342 if err != nil {
324343 return err
325344 }
@@ -341,21 +360,6 @@ func QueryBlockResultsCmd() *cobra.Command {
341360 return cmd
342361}
343362
344- func parseOptionalHeight (heightStr string ) (* int64 , error ) {
345- h , err := strconv .Atoi (heightStr )
346- if err != nil {
347- return nil , err
348- }
349-
350- if h == 0 {
351- return nil , nil
352- }
353-
354- tmp := int64 (h )
355-
356- return & tmp , nil
357- }
358-
359363func BootstrapStateCmd (appCreator types.AppCreator ) * cobra.Command {
360364 cmd := & cobra.Command {
361365 Use : "bootstrap-state" ,
0 commit comments