added rpc.Provider interface
This commit is contained in:
parent
eef3cea353
commit
89d209f188
|
@ -25,7 +25,7 @@ func init() {
|
|||
}
|
||||
|
||||
type solanaCollector struct {
|
||||
rpcClient *rpc.Client
|
||||
rpcClient rpc.Provider
|
||||
|
||||
totalValidatorsDesc *prometheus.Desc
|
||||
validatorActivatedStake *prometheus.Desc
|
||||
|
@ -35,9 +35,9 @@ type solanaCollector struct {
|
|||
solanaVersion *prometheus.Desc
|
||||
}
|
||||
|
||||
func NewSolanaCollector(rpcAddr string) *solanaCollector {
|
||||
func createSolanaCollector(provider rpc.Provider) *solanaCollector {
|
||||
return &solanaCollector{
|
||||
rpcClient: rpc.NewRPCClient(rpcAddr),
|
||||
rpcClient: provider,
|
||||
totalValidatorsDesc: prometheus.NewDesc(
|
||||
"solana_active_validators",
|
||||
"Total number of active validators by state",
|
||||
|
@ -65,6 +65,10 @@ func NewSolanaCollector(rpcAddr string) *solanaCollector {
|
|||
}
|
||||
}
|
||||
|
||||
func NewSolanaCollector(rpcAddr string) *solanaCollector {
|
||||
return createSolanaCollector(rpc.NewRPCClient(rpcAddr))
|
||||
}
|
||||
|
||||
func (c *solanaCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.totalValidatorsDesc
|
||||
ch <- c.solanaVersion
|
||||
|
|
|
@ -164,7 +164,7 @@ func getEpochBounds(info *rpc.EpochInfo) (int64, int64, int64) {
|
|||
return info.Epoch, firstSlot, lastSlot
|
||||
}
|
||||
|
||||
func updateCounters(c *rpc.Client, epoch, firstSlot int64, lastSlotOpt *int64) (int64, error) {
|
||||
func updateCounters(c rpc.Provider, epoch, firstSlot int64, lastSlotOpt *int64) (int64, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), httpTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
|
|
@ -35,6 +35,14 @@ type (
|
|||
Commitment string
|
||||
)
|
||||
|
||||
type Provider interface {
|
||||
GetBlockProduction(ctx context.Context, firstSlot *int64, lastSlot *int64) (BlockProduction, error)
|
||||
GetEpochInfo(ctx context.Context, commitment Commitment) (*EpochInfo, error)
|
||||
GetSlot(ctx context.Context) (int64, error)
|
||||
GetVoteAccounts(ctx context.Context, params []interface{}) (*GetVoteAccountsResponse, error)
|
||||
GetVersion(ctx context.Context) (*string, error)
|
||||
}
|
||||
|
||||
func (c Commitment) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(map[string]string{"commitment": string(c)})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue