-
Notifications
You must be signed in to change notification settings - Fork 4.2k
supply querier #4592
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
Merged
Merged
supply querier #4592
Changes from 186 commits
Commits
Show all changes
189 commits
Select commit
Hold shift + click to select a range
e8533ee
supply module
fedekunze 0866d2e
invariants
fedekunze 89a54e4
add to gaia, tests, minor fixes
fedekunze cf02698
tests
fedekunze 7f3a5c9
fixes
fedekunze e19d098
expected crisis keeper
fedekunze d2c13a6
accounts
fedekunze bb12b4f
supply bank
fedekunze 1983151
total supply type and keeper
fedekunze ce46707
Apply suggestions from code review
alexanderbez 26c4804
cleanup app.go
fedekunze f67852b
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze 7200d2e
genesis stuff
fedekunze 8940db4
fix error checks
fedekunze eeaa0c3
gov module holder account
fedekunze bc314a9
some gov tests
fedekunze 739673a
remove fee collector keeper and staking pool
fedekunze 03564c1
more fixes on staking
fedekunze d59b287
fix gov supplyKeeper
fedekunze 249ae59
remove staking pool fixes
fedekunze 1dda132
fix mock mod
fedekunze 06c65d7
more staking pool changes
fedekunze 1186198
more changes in tests
fedekunze fe1e028
remove fee pool from store
fedekunze 7afdfad
extend pool accs to use DecCoins instead of Coins
fedekunze 310f566
revert DecCoins
fedekunze 6f38715
some build fixes
fedekunze 1cf75b6
revert changes from distr
fedekunze a93874c
cleanup supply module's bank logic
fedekunze 8fe8afb
cleanup supply, remove inflate/deflate exported funcs
fedekunze 859c1bb
remove inflate
fedekunze c5f8b91
more fixes
fedekunze 6f45043
@rigelrozanski gen modularization PR changes
fedekunze f6d73e7
golangci bot and rename distr module name
fedekunze 212cc2a
supply module.go changes
fedekunze 32942d0
add supply to gaia
fedekunze 8dc60dc
register account types and interfaces in x/auth
fedekunze a0c95c1
fix some tests
fedekunze 68cf00e
fix tests part 2
fedekunze dbaab38
remove gaia changes
fedekunze 71537bd
not bonded pool only holds coins from staking
fedekunze 27d9c7e
fix tests pt 3
fedekunze 1fee72e
more tests fixes
fedekunze 6dc28a4
genesis changes when module accs are not set
fedekunze f8aa29c
Fix all amino codec related panics for Fede (#4407)
liamsi ae28518
test fixes and changes
fedekunze bec358d
revert query staking pool to use sdk.Int
fedekunze 8007eb1
remove err from GetAccs
fedekunze 668b64d
supply keeper tests
fedekunze 797939b
rename PoolAccount to ModuleAccount
fedekunze c23f219
edit supply account
fedekunze 9240934
rename bank supply funcs
fedekunze 86f328e
fix tests and add getters for module accs
fedekunze 2d7f208
burn tokens removed from validator
fedekunze 9979dc3
fixes
fedekunze 1029eb4
fix ante and mint
fedekunze 16bfc2e
fix sig verification
fedekunze ac6477e
fix fast sim
fedekunze 6f3aa19
update genesis account to support module accs
fedekunze 6f466fc
lint
fedekunze 1c326ea
fix conflicts w/ master
fedekunze b57c103
renamings and other minor changes
fedekunze b3e32bb
few minor changes
fedekunze 32fdfe0
update invariants to be consistent with genesis
fedekunze 84493fd
refactor gov keys
fedekunze 91e9c68
iterators and renamings
fedekunze de49818
invert queue key order
fedekunze 8194039
changelog
fedekunze 1df9b17
fix tests
fedekunze 0215c8a
update alias.go
fedekunze e314157
update alias.go
fedekunze b9a7d88
Apply suggestions from code review
fedekunze 01fcfdf
rename keys
fedekunze 0e649f0
rename functions
fedekunze 0fe446c
merge in master
fedekunze 9acdca4
conflicts
fedekunze a4d0029
merge gov iterators PR
fedekunze e4f1fc3
gov invariant
fedekunze 02b69f0
Apply suggestions from code review
fedekunze c0d0c04
address Aleks' comments
fedekunze 476a606
fix test
fedekunze 7fec55e
Merge branch 'fedekunze/gov-fixes' of https://github.com/cosmos/cosmo…
fedekunze 3d5fb26
fix invariants simulation
fedekunze 6ae7647
update staking tests
fedekunze 7c6a6af
improved simulation logs
fedekunze 76f77ae
fix account number error
fedekunze a96936d
fix conflicts with master
fedekunze dc89796
leftover changes
fedekunze 444e191
fix merge conflicts and tests
fedekunze 6e78171
merge master
fedekunze b59a40f
Delete LOCK
fedekunze f19ffda
Delete LOG
fedekunze 80f2efa
minor changes
fedekunze 29adde8
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze 11e96b3
reduce invariance amount
fedekunze 6e9f686
minor changes
fedekunze b411d79
update supply keeper to use bank keeper
fedekunze 89ab360
reaname GetPools
fedekunze 8b35156
use supply (un)delegateCoins
fedekunze 801d265
fix benchmark invariants
fedekunze 3002808
merge master and resolve conflicts
fedekunze 6a00e9c
fixed simulations !
fedekunze 26260f3
Apply suggestions from code review
fedekunze ae4cf68
addressed minor comments from code reviews
fedekunze 3810674
move validator funcs back to types
fedekunze b0f5953
update (un)delegateCoins
fedekunze e357b60
fix panic
fedekunze a61e7b4
set maccs on simapp, panic on genesis and make feeCollector a macc
fedekunze 0b289d6
populate module account coins on genesis
fedekunze 173f086
more updates (broken)
fedekunze 0de237e
fix test_cover
rigelrozanski 2153e24
work through a bunch of core changes
rigelrozanski c79e804
fix some tests
fedekunze c8438d5
working debugging make test
rigelrozanski 8aa7500
fix make test
rigelrozanski 931c163
misspell
rigelrozanski 05d672b
minor changes
fedekunze 67a62db
sendDelegatedCoins
fedekunze 3777eb1
update (un)delegate coins
fedekunze 1a663e7
merge changes from master
fedekunze 7a399a5
update alias
fedekunze 06fec07
minor updates
fedekunze 5d1b409
supply Queriers
fedekunze 0ee27d7
add cmd and rest routes to module
fedekunze 2d3b2a8
update swagger API
fedekunze 1cbe788
return err on unmarshal and minor refactor on querier
fedekunze ffcf962
fix TestUpdateValidatorByPowerIndex
rigelrozanski 8668af8
fix TestGetValidatorsEdgeCases
rigelrozanski 94e8b66
merge cmds
fedekunze 9ff5736
supply refactors (#4604)
rigelrozanski bd072bb
Merge remote-tracking branch 'origin/master' into fedekunze/3972-supply
rigelrozanski 9cc078d
build conflicts fixed
rigelrozanski 6738963
fix TestAnteHandlerFees
rigelrozanski ee22929
linting
rigelrozanski 877e228
remove retrieveSimLog
rigelrozanski 0d95280
add logger for mint and burn
fedekunze 5df3f65
log fixes / working on removing embedded module addresses
rigelrozanski 2c6eeed
remove all references to Module Addresses
rigelrozanski e201cee
simulation changes
rigelrozanski a6e73cd
fix yaml
fedekunze 937327d
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze a27e948
HandleCommunityPoolSpendProposal common code refactor
rigelrozanski 9594ed6
redelegation dstValidator slashing supply fix
rigelrozanski 02daec9
typo
rigelrozanski 15c2f93
remove panic
fedekunze b1e6dbc
minor fix
fedekunze 2bbc348
merge supply
fedekunze f78b468
resolve conflicts
fedekunze 62b897c
fix tests
fedekunze 7dd0e1e
lint
fedekunze 7767d1c
minor changes
fedekunze a8bac8a
unused export
rigelrozanski effd5d8
Apply suggestions from code review
fedekunze 05c7952
address @alexanderbez comments
fedekunze 4f073d4
merge supply
fedekunze 63c9a35
move fee deduction to the original place in ante-handler
rigelrozanski 0eed53f
rename holder permission and address some comments from Rigel
fedekunze d1309f5
pass fee collector name; fix sim bug
fedekunze f1787eb
remove fee collector name from core module logic
fedekunze cfbbba6
set account before return
fedekunze f609ad6
panic if not a module account
rigelrozanski 0bf09f7
proper module account creation
rigelrozanski e9e7acc
fix make test
rigelrozanski cecbb34
fix make test
rigelrozanski 01b4891
sim test util
fedekunze 6b91a29
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze f46dbd8
lint fix
rigelrozanski 50d5de7
resolve import export bug
rigelrozanski 687fa79
fix conflicts with master
fedekunze b7de554
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze 69b48a1
cha-cha-cha
fedekunze ae281ad
Update simapp/sim_test.go
fedekunze 92d0702
Update x/slashing/keeper.go
fedekunze 5f1f0e9
Update x/slashing/keeper.go
fedekunze 16ff6df
Update x/slashing/keeper.go
fedekunze 6224dda
Update x/slashing/keeper.go
fedekunze ef2c8c2
Update x/slashing/keeper.go
fedekunze 8b29a19
Update x/slashing/keeper.go
fedekunze d7a9ca0
Update x/slashing/keeper.go
fedekunze c78f378
Update x/slashing/keeper.go
fedekunze bdeea26
address final @alexanderbez comments
fedekunze a1d0001
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze db22422
Merge branch 'fedekunze/3972-supply' of https://github.com/cosmos/cos…
fedekunze 2cbc75f
fix conflicts
fedekunze e0aea02
pending
fedekunze fbe8e69
Update 4595-supply-queriers
fedekunze 57d38be
Address @alessio 's suggestions
fedekunze ad73508
fix test
fedekunze 4ad412d
set cliCtx.WithHeight(). cc @colin-axner
fedekunze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #4082 supply module queriers for CLI and REST endpoints |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)]", | ||
| 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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.
Outdated
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) | ||
| return | ||
| } | ||
|
|
||
| rest.PostProcessResponse(w, cliCtx, res) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, ¶ms) | ||
| 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, ¶ms) | ||
| 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 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.