Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle big size exponent #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
main

dist/
.idea
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.18 AS exporter

ENV GOBIN=/go/bin
ENV GOPATH=/go
ENV CGO_ENABLED=0
ENV GOOS=linux

RUN git clone "https://github.com/solarlabsteam/cosmos-exporter" /exporter
WORKDIR /exporter
RUN go install

FROM debian:buster-slim

RUN apt-get update && apt-get upgrade && apt-get install -y curl
RUN useradd -ms /bin/bash exporter && chown -R exporter /usr

COPY --from=exporter /go/bin/main /usr/bin/cosmos-exporter

USER exporter
11 changes: 9 additions & 2 deletions general.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"math/big"
"net/http"
"strconv"
"sync"
Expand Down Expand Up @@ -105,8 +106,14 @@ func GeneralHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Clien
Float64("request-time", time.Since(queryStart).Seconds()).
Msg("Finished querying staking pool")

generalBondedTokensGauge.Set(float64(response.Pool.BondedTokens.Int64()))
generalNotBondedTokensGauge.Set(float64(response.Pool.NotBondedTokens.Int64()))
bondedTokensBigInt := response.Pool.BondedTokens.BigInt()
bondedTokens, _ := new(big.Float).SetInt(bondedTokensBigInt).Float64()

notBondedTokensBigInt := response.Pool.NotBondedTokens.BigInt()
notBondedTokens, _ := new(big.Float).SetInt(notBondedTokensBigInt).Float64()

generalBondedTokensGauge.Set(bondedTokens)
generalNotBondedTokensGauge.Set(notBondedTokens)
}()

wg.Add(1)
Expand Down
6 changes: 6 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ func ValidatorHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cli
firstShares, firstErr := strconv.ParseFloat(validators[i].DelegatorShares.String(), 64)
secondShares, secondErr := strconv.ParseFloat(validators[j].DelegatorShares.String(), 64)

if !validators[i].IsBonded() && validators[j].IsBonded() {
return false
} else if validators[i].IsBonded() && !validators[j].IsBonded() {
return true
}

if firstErr != nil || secondErr != nil {
sublogger.Error().
Err(err).
Expand Down
9 changes: 7 additions & 2 deletions validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ func ValidatorsHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cl
Msg("Finished querying validators")
validators = validatorsResponse.Validators

// sorting by delegator shares to display rankings
// sorting by delegator shares to display rankings (unbonded go last)
sort.Slice(validators, func(i, j int) bool {
return validators[i].DelegatorShares.RoundInt64() > validators[j].DelegatorShares.RoundInt64()
if !validators[i].IsBonded() && validators[j].IsBonded() {
return false
} else if validators[i].IsBonded() && !validators[j].IsBonded() {
return true
}
return validators[i].DelegatorShares.BigInt().Cmp(validators[j].DelegatorShares.BigInt()) > 0
})
}()

Expand Down