@@ -603,6 +603,11 @@ type GetCurrentValidatorsArgs struct {
603603 // Subnet we're listing the validators of
604604 // If omitted, defaults to primary network
605605 SubnetID ids.ID `json:"subnetID"`
606+ // NodeIDs of validators to request. If [NodeIDs]
607+ // is empty, it fetches all current validators. If
608+ // some nodeIDs are not currently validators, they
609+ // will be omitted from the response.
610+ NodeIDs []string `json:"nodeIDs"`
606611}
607612
608613// GetCurrentValidatorsReply are the results from calling GetCurrentValidators.
@@ -620,6 +625,17 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
620625 // Validator's node ID as string --> Delegators to them
621626 vdrTodelegators := map [string ][]APIPrimaryDelegator {}
622627
628+ // Create set of nodeIDs
629+ nodeIDs := ids.ShortSet {}
630+ for _ , nodeID := range args .NodeIDs {
631+ nID , err := ids .ShortFromPrefixedString (nodeID , constants .NodeIDPrefix )
632+ if err != nil {
633+ return err
634+ }
635+ nodeIDs .Add (nID )
636+ }
637+ includeAllNodes := nodeIDs .Len () == 0
638+
623639 stopPrefix := []byte (fmt .Sprintf ("%s%s" , args .SubnetID , stopDBPrefix ))
624640 stopDB := prefixdb .NewNested (stopPrefix , service .vm .DB )
625641 defer stopDB .Close ()
@@ -640,6 +656,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
640656
641657 switch staker := tx .Tx .UnsignedTx .(type ) {
642658 case * UnsignedAddDelegatorTx :
659+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
660+ continue
661+ }
662+
643663 weight := json .Uint64 (staker .Validator .Weight ())
644664
645665 var rewardOwner * APIOwner
@@ -672,6 +692,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
672692 }
673693 vdrTodelegators [delegator .NodeID ] = append (vdrTodelegators [delegator .NodeID ], delegator )
674694 case * UnsignedAddValidatorTx :
695+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
696+ continue
697+ }
698+
675699 nodeID := staker .Validator .ID ()
676700 startTime := staker .StartTime ()
677701 weight := json .Uint64 (staker .Validator .Weight ())
@@ -716,6 +740,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
716740 DelegationFee : delegationFee ,
717741 })
718742 case * UnsignedAddSubnetValidatorTx :
743+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
744+ continue
745+ }
746+
719747 weight := json .Uint64 (staker .Validator .Weight ())
720748 reply .Validators = append (reply .Validators , APIStaker {
721749 TxID : tx .Tx .ID (),
@@ -751,6 +779,11 @@ type GetPendingValidatorsArgs struct {
751779 // Subnet we're getting the pending validators of
752780 // If omitted, defaults to primary network
753781 SubnetID ids.ID `json:"subnetID"`
782+ // NodeIDs of validators to request. If [NodeIDs]
783+ // is empty, it fetches all pending validators. If
784+ // some requested nodeIDs are not pending validators,
785+ // they are omitted from the response.
786+ NodeIDs []string `json:"nodeIDs"`
754787}
755788
756789// GetPendingValidatorsReply are the results from calling GetPendingValidators.
@@ -767,6 +800,17 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
767800 reply .Validators = []interface {}{}
768801 reply .Delegators = []interface {}{}
769802
803+ // Create set of nodeIDs
804+ nodeIDs := ids.ShortSet {}
805+ for _ , nodeID := range args .NodeIDs {
806+ nID , err := ids .ShortFromPrefixedString (nodeID , constants .NodeIDPrefix )
807+ if err != nil {
808+ return err
809+ }
810+ nodeIDs .Add (nID )
811+ }
812+ includeAllNodes := nodeIDs .Len () == 0
813+
770814 startPrefix := []byte (fmt .Sprintf ("%s%s" , args .SubnetID , startDBPrefix ))
771815 startDB := prefixdb .NewNested (startPrefix , service .vm .DB )
772816 defer startDB .Close ()
@@ -787,6 +831,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
787831
788832 switch staker := tx .UnsignedTx .(type ) {
789833 case * UnsignedAddDelegatorTx :
834+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
835+ continue
836+ }
837+
790838 weight := json .Uint64 (staker .Validator .Weight ())
791839 reply .Delegators = append (reply .Delegators , APIStaker {
792840 TxID : tx .ID (),
@@ -796,6 +844,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
796844 StakeAmount : & weight ,
797845 })
798846 case * UnsignedAddValidatorTx :
847+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
848+ continue
849+ }
850+
799851 nodeID := staker .Validator .ID ()
800852 weight := json .Uint64 (staker .Validator .Weight ())
801853 delegationFee := json .Float32 (100 * float32 (staker .Shares ) / float32 (PercentDenominator ))
@@ -813,6 +865,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
813865 Connected : & connected ,
814866 })
815867 case * UnsignedAddSubnetValidatorTx :
868+ if ! includeAllNodes && ! nodeIDs .Contains (staker .Validator .ID ()) {
869+ continue
870+ }
871+
816872 weight := json .Uint64 (staker .Validator .Weight ())
817873 reply .Validators = append (reply .Validators , APIStaker {
818874 TxID : tx .ID (),
0 commit comments