[staking] nil pointer check
@@ -402,7 +402,7 @@ func (c *candSR) readStateBucketsByVoter(ctx context.Context, req *iotexapi.Read
func (c *candSR) readStateBucketsByCandidate(ctx context.Context, req *iotexapi.ReadStakingDataRequest_VoteBucketsByCandidate) (*iotextypes.VoteBucketList, uint64, error) {
cand := c.GetCandidateByName(req.GetCandName())
- if c == nil {
+ if cand == nil {
return &iotextypes.VoteBucketList{}, 0, nil
}
@@ -466,7 +466,7 @@ func (c *candSR) readStateCandidates(ctx context.Context, req *iotexapi.ReadStak
func (c *candSR) readStateCandidateByName(ctx context.Context, req *iotexapi.ReadStakingDataRequest_CandidateByName) (*iotextypes.CandidateV2, uint64, error) {
cand := c.GetCandidateByName(req.GetCandName())
- if c == nil {
+ if cand == nil {
return &iotextypes.CandidateV2{}, c.Height(), nil
}
return cand.toIoTeXTypes(), c.Height(), nil
@@ -478,7 +478,7 @@ func (c *candSR) readStateCandidateByAddress(ctx context.Context, req *iotexapi.
return nil, 0, err
}
cand := c.GetCandidateByOwner(owner)
- if c == nil {
+ if cand == nil {
return &iotextypes.CandidateV2{}, c.Height(), nil
}
return cand.toIoTeXTypes(), c.Height(), nil
