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

add block height to supply response #5

Open
wants to merge 3 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
7 changes: 7 additions & 0 deletions x/supply/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func circulatingSupplyHandler(ctx client.Context) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
height, err := CurrentBlockHeight(ctx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

ctx = ctx.WithHeight(height)
rest.PostProcessResponse(w, ctx, out)
return
}
Expand Down
20 changes: 20 additions & 0 deletions x/supply/client/rest/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package rest

import (
"context"

"github.com/cosmos/cosmos-sdk/client"
)

// CurrentBlockHeight returns current block height of node
func CurrentBlockHeight(ctx client.Context) (int64, error) {
client, err := ctx.GetNode()
if err != nil {
return 0, err
}
status, err := client.Status(context.Background())
if err != nil {
return 0, err
}
return status.SyncInfo.LatestBlockHeight, nil
}
5 changes: 4 additions & 1 deletion x/supply/query/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (q Querier) Summary(c context.Context, req *types.QuerySummaryRequest) (*ty
vestingCoins := va.GetVestingCoins(ctx.BlockTime())
delegatedVesting := va.GetDelegatedVesting()
lockedCoins := va.LockedCoins(ctx.BlockTime())
spendableCoins := balances.Sub(lockedCoins)
var spendableCoins sdk.Coins
if balances.AmountOf(bondDenom).GT(lockedCoins.AmountOf(bondDenom)) {
spendableCoins = balances.Sub(lockedCoins)
}
if delegatedVesting.AmountOf(bondDenom).GT(vestingCoins.AmountOf(bondDenom)) {
supplyData.Vesting.Bonded = supplyData.Vesting.Bonded.Add(vestingCoins...)
supplyData.Available.Bonded = supplyData.Available.Bonded.Add(delegatedVesting...).Sub(vestingCoins)
Expand Down