Skip to content

Commit

Permalink
chore: use math.Int for string ints
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jun 22, 2024
1 parent d011163 commit 9b0dac0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/generators/signing_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"main/pkg/constants"
fetchersPkg "main/pkg/fetchers"
statePkg "main/pkg/state"
"main/pkg/utils"

"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -34,7 +33,7 @@ func (g *SigningInfoGenerator) Generate(state *statePkg.State) []prometheus.Coll

for chain, commissions := range data.SigningInfos {
for validator, signingInfo := range commissions {
missedBlocksCounter := utils.StrToInt64(signingInfo.ValSigningInfo.MissedBlocksCounter)
missedBlocksCounter := signingInfo.ValSigningInfo.MissedBlocksCounter.Int64()
if missedBlocksCounter >= 0 {
missedBlocksGauge.With(prometheus.Labels{
"chain": chain,
Expand Down
4 changes: 3 additions & 1 deletion pkg/generators/signing_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"main/pkg/types"
"testing"

"cosmossdk.io/math"

"github.com/stretchr/testify/assert"
)

Expand All @@ -28,7 +30,7 @@ func TestSigningInfoGeneratorNotEmptyState(t *testing.T) {
"chain": {
"validator": &types.SigningInfoResponse{
ValSigningInfo: types.SigningInfo{
MissedBlocksCounter: "100",
MissedBlocksCounter: math.NewInt(100),
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/generators/slashing_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"main/pkg/constants"
fetchersPkg "main/pkg/fetchers"
statePkg "main/pkg/state"
"main/pkg/utils"

"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -35,7 +34,7 @@ func (g *SlashingParamsGenerator) Generate(state *statePkg.State) []prometheus.C
for chain, params := range data.Params {
blocksWindowGauge.With(prometheus.Labels{
"chain": chain,
}).Set(float64(utils.StrToInt64(params.SlashingParams.SignedBlocksWindow)))
}).Set(float64(params.SlashingParams.SignedBlocksWindow.Int64()))
}

return []prometheus.Collector{blocksWindowGauge}
Expand Down
4 changes: 3 additions & 1 deletion pkg/generators/slashing_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"main/pkg/types"
"testing"

"cosmossdk.io/math"

"github.com/stretchr/testify/assert"
)

Expand All @@ -27,7 +29,7 @@ func TestSlashingParamsGeneratorNotEmptyState(t *testing.T) {
Params: map[string]*types.SlashingParamsResponse{
"chain": {
SlashingParams: types.SlashingParams{
SignedBlocksWindow: "100",
SignedBlocksWindow: math.NewInt(100),
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions pkg/types/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"main/pkg/constants"
"main/pkg/utils"
"time"

"cosmossdk.io/math"
)

type ValidatorResponse struct {
Expand Down Expand Up @@ -84,7 +86,7 @@ type SigningInfo struct {
IndexOffset string `json:"index_offset"`
JailedUntil time.Time `json:"jailed_until"`
Tombstoned bool `json:"tombstoned"`
MissedBlocksCounter string `json:"missed_blocks_counter"`
MissedBlocksCounter math.Int `json:"missed_blocks_counter"`
}

type SigningInfoResponse struct {
Expand All @@ -98,7 +100,7 @@ type AssignedKeyResponse struct {
}

type SlashingParams struct {
SignedBlocksWindow string `json:"signed_blocks_window"`
SignedBlocksWindow math.Int `json:"signed_blocks_window"`
}

type SlashingParamsResponse struct {
Expand Down

0 comments on commit 9b0dac0

Please sign in to comment.