@@ -600,14 +600,17 @@ func (api *Server) readState(ctx context.Context, in *iotexapi.ReadStateRequest)
600
600
// GetActions returns actions within the range
601
601
// This is a workaround for the slow access issue if the start index is very big
602
602
func (api * Server ) getActions (start uint64 , count uint64 ) (* iotexapi.GetActionsResponse , error ) {
603
- if count == 0 || count > api .cfg .RangeQueryLimit {
603
+ if count > api .cfg .RangeQueryLimit {
604
604
return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
605
605
}
606
606
607
607
totalActions , err := api .bc .GetTotalActions ()
608
608
if err != nil {
609
609
return nil , status .Error (codes .Internal , err .Error ())
610
610
}
611
+ if totalActions == uint64 (0 ) {
612
+ return & iotexapi.GetActionsResponse {}, nil
613
+ }
611
614
if start >= totalActions {
612
615
return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
613
616
}
@@ -661,14 +664,17 @@ func (api *Server) getSingleAction(actionHash string, checkPending bool) (*iotex
661
664
662
665
// getActionsByAddress returns all actions associated with an address
663
666
func (api * Server ) getActionsByAddress (address string , start uint64 , count uint64 ) (* iotexapi.GetActionsResponse , error ) {
664
- if count == 0 || count > api .cfg .RangeQueryLimit {
667
+ if count > api .cfg .RangeQueryLimit {
665
668
return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
666
669
}
667
670
668
671
actions , err := api .getTotalActionsByAddress (address )
669
672
if err != nil {
670
673
return nil , status .Error (codes .NotFound , err .Error ())
671
674
}
675
+ if len (actions ) == 0 {
676
+ return & iotexapi.GetActionsResponse {}, nil
677
+ }
672
678
if start >= uint64 (len (actions )) {
673
679
return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
674
680
}
@@ -693,11 +699,14 @@ func (api *Server) getActionsByAddress(address string, start uint64, count uint6
693
699
694
700
// getUnconfirmedActionsByAddress returns all unconfirmed actions in actpool associated with an address
695
701
func (api * Server ) getUnconfirmedActionsByAddress (address string , start uint64 , count uint64 ) (* iotexapi.GetActionsResponse , error ) {
696
- if count == 0 || count > api .cfg .RangeQueryLimit {
702
+ if count > api .cfg .RangeQueryLimit {
697
703
return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
698
704
}
699
705
700
706
selps := api .ap .GetUnconfirmedActs (address )
707
+ if len (selps ) == 0 {
708
+ return & iotexapi.GetActionsResponse {}, nil
709
+ }
701
710
if start >= uint64 (len (selps )) {
702
711
return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
703
712
}
@@ -718,7 +727,7 @@ func (api *Server) getUnconfirmedActionsByAddress(address string, start uint64,
718
727
719
728
// getActionsByBlock returns all actions in a block
720
729
func (api * Server ) getActionsByBlock (blkHash string , start uint64 , count uint64 ) (* iotexapi.GetActionsResponse , error ) {
721
- if count == 0 || count > api .cfg .RangeQueryLimit {
730
+ if count > api .cfg .RangeQueryLimit {
722
731
return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
723
732
}
724
733
@@ -730,20 +739,23 @@ func (api *Server) getActionsByBlock(blkHash string, start uint64, count uint64)
730
739
if err != nil {
731
740
return nil , status .Error (codes .NotFound , err .Error ())
732
741
}
742
+ if len (blk .Actions ) == 0 {
743
+ return & iotexapi.GetActionsResponse {}, nil
744
+ }
733
745
if start >= uint64 (len (blk .Actions )) {
734
746
return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
735
747
}
736
748
737
749
res := api .actionsInBlock (blk , start , count )
738
750
return & iotexapi.GetActionsResponse {
739
- Total : uint64 (len (res )),
751
+ Total : uint64 (len (blk . Actions )),
740
752
ActionInfo : res ,
741
753
}, nil
742
754
}
743
755
744
756
// getBlockMetas gets block within the height range
745
757
func (api * Server ) getBlockMetas (start uint64 , count uint64 ) (* iotexapi.GetBlockMetasResponse , error ) {
746
- if count == 0 || count > api .cfg .RangeQueryLimit {
758
+ if count > api .cfg .RangeQueryLimit {
747
759
return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
748
760
}
749
761
0 commit comments