From 3bf82e9ee962e16e355bf77c9fa0cb4bfc2e9c3e Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Wed, 25 Sep 2019 15:50:03 -0400 Subject: [PATCH] update app and cmd --- app/app.go | 9 ++++++--- app/genesis.go | 22 ---------------------- cmd/kvcli/main.go | 2 ++ cmd/kvd/add_account.go | 17 ++++------------- cmd/kvd/main.go | 5 +++-- 5 files changed, 15 insertions(+), 40 deletions(-) diff --git a/app/app.go b/app/app.go index 8ddb720a..efe9e3cf 100644 --- a/app/app.go +++ b/app/app.go @@ -224,9 +224,12 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, // genutils must occur after staking so that pools are properly // initialized with tokens from genesis accounts. - app.mm.SetOrderInitGenesis(auth.ModuleName, distr.ModuleName, - staking.ModuleName, auth.ModuleName, bank.ModuleName, slashing.ModuleName, - gov.ModuleName, mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName) + // TODO should auth be first? + app.mm.SetOrderInitGenesis( + auth.ModuleName, distr.ModuleName, + staking.ModuleName, bank.ModuleName, slashing.ModuleName, + gov.ModuleName, mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName, + ) app.mm.RegisterInvariants(&app.crisisKeeper) app.mm.RegisterRoutes(app.Router(), app.QueryRouter()) diff --git a/app/genesis.go b/app/genesis.go index 5602b64f..d6af7e32 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -2,9 +2,6 @@ package app import ( "encoding/json" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // GenesisState represents the genesis state of the blockchain. It is a map from module names to module genesis states. @@ -14,22 +11,3 @@ type GenesisState map[string]json.RawMessage func NewDefaultGenesisState() GenesisState { return ModuleBasics.DefaultGenesis() } - -// TODO remove iterator once merged into sdk master -type GenesisAccountIterator struct{} -// IterateGenesisAccounts iterates over all the genesis accounts found in -// appGenesis and invokes a callback on each genesis account. If any call -// returns true, iteration stops. -func (GenesisAccountIterator) IterateGenesisAccounts( - cdc *codec.Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), -) { - - var authGenState auth.GenesisState - cdc.MustUnmarshalJSON(appGenesis[auth.ModuleName], &authGenState) - - for _, genAcc := range authGenState.Accounts { - if cb(genAcc) { - break - } - } -} \ No newline at end of file diff --git a/cmd/kvcli/main.go b/cmd/kvcli/main.go index dbe097b8..5407de3a 100644 --- a/cmd/kvcli/main.go +++ b/cmd/kvcli/main.go @@ -34,6 +34,7 @@ func main() { cdc := app.MakeCodec() // Read in the configuration file for the sdk + // TODO check there is no issue with `kvcli keys parse` config := sdk.GetConfig() app.SetBech32AddressPrefixes(config) config.Seal() @@ -115,6 +116,7 @@ func txCmd(cdc *amino.Codec) *cobra.Command { client.LineBreak, authcmd.GetBroadcastCommand(cdc), authcmd.GetEncodeCommand(cdc), + authcmd.GetDecodeCommand(cdc), client.LineBreak, ) diff --git a/cmd/kvd/add_account.go b/cmd/kvd/add_account.go index a9fc9a2d..7a4f4fb2 100644 --- a/cmd/kvd/add_account.go +++ b/cmd/kvd/add_account.go @@ -104,24 +104,15 @@ func AddGenesisAccountCmd( return fmt.Errorf("failed to unmarshal genesis state: %w", err) } - // authGenState := auth.GetGenesisStateFromAppState(cdc, appState) - // TODO replace 2 following lines with above once sdk updated - var authGenState auth.GenesisState - cdc.MustUnmarshalJSON(appState[auth.ModuleName], &authGenState) - - // if authGenState.Accounts.Contains(addr) { - // TODO replace loop below with above once sdk is updated - for _, acc := range authGenState.Accounts { - if acc.GetAddress().Equals(addr) { - return fmt.Errorf("cannot add account at existing address %s", addr) - } + authGenState := auth.GetGenesisStateFromAppState(cdc, appState) + if authGenState.Accounts.Contains(addr) { + return fmt.Errorf("cannot add account at existing address %s", addr) } // Add the new account to the set of genesis accounts and sanitize the // accounts afterwards. authGenState.Accounts = append(authGenState.Accounts, genAccount) - // TODO uncomment following line once merged into master - // authGenState.Accounts = auth.SanitizeGenesisAccounts(authGenState.Accounts) + authGenState.Accounts = auth.SanitizeGenesisAccounts(authGenState.Accounts) authGenStateBz, err := cdc.MarshalJSON(authGenState) if err != nil { diff --git a/cmd/kvd/main.go b/cmd/kvd/main.go index 0b9324d4..587b9543 100644 --- a/cmd/kvd/main.go +++ b/cmd/kvd/main.go @@ -20,6 +20,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/kava-labs/kava/app" ) @@ -45,14 +46,14 @@ func main() { } rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)) - rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, app.GenesisAccountIterator{}, app.DefaultNodeHome)) + rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, auth.GenesisAccountIterator{}, app.DefaultNodeHome)) rootCmd.AddCommand(genutilcli.MigrateGenesisCmd(ctx, cdc)) rootCmd.AddCommand(genutilcli.GenTxCmd( ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, - app.GenesisAccountIterator{}, + auth.GenesisAccountIterator{}, app.DefaultNodeHome, app.DefaultCLIHome)) rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))