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 6 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
14 changes: 7 additions & 7 deletions codec/std/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/bank"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/evidence"
eviexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)

var (
_ auth.Codec = (*Codec)(nil)
_ supply.Codec = (*Codec)(nil)
_ bank.Codec = (*Codec)(nil)
_ evidence.Codec = (*Codec)(nil)
_ gov.Codec = (*Codec)(nil)
)
Expand Down Expand Up @@ -77,7 +77,7 @@ func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) {
// MarshalSupply marshals a SupplyI interface. If the given type implements
// the Marshaler interface, it is treated as a Proto-defined message and
// serialized that way. Otherwise, it falls back on the internal Amino codec.
func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) {
func (c *Codec) MarshalSupply(supplyI bankexported.SupplyI) ([]byte, error) {
supply := &Supply{}
if err := supply.SetSupplyI(supplyI); err != nil {
return nil, err
Expand All @@ -88,7 +88,7 @@ func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) {

// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes
// of a Proto-based SupplyI type. An error is returned upon decoding failure.
func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) {
func (c *Codec) UnmarshalSupply(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalBinaryBare(bz, supply); err != nil {
return nil, err
Expand All @@ -99,12 +99,12 @@ func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) {

// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI
// interface.
func (c *Codec) MarshalSupplyJSON(supply supplyexported.SupplyI) ([]byte, error) {
func (c *Codec) MarshalSupplyJSON(supply bankexported.SupplyI) ([]byte, error) {
return c.Marshaler.MarshalJSON(supply)
}

// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes.
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (supplyexported.SupplyI, error) {
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil {
return nil, err
Expand Down
332 changes: 165 additions & 167 deletions codec/std/codec.pb.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions codec/std/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "x/auth/vesting/types/types.proto";
import "x/bank/types/types.proto";
import "x/crisis/types/types.proto";
import "x/distribution/types/types.proto";
import "x/supply/types/types.proto";
import "x/evidence/types/types.proto";
import "x/gov/types/types.proto";
import "x/slashing/types/types.proto";
Expand All @@ -29,18 +28,18 @@ message Account {
cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2;
cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3;
cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4;
cosmos_sdk.x.supply.v1.ModuleAccount module_account = 5;
cosmos_sdk.x.bank.v1.ModuleAccount module_account = 5;
}
}

// Supply defines the application-level Supply type.
message Supply {
option (gogoproto.equal) = true;
option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/supply/exported.SupplyI";
option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/bank/exported.SupplyI";

// sum defines a set of all acceptable concrete Supply implementations.
oneof sum {
cosmos_sdk.x.supply.v1.Supply supply = 1;
cosmos_sdk.x.bank.v1.Supply supply = 1;
}
}

Expand Down
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)
}
Loading