@@ -600,14 +600,17 @@ func (api *Server) readState(ctx context.Context, in *iotexapi.ReadStateRequest)
600600// GetActions returns actions within the range
601601// This is a workaround for the slow access issue if the start index is very big
602602func (api * Server ) getActions (start uint64 , count uint64 ) (* iotexapi.GetActionsResponse , error ) {
603- if count == 0 || count > api .cfg .RangeQueryLimit {
603+ if count > api .cfg .RangeQueryLimit {
604604 return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
605605 }
606606
607607 totalActions , err := api .bc .GetTotalActions ()
608608 if err != nil {
609609 return nil , status .Error (codes .Internal , err .Error ())
610610 }
611+ if totalActions == uint64 (0 ) {
612+ return & iotexapi.GetActionsResponse {}, nil
613+ }
611614 if start >= totalActions {
612615 return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
613616 }
@@ -661,14 +664,17 @@ func (api *Server) getSingleAction(actionHash string, checkPending bool) (*iotex
661664
662665// getActionsByAddress returns all actions associated with an address
663666func (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 {
665668 return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
666669 }
667670
668671 actions , err := api .getTotalActionsByAddress (address )
669672 if err != nil {
670673 return nil , status .Error (codes .NotFound , err .Error ())
671674 }
675+ if len (actions ) == 0 {
676+ return & iotexapi.GetActionsResponse {}, nil
677+ }
672678 if start >= uint64 (len (actions )) {
673679 return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
674680 }
@@ -693,11 +699,14 @@ func (api *Server) getActionsByAddress(address string, start uint64, count uint6
693699
694700// getUnconfirmedActionsByAddress returns all unconfirmed actions in actpool associated with an address
695701func (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 {
697703 return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
698704 }
699705
700706 selps := api .ap .GetUnconfirmedActs (address )
707+ if len (selps ) == 0 {
708+ return & iotexapi.GetActionsResponse {}, nil
709+ }
701710 if start >= uint64 (len (selps )) {
702711 return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
703712 }
@@ -718,7 +727,7 @@ func (api *Server) getUnconfirmedActionsByAddress(address string, start uint64,
718727
719728// getActionsByBlock returns all actions in a block
720729func (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 {
722731 return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
723732 }
724733
@@ -730,20 +739,23 @@ func (api *Server) getActionsByBlock(blkHash string, start uint64, count uint64)
730739 if err != nil {
731740 return nil , status .Error (codes .NotFound , err .Error ())
732741 }
742+ if len (blk .Actions ) == 0 {
743+ return & iotexapi.GetActionsResponse {}, nil
744+ }
733745 if start >= uint64 (len (blk .Actions )) {
734746 return nil , status .Error (codes .InvalidArgument , "start exceeds the limit" )
735747 }
736748
737749 res := api .actionsInBlock (blk , start , count )
738750 return & iotexapi.GetActionsResponse {
739- Total : uint64 (len (res )),
751+ Total : uint64 (len (blk . Actions )),
740752 ActionInfo : res ,
741753 }, nil
742754}
743755
744756// getBlockMetas gets block within the height range
745757func (api * Server ) getBlockMetas (start uint64 , count uint64 ) (* iotexapi.GetBlockMetasResponse , error ) {
746- if count == 0 || count > api .cfg .RangeQueryLimit {
758+ if count > api .cfg .RangeQueryLimit {
747759 return nil , status .Error (codes .InvalidArgument , "range exceeds the limit" )
748760 }
749761
0 commit comments