From 0dcf1583878e4b8eea402da7fadbe3a8e4e77521 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 6 Aug 2019 16:51:18 -0400 Subject: [PATCH] Merge PR #4852: Cleanup Supply Genesis State --- simapp/utils.go | 2 +- x/genutil/legacy/v036/migrate.go | 1 + x/supply/genesis.go | 10 +++++----- x/supply/internal/types/genesis.go | 8 ++++---- x/supply/legacy/v0_36/types.go | 10 ++-------- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/simapp/utils.go b/simapp/utils.go index b4f14db26a..41ce7cb894 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -174,7 +174,7 @@ func GenBankGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams func GenSupplyGenesisState(cdc *codec.Codec, amount, numInitiallyBonded, numAccs int64, genesisState map[string]json.RawMessage) { totalSupply := sdk.NewInt(amount * (numAccs + numInitiallyBonded)) supplyGenesis := supply.NewGenesisState( - supply.NewSupply(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, totalSupply))), + sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, totalSupply)), ) fmt.Printf("Generated supply parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, supplyGenesis)) diff --git a/x/genutil/legacy/v036/migrate.go b/x/genutil/legacy/v036/migrate.go index fcab4a666f..5ba4af490e 100644 --- a/x/genutil/legacy/v036/migrate.go +++ b/x/genutil/legacy/v036/migrate.go @@ -89,6 +89,7 @@ func Migrate(appState genutil.AppMap) genutil.AppMap { appState[v036staking.ModuleName] = v036Codec.MustMarshalJSON(v036staking.Migrate(stakingGenState)) } + // migrate supply state appState[v036supply.ModuleName] = v036Codec.MustMarshalJSON(v036supply.EmptyGenesisState()) return appState diff --git a/x/supply/genesis.go b/x/supply/genesis.go index 36e928d383..7af02a61c7 100644 --- a/x/supply/genesis.go +++ b/x/supply/genesis.go @@ -11,7 +11,7 @@ import ( // CONTRACT: all types of accounts must have been already initialized/created func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data GenesisState) { // manually set the total supply based on accounts if not provided - if data.Supply.GetTotal().Empty() { + if data.Supply.Empty() { var totalSupply sdk.Coins ak.IterateAccounts(ctx, func(acc authexported.Account) (stop bool) { @@ -20,19 +20,19 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data Ge }, ) - data.Supply = data.Supply.SetTotal(totalSupply) + data.Supply = totalSupply } - keeper.SetSupply(ctx, data.Supply) + keeper.SetSupply(ctx, types.NewSupply(data.Supply)) } // ExportGenesis returns a GenesisState for a given context and keeper. func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState { - return NewGenesisState(keeper.GetSupply(ctx)) + return NewGenesisState(keeper.GetSupply(ctx).GetTotal()) } // ValidateGenesis performs basic validation of supply genesis data returning an // error for any failed validation criteria. func ValidateGenesis(data GenesisState) error { - return data.Supply.ValidateBasic() + return types.NewSupply(data.Supply).ValidateBasic() } diff --git a/x/supply/internal/types/genesis.go b/x/supply/internal/types/genesis.go index 27f8b3ff1b..e73491d18c 100644 --- a/x/supply/internal/types/genesis.go +++ b/x/supply/internal/types/genesis.go @@ -1,20 +1,20 @@ package types import ( - "github.com/cosmos/cosmos-sdk/x/supply/exported" + sdk "github.com/cosmos/cosmos-sdk/types" ) // GenesisState is the supply state that must be provided at genesis. type GenesisState struct { - Supply exported.SupplyI `json:"supply" yaml:"supply"` + Supply sdk.Coins `json:"supply" yaml:"supply"` } // NewGenesisState creates a new genesis state. -func NewGenesisState(supply exported.SupplyI) GenesisState { +func NewGenesisState(supply sdk.Coins) GenesisState { return GenesisState{supply} } // DefaultGenesisState returns a default genesis state func DefaultGenesisState() GenesisState { - return NewGenesisState(DefaultSupply()) + return NewGenesisState(DefaultSupply().GetTotal()) } diff --git a/x/supply/legacy/v0_36/types.go b/x/supply/legacy/v0_36/types.go index 4a219f5487..7e4aa425be 100644 --- a/x/supply/legacy/v0_36/types.go +++ b/x/supply/legacy/v0_36/types.go @@ -9,19 +9,13 @@ import ( const ModuleName = "supply" type ( - Supply struct { - Total sdk.Coins `json:"total"` - } - GenesisState struct { - Supply Supply `json:"supply"` + Supply sdk.Coins `json:"supply" yaml:"supply"` } ) func EmptyGenesisState() GenesisState { return GenesisState{ - Supply: Supply{ - Total: sdk.NewCoins(), // leave this empty as it's filled on initialization - }, + Supply: sdk.NewCoins(), // leave this empty as it's filled on initialization } }