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

supply querier #4592

Merged
merged 189 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 186 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
e8533ee
supply module
fedekunze May 2, 2019
0866d2e
invariants
fedekunze May 2, 2019
89a54e4
add to gaia, tests, minor fixes
fedekunze May 2, 2019
cf02698
tests
fedekunze May 2, 2019
7f3a5c9
fixes
fedekunze May 2, 2019
e19d098
expected crisis keeper
fedekunze May 2, 2019
d2c13a6
accounts
fedekunze May 5, 2019
bb12b4f
supply bank
fedekunze May 5, 2019
1983151
total supply type and keeper
fedekunze May 5, 2019
ce46707
Apply suggestions from code review
alexanderbez May 5, 2019
26c4804
cleanup app.go
fedekunze May 5, 2019
f67852b
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze May 5, 2019
7200d2e
genesis stuff
fedekunze May 5, 2019
8940db4
fix error checks
fedekunze May 5, 2019
eeaa0c3
gov module holder account
fedekunze May 6, 2019
bc314a9
some gov tests
fedekunze May 6, 2019
739673a
remove fee collector keeper and staking pool
fedekunze May 8, 2019
03564c1
more fixes on staking
fedekunze May 8, 2019
d59b287
fix gov supplyKeeper
fedekunze May 10, 2019
249ae59
remove staking pool fixes
fedekunze May 10, 2019
1dda132
fix mock mod
fedekunze May 10, 2019
06c65d7
more staking pool changes
fedekunze May 13, 2019
1186198
more changes in tests
fedekunze May 14, 2019
fe1e028
remove fee pool from store
fedekunze May 14, 2019
7afdfad
extend pool accs to use DecCoins instead of Coins
fedekunze May 14, 2019
310f566
revert DecCoins
fedekunze May 14, 2019
6f38715
some build fixes
fedekunze May 14, 2019
1cf75b6
revert changes from distr
fedekunze May 14, 2019
a93874c
cleanup supply module's bank logic
fedekunze May 14, 2019
8fe8afb
cleanup supply, remove inflate/deflate exported funcs
fedekunze May 15, 2019
859c1bb
remove inflate
fedekunze May 15, 2019
c5f8b91
more fixes
fedekunze May 16, 2019
6f45043
@rigelrozanski gen modularization PR changes
fedekunze May 16, 2019
f6d73e7
golangci bot and rename distr module name
fedekunze May 16, 2019
212cc2a
supply module.go changes
fedekunze May 16, 2019
32942d0
add supply to gaia
fedekunze May 16, 2019
8dc60dc
register account types and interfaces in x/auth
fedekunze May 16, 2019
a0c95c1
fix some tests
fedekunze May 16, 2019
68cf00e
fix tests part 2
fedekunze May 17, 2019
dbaab38
remove gaia changes
fedekunze May 22, 2019
71537bd
not bonded pool only holds coins from staking
fedekunze May 23, 2019
27d9c7e
fix tests pt 3
fedekunze May 23, 2019
1fee72e
more tests fixes
fedekunze May 23, 2019
6dc28a4
genesis changes when module accs are not set
fedekunze May 24, 2019
f8aa29c
Fix all amino codec related panics for Fede (#4407)
liamsi May 24, 2019
ae28518
test fixes and changes
fedekunze May 24, 2019
bec358d
revert query staking pool to use sdk.Int
fedekunze May 24, 2019
8007eb1
remove err from GetAccs
fedekunze May 24, 2019
668b64d
supply keeper tests
fedekunze May 24, 2019
797939b
rename PoolAccount to ModuleAccount
fedekunze May 24, 2019
c23f219
edit supply account
fedekunze May 24, 2019
9240934
rename bank supply funcs
fedekunze May 24, 2019
86f328e
fix tests and add getters for module accs
fedekunze May 26, 2019
2d7f208
burn tokens removed from validator
fedekunze May 26, 2019
9979dc3
fixes
fedekunze May 26, 2019
1029eb4
fix ante and mint
fedekunze May 27, 2019
16bfc2e
fix sig verification
fedekunze May 27, 2019
ac6477e
fix fast sim
fedekunze May 27, 2019
6f3aa19
update genesis account to support module accs
fedekunze May 27, 2019
6f466fc
lint
fedekunze May 27, 2019
1c326ea
fix conflicts w/ master
fedekunze May 27, 2019
b57c103
renamings and other minor changes
fedekunze May 28, 2019
b3e32bb
few minor changes
fedekunze May 28, 2019
32fdfe0
update invariants to be consistent with genesis
fedekunze May 28, 2019
84493fd
refactor gov keys
fedekunze May 31, 2019
91e9c68
iterators and renamings
fedekunze May 31, 2019
de49818
invert queue key order
fedekunze May 31, 2019
8194039
changelog
fedekunze May 31, 2019
1df9b17
fix tests
fedekunze May 31, 2019
0215c8a
update alias.go
fedekunze May 31, 2019
e314157
update alias.go
fedekunze May 31, 2019
b9a7d88
Apply suggestions from code review
fedekunze Jun 3, 2019
01fcfdf
rename keys
fedekunze Jun 3, 2019
0e649f0
rename functions
fedekunze Jun 3, 2019
0fe446c
merge in master
fedekunze Jun 3, 2019
9acdca4
conflicts
fedekunze Jun 3, 2019
a4d0029
merge gov iterators PR
fedekunze Jun 3, 2019
e4f1fc3
gov invariant
fedekunze Jun 3, 2019
02b69f0
Apply suggestions from code review
fedekunze Jun 3, 2019
c0d0c04
address Aleks' comments
fedekunze Jun 3, 2019
476a606
fix test
fedekunze Jun 3, 2019
7fec55e
Merge branch 'fedekunze/gov-fixes' of https://github.com/cosmos/cosmo…
fedekunze Jun 3, 2019
3d5fb26
fix invariants simulation
fedekunze Jun 3, 2019
6ae7647
update staking tests
fedekunze Jun 4, 2019
7c6a6af
improved simulation logs
fedekunze Jun 4, 2019
76f77ae
fix account number error
fedekunze Jun 4, 2019
a96936d
fix conflicts with master
fedekunze Jun 5, 2019
dc89796
leftover changes
fedekunze Jun 5, 2019
444e191
fix merge conflicts and tests
fedekunze Jun 6, 2019
6e78171
merge master
fedekunze Jun 6, 2019
b59a40f
Delete LOCK
fedekunze Jun 6, 2019
f19ffda
Delete LOG
fedekunze Jun 6, 2019
80f2efa
minor changes
fedekunze Jun 6, 2019
29adde8
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 6, 2019
11e96b3
reduce invariance amount
fedekunze Jun 7, 2019
6e9f686
minor changes
fedekunze Jun 10, 2019
b411d79
update supply keeper to use bank keeper
fedekunze Jun 10, 2019
89ab360
reaname GetPools
fedekunze Jun 10, 2019
8b35156
use supply (un)delegateCoins
fedekunze Jun 10, 2019
801d265
fix benchmark invariants
fedekunze Jun 10, 2019
3002808
merge master and resolve conflicts
fedekunze Jun 11, 2019
6a00e9c
fixed simulations !
fedekunze Jun 11, 2019
26260f3
Apply suggestions from code review
fedekunze Jun 12, 2019
ae4cf68
addressed minor comments from code reviews
fedekunze Jun 12, 2019
3810674
move validator funcs back to types
fedekunze Jun 13, 2019
b0f5953
update (un)delegateCoins
fedekunze Jun 13, 2019
e357b60
fix panic
fedekunze Jun 13, 2019
a61e7b4
set maccs on simapp, panic on genesis and make feeCollector a macc
fedekunze Jun 15, 2019
0b289d6
populate module account coins on genesis
fedekunze Jun 15, 2019
173f086
more updates (broken)
fedekunze Jun 16, 2019
0de237e
fix test_cover
rigelrozanski Jun 16, 2019
2153e24
work through a bunch of core changes
rigelrozanski Jun 16, 2019
c79e804
fix some tests
fedekunze Jun 17, 2019
c8438d5
working debugging make test
rigelrozanski Jun 17, 2019
8aa7500
fix make test
rigelrozanski Jun 17, 2019
931c163
misspell
rigelrozanski Jun 17, 2019
05d672b
minor changes
fedekunze Jun 18, 2019
67a62db
sendDelegatedCoins
fedekunze Jun 18, 2019
3777eb1
update (un)delegate coins
fedekunze Jun 18, 2019
1a663e7
merge changes from master
fedekunze Jun 19, 2019
7a399a5
update alias
fedekunze Jun 19, 2019
06fec07
minor updates
fedekunze Jun 19, 2019
5d1b409
supply Queriers
fedekunze Jun 19, 2019
0ee27d7
add cmd and rest routes to module
fedekunze Jun 19, 2019
2d3b2a8
update swagger API
fedekunze Jun 20, 2019
1cbe788
return err on unmarshal and minor refactor on querier
fedekunze Jun 20, 2019
ffcf962
fix TestUpdateValidatorByPowerIndex
rigelrozanski Jun 20, 2019
8668af8
fix TestGetValidatorsEdgeCases
rigelrozanski Jun 20, 2019
94e8b66
merge cmds
fedekunze Jun 20, 2019
9ff5736
supply refactors (#4604)
rigelrozanski Jun 25, 2019
bd072bb
Merge remote-tracking branch 'origin/master' into fedekunze/3972-supply
rigelrozanski Jun 25, 2019
9cc078d
build conflicts fixed
rigelrozanski Jun 25, 2019
6738963
fix TestAnteHandlerFees
rigelrozanski Jun 25, 2019
ee22929
linting
rigelrozanski Jun 25, 2019
877e228
remove retrieveSimLog
rigelrozanski Jun 25, 2019
0d95280
add logger for mint and burn
fedekunze Jun 25, 2019
5df3f65
log fixes / working on removing embedded module addresses
rigelrozanski Jun 25, 2019
2c6eeed
remove all references to Module Addresses
rigelrozanski Jun 25, 2019
e201cee
simulation changes
rigelrozanski Jun 25, 2019
a6e73cd
fix yaml
fedekunze Jun 25, 2019
937327d
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 25, 2019
a27e948
HandleCommunityPoolSpendProposal common code refactor
rigelrozanski Jun 25, 2019
9594ed6
redelegation dstValidator slashing supply fix
rigelrozanski Jun 25, 2019
02daec9
typo
rigelrozanski Jun 25, 2019
15c2f93
remove panic
fedekunze Jun 25, 2019
b1e6dbc
minor fix
fedekunze Jun 25, 2019
2bbc348
merge supply
fedekunze Jun 25, 2019
f78b468
resolve conflicts
fedekunze Jun 26, 2019
62b897c
fix tests
fedekunze Jun 26, 2019
7dd0e1e
lint
fedekunze Jun 26, 2019
7767d1c
minor changes
fedekunze Jun 26, 2019
a8bac8a
unused export
rigelrozanski Jun 26, 2019
effd5d8
Apply suggestions from code review
fedekunze Jun 26, 2019
05c7952
address @alexanderbez comments
fedekunze Jun 26, 2019
4f073d4
merge supply
fedekunze Jun 26, 2019
63c9a35
move fee deduction to the original place in ante-handler
rigelrozanski Jun 26, 2019
0eed53f
rename holder permission and address some comments from Rigel
fedekunze Jun 27, 2019
d1309f5
pass fee collector name; fix sim bug
fedekunze Jun 27, 2019
f1787eb
remove fee collector name from core module logic
fedekunze Jun 27, 2019
cfbbba6
set account before return
fedekunze Jun 27, 2019
f609ad6
panic if not a module account
rigelrozanski Jun 27, 2019
0bf09f7
proper module account creation
rigelrozanski Jun 27, 2019
e9e7acc
fix make test
rigelrozanski Jun 27, 2019
cecbb34
fix make test
rigelrozanski Jun 27, 2019
01b4891
sim test util
fedekunze Jun 27, 2019
6b91a29
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 27, 2019
f46dbd8
lint fix
rigelrozanski Jun 27, 2019
50d5de7
resolve import export bug
rigelrozanski Jun 27, 2019
687fa79
fix conflicts with master
fedekunze Jun 28, 2019
b7de554
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 28, 2019
69b48a1
cha-cha-cha
fedekunze Jun 28, 2019
ae281ad
Update simapp/sim_test.go
fedekunze Jun 28, 2019
92d0702
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
5f1f0e9
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
16ff6df
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
6224dda
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
ef2c8c2
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
8b29a19
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
d7a9ca0
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
c78f378
Update x/slashing/keeper.go
fedekunze Jun 28, 2019
bdeea26
address final @alexanderbez comments
fedekunze Jun 28, 2019
a1d0001
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 28, 2019
db22422
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze Jun 28, 2019
2cbc75f
fix conflicts
fedekunze Jun 28, 2019
e0aea02
pending
fedekunze Jun 28, 2019
fbe8e69
Update 4595-supply-queriers
fedekunze Jun 28, 2019
57d38be
Address @alessio 's suggestions
fedekunze Jun 29, 2019
ad73508
fix test
fedekunze Jun 30, 2019
4ad412d
set cliCtx.WithHeight(). cc @colin-axner
fedekunze Jun 30, 2019
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 .pending/improvements/sdk/4595-supply-queriers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4082 supply module queriers for CLI and REST endpoints
2 changes: 1 addition & 1 deletion client/lcd/statik/statik.go

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ tags:
description: Slashing module APIs
- name: Distribution
description: Fee distribution module APIs
- name: Supply
description: Supply module APIs
- name: version
- name: Mint
description: Minting module APIs
- name: Misc
Expand Down Expand Up @@ -1827,6 +1830,43 @@ paths:
type: string
500:
description: Internal Server Error
/supply/total:
get:
summary: Total supply of coins in the chain
tags:
- Supply
produces:
- application/json
responses:
200:
description: OK
schema:
$ref: "#/definitions/Supply"
500:
description: Internal Server Error
/supply/total/{denomination}:
parameters:
- in: path
name: denomination
description: Coin denomination
required: true
type: string
x-example: uatom
get:
summary: Total supply of a single coin denomination
tags:
- Supply
produces:
- application/json
responses:
200:
description: OK
schema:
type: integer
400:
description: Invalid coin denomination
500:
description: Internal Server Error
definitions:
CheckTxResult:
type: object
Expand Down Expand Up @@ -2435,3 +2475,10 @@ definitions:
example: ""
value:
type: object
Supply:
type: object
properties:
total:
type: array
items:
$ref: "#/definitions/Coin"
104 changes: 104 additions & 0 deletions x/supply/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cli

import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/spf13/cobra"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
// Group supply queries under a subcommand
supplyQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the supply module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

supplyQueryCmd.AddCommand(client.GetCommands(
GetCmdQueryTotalSupply(cdc),
)...)

return supplyQueryCmd
}

// GetCmdQueryTotalSupply implements the query total supply command.
func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "total [denom (optional)]",
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
Args: cobra.MaximumNArgs(1),
Short: "Query the total supply of coins of the chain",
Long: strings.TrimSpace(
fmt.Sprintf(`Query total supply of coins that are held by accounts in the
chain.

Example:
$ %s query %s total

To query for the total supply of a specific coin denomination use:
$ %s query %s total stake
`,
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

if len(args) == 0 {
return queryTotalSupply(cliCtx, cdc)
}
return querySupplyOf(cliCtx, cdc, args[0])
},
}
}

func queryTotalSupply(cliCtx context.CLIContext, cdc *codec.Codec) error {
params := types.NewQueryTotalSupplyParams(1, 0) // no pagination
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), bz)
if err != nil {
return err
}

var totalSupply sdk.Coins
err = cdc.UnmarshalJSON(res, &totalSupply)
if err != nil {
return err
}

return cliCtx.PrintOutput(totalSupply)
}

func querySupplyOf(cliCtx context.CLIContext, cdc *codec.Codec, denom string) error {
params := types.NewQuerySupplyOfParams(denom)
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySupplyOf), bz)
if err != nil {
return err
}

var supply sdk.Int
err = cdc.UnmarshalJSON(res, &supply)
if err != nil {
return err
}

return cliCtx.PrintOutput(supply)
}
88 changes: 88 additions & 0 deletions x/supply/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package rest

import (
"fmt"
"net/http"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/supply/types"
)

// RegisterRoutes registers staking-related REST handlers to a router
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
registerQueryRoutes(cliCtx, r)
}

func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
// Query the total supply of coins
r.HandleFunc(
"/supply/total/",
totalSupplyHandlerFn(cliCtx),
).Methods("GET")

// Query the supply of a single denom
r.HandleFunc(
"/supply/total/{denom}",
supplyOfHandlerFn(cliCtx),
).Methods("GET")
}

// HTTP request handler to query the total supply of coins
func totalSupplyHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

params := types.NewQueryTotalSupplyParams(page, limit)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), bz)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

rest.PostProcessResponse(w, cliCtx, res)
}
}

// HTTP request handler to query the supply of a single denom
func supplyOfHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
denom := mux.Vars(r)["denom"]
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

params := types.NewQuerySupplyOfParams(denom)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySupplyOf), bz)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

rest.PostProcessResponse(w, cliCtx, res)
}
}
78 changes: 78 additions & 0 deletions x/supply/keeper/querier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package keeper

import (
"fmt"

abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
)

// NewQuerier creates a querier for supply REST endpoints
func NewQuerier(k Keeper) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) {
switch path[0] {
case types.QueryTotalSupply:
return queryTotalSupply(ctx, req, k)
case types.QuerySupplyOf:
return querySupplyOf(ctx, req, k)
default:
return nil, sdk.ErrUnknownRequest("unknown supply query endpoint")
}
}
}

func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
var params types.QueryTotalSupplyParams

err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
}

totalSupply := k.GetSupply(ctx).Total
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
totalSupplyLen := len(totalSupply)

if params.Limit == 0 {
params.Limit = totalSupplyLen
}

start := (params.Page - 1) * params.Limit
end := params.Limit + start
if end >= totalSupplyLen {
end = totalSupplyLen
}

if start >= totalSupplyLen {
// page is out of bounds
totalSupply = sdk.Coins{}
} else {
totalSupply = totalSupply[start:end]
}

res, err := totalSupply.MarshalJSON()
if err != nil {
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error()))
}

return res, nil
}

func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
var params types.QuerySupplyOfParams

err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
}

supply := k.GetSupply(ctx).Total.AmountOf(params.Denom)

res, err := supply.MarshalJSON()
if err != nil {
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error()))
}

return res, nil
}
Loading