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

Merge x/supply into x/bank #6010

Merged
merged 29 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
abae2ec
Remove x/supply module
alexanderbez Apr 16, 2020
449bd18
Start migration
alexanderbez Apr 16, 2020
305b2d1
More updates
alexanderbez Apr 16, 2020
14d1f0d
Update codec
alexanderbez Apr 17, 2020
16cf70f
Update x/staking
alexanderbez Apr 17, 2020
c69418d
Update x/mint
alexanderbez Apr 17, 2020
c4fe6c2
Update x/ibc
alexanderbez Apr 17, 2020
5ba82da
Update x/gov
alexanderbez Apr 17, 2020
e6f2e6c
Lint
alexanderbez Apr 17, 2020
cd5b28e
Fix x/ibc
alexanderbez Apr 17, 2020
feb3a16
Update more mods
alexanderbez Apr 17, 2020
974fb33
Update x/auth
alexanderbez Apr 17, 2020
09194de
Update simapp
alexanderbez Apr 17, 2020
b1666d4
Update querier tests
alexanderbez Apr 17, 2020
124d689
Update keeper tests
alexanderbez Apr 17, 2020
3324a00
Merge branch 'master' into bez/5913-remove-supply-mod
alexanderbez Apr 17, 2020
5f9f528
Lint
alexanderbez Apr 17, 2020
dee0da7
Fix tests
alexanderbez Apr 17, 2020
68f0472
Fix TestImportExportQueues
alexanderbez Apr 17, 2020
2152b36
Add changelog entries
alexanderbez Apr 17, 2020
0c21364
Merge branch 'master' into bez/5913-remove-supply-mod
alexanderbez Apr 17, 2020
6c381e3
Merge branch 'master' into bez/5913-remove-supply-mod
alexanderbez Apr 17, 2020
2749dc3
Merge branch 'master' into bez/5913-remove-supply-mod
fedekunze Apr 18, 2020
702805b
Sim updates
alexanderbez Apr 19, 2020
50f0a14
Merge branch 'bez/5913-remove-supply-mod' of github.com:cosmos/cosmos…
alexanderbez Apr 19, 2020
f7c668a
Use module name
alexanderbez Apr 19, 2020
1bb8543
Fix bui;ld
alexanderbez Apr 19, 2020
e499b62
Merge branch 'master' into bez/5913-remove-supply-mod
fedekunze Apr 20, 2020
3e47909
Update x/auth/types/expected_keepers.go
alexanderbez Apr 20, 2020
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
27 changes: 20 additions & 7 deletions x/bank/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import (
const (
QueryBalance = types.QueryBalance
QueryAllBalances = types.QueryAllBalances
ModuleName = types.ModuleName
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
StoreKey = types.StoreKey
DefaultParamspace = types.DefaultParamspace
DefaultSendEnabled = types.DefaultSendEnabled

EventTypeTransfer = types.EventTypeTransfer
AttributeKeyRecipient = types.AttributeKeyRecipient
AttributeKeySender = types.AttributeKeySender
AttributeValueCategory = types.AttributeValueCategory

ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
Minter = types.Minter
Burner = types.Burner
Staking = types.Staking
)

var (
Expand All @@ -37,7 +41,6 @@ var (
ErrSendDisabled = types.ErrSendDisabled
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis
SanitizeGenesisBalances = types.SanitizeGenesisBalances
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
NewMsgSend = types.NewMsgSend
Expand All @@ -52,16 +55,21 @@ var (
ParamStoreKeySendEnabled = types.ParamStoreKeySendEnabled
BalancesPrefix = types.BalancesPrefix
AddressFromBalancesStore = types.AddressFromBalancesStore
AllInvariants = keeper.AllInvariants
TotalSupply = keeper.TotalSupply
NewModuleAddress = types.NewModuleAddress
NewEmptyModuleAccount = types.NewEmptyModuleAccount
NewModuleAccount = types.NewModuleAccount
NewSupply = types.NewSupply
DefaultSupply = types.DefaultSupply
)

type (
Keeper = keeper.Keeper
BaseKeeper = keeper.BaseKeeper
SendKeeper = keeper.SendKeeper
BaseSendKeeper = keeper.BaseSendKeeper
ViewKeeper = keeper.ViewKeeper
BaseViewKeeper = keeper.BaseViewKeeper
GenesisState = types.GenesisState
Balance = types.Balance
MsgSend = types.MsgSend
MsgMultiSend = types.MsgMultiSend
Expand All @@ -70,4 +78,9 @@ type (
QueryBalanceParams = types.QueryBalanceParams
QueryAllBalancesParams = types.QueryAllBalancesParams
GenesisBalancesIterator = types.GenesisBalancesIterator
Keeper = keeper.Keeper
ModuleAccount = types.ModuleAccount
GenesisState = types.GenesisState
Supply = types.Supply
Codec = types.Codec
)
4 changes: 2 additions & 2 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/supply"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestSendToModuleAcc(t *testing.T) {
{
name: "Allowed module account can be the recipient of bank sends",
fromBalance: coins,
msg: types.NewMsgSend(addr1, supply.NewModuleAddress(distribution.ModuleName), coins),
msg: types.NewMsgSend(addr1, bank.NewModuleAddress(distribution.ModuleName), coins),
expPass: true,
expSimPass: true,
expFromBalance: sdk.NewCoins(),
Expand Down
4 changes: 2 additions & 2 deletions x/bank/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)

var moduleAccAddr = supply.NewModuleAddress(staking.BondedPoolName)
var moduleAccAddr = bank.NewModuleAddress(staking.BondedPoolName)

func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
// Add an account at genesis
Expand Down
120 changes: 40 additions & 80 deletions x/bank/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -11,92 +12,14 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"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/bank/types"
)

const (
flagDenom = "denom"
)

// NewQueryCmd returns a root CLI command handler for all x/bank query commands.
func NewQueryCmd(m codec.Marshaler) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the bank module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(NewBalancesCmd(m))

return cmd
}

// NewBalancesCmd returns a CLI command handler for querying account balance(s).
func NewBalancesCmd(m codec.Marshaler) *cobra.Command {
cmd := &cobra.Command{
Use: "balances [address]",
Short: "Query for account balance(s) by address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithMarshaler(m)

addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

var (
params interface{}
result interface{}
route string
)

denom := viper.GetString(flagDenom)
if denom == "" {
params = types.NewQueryAllBalancesParams(addr)
route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAllBalances)
} else {
params = types.NewQueryBalanceParams(addr, denom)
route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBalance)
}

bz, err := m.MarshalJSON(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
}

res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}

if denom == "" {
var balances sdk.Coins
if err := m.UnmarshalJSON(res, &balances); err != nil {
return err
}

result = balances
} else {
var balance sdk.Coin
if err := m.UnmarshalJSON(res, &balance); err != nil {
return err
}

result = balance
}

return cliCtx.Println(result)
},
}

cmd.Flags().String(flagDenom, "", "The specific balance denomination to query for")

return flags.GetCommands(cmd)[0]
}

// ---------------------------------------------------------------------------
// Deprecated
//
Expand All @@ -116,7 +39,10 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(GetBalancesCmd(cdc))
cmd.AddCommand(
GetBalancesCmd(cdc),
GetCmdQueryTotalSupply(cdc),
)

return cmd
}
Expand Down Expand Up @@ -188,3 +114,37 @@ func GetBalancesCmd(cdc *codec.Codec) *cobra.Command {

return flags.GetCommands(cmd)[0]
}

// TODO: Remove once client-side Protobuf migration has been completed.
// ref: https://github.com/cosmos/cosmos-sdk/issues/5864
func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "total [denom]",
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])
},
}

return flags.GetCommands(cmd)[0]
}
52 changes: 52 additions & 0 deletions x/bank/client/cli/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cli

import (
"fmt"

"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/x/bank/types"
)

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)
}
54 changes: 54 additions & 0 deletions x/bank/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,57 @@ func QueryBalancesRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc {
rest.PostProcessResponse(w, ctx, res)
}
}

// 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 rest.CheckBadRequestError(w, err) {
return
}

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

params := types.NewQueryTotalSupplyParams(page, limit)
bz, err := cliCtx.Codec.MarshalJSON(params)
if rest.CheckBadRequestError(w, err) {
return
}

res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), bz)
if rest.CheckInternalServerError(w, err) {
return
}

cliCtx = cliCtx.WithHeight(height)
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 rest.CheckBadRequestError(w, err) {
return
}

res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySupplyOf), bz)
if rest.CheckInternalServerError(w, err) {
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 2 additions & 0 deletions x/bank/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg tx.Generato
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bank/total", totalSupplyHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bank/total/{denom}", supplyOfHandlerFn(cliCtx)).Methods("GET")
}
Loading