Skip to content

Commit

Permalink
feat: return the number of active proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Jun 14, 2023
1 parent 2582466 commit a438ef2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions general.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/google/uuid"
Expand Down Expand Up @@ -93,6 +94,14 @@ func (s *service) GeneralHandler(w http.ResponseWriter, r *http.Request) {
},
)

paramsGovVotingPeriodProposals := prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "cosmos_gov_voting_period_proposals",
Help: "Voting period proposals",
ConstLabels: ConstLabels,
},
)

registry := prometheus.NewRegistry()
registry.MustRegister(generalBondedTokensGauge)
registry.MustRegister(generalNotBondedTokensGauge)
Expand All @@ -102,6 +111,7 @@ func (s *service) GeneralHandler(w http.ResponseWriter, r *http.Request) {
registry.MustRegister(generalAnnualProvisions)
registry.MustRegister(generalLatestBlockHeight)
registry.MustRegister(generalTokenPrice)
registry.MustRegister(paramsGovVotingPeriodProposals)

var wg sync.WaitGroup

Expand Down Expand Up @@ -297,6 +307,24 @@ func (s *service) GeneralHandler(w http.ResponseWriter, r *http.Request) {
}
}()

wg.Add(1)
go func() {
defer wg.Done()
sublogger.Debug().Msg("Started querying global gov params")
govClient := govtypes.NewQueryClient(s.grpcConn)
proposals, err := govClient.Proposals(context.Background(), &govtypes.QueryProposalsRequest{
ProposalStatus: govtypes.StatusVotingPeriod,
})
if err != nil {
sublogger.Error().
Err(err).
Msg("Could not get active proposals")
}

proposalsCount := len(proposals.GetProposals())
paramsGovVotingPeriodProposals.Set(float64(proposalsCount))
}()

wg.Wait()

h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
Expand Down

0 comments on commit a438ef2

Please sign in to comment.