From ac9610c0f38378e6d53db2ce950b26277630484b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:00:24 +0200 Subject: [PATCH 1/2] bump genaccounts.go to use latest sdk version --- testing/simapp/simd/cmd/genaccounts.go | 35 ++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/testing/simapp/simd/cmd/genaccounts.go b/testing/simapp/simd/cmd/genaccounts.go index 92f82070edd..97275a41fc4 100644 --- a/testing/simapp/simd/cmd/genaccounts.go +++ b/testing/simapp/simd/cmd/genaccounts.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -16,7 +18,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/spf13/cobra" ) const ( @@ -38,33 +39,35 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - depCdc := clientCtx.Codec - cdc := depCdc - serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config config.SetRoot(clientCtx.HomeDir) + var kr keyring.Keyring addr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { inBuf := bufio.NewReader(cmd.InOrStdin()) keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) - // attempt to lookup address from Keybase if no address was provided - kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec) - if err != nil { - return err + if keyringBackend != "" && clientCtx.Keyring == nil { + var err error + kr, err = keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec) + if err != nil { + return err + } + } else { + kr = clientCtx.Keyring } - info, err := kb.Key(args[0]) + k, err := kr.Key(args[0]) if err != nil { - return fmt.Errorf("failed to get address from Keybase: %w", err) + return fmt.Errorf("failed to get address from Keyring: %w", err) } - _, err = info.GetAddress() + addr, err = k.GetAddress() if err != nil { - return fmt.Errorf("failed to get address from Keybase: %w", err) + return err } } @@ -120,7 +123,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa return fmt.Errorf("failed to unmarshal genesis state: %w", err) } - authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState) + authGenState := authtypes.GetGenesisStateFromAppState(clientCtx.Codec, appState) accs, err := authtypes.UnpackAccounts(authGenState.Accounts) if err != nil { @@ -142,19 +145,19 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa } authGenState.Accounts = genAccs - authGenStateBz, err := cdc.MarshalJSON(&authGenState) + authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState) if err != nil { return fmt.Errorf("failed to marshal auth genesis state: %w", err) } appState[authtypes.ModuleName] = authGenStateBz - bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState) + bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState) bankGenState.Balances = append(bankGenState.Balances, balances) bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...) - bankGenStateBz, err := cdc.MarshalJSON(bankGenState) + bankGenStateBz, err := clientCtx.Codec.MarshalJSON(bankGenState) if err != nil { return fmt.Errorf("failed to marshal bank genesis state: %w", err) } From 06d15f3f35cd74cd348522d1a46cee3f215587f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:03:06 +0200 Subject: [PATCH 2/2] fix imports --- testing/simapp/simd/cmd/genaccounts.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/simapp/simd/cmd/genaccounts.go b/testing/simapp/simd/cmd/genaccounts.go index 97275a41fc4..0b25662d093 100644 --- a/testing/simapp/simd/cmd/genaccounts.go +++ b/testing/simapp/simd/cmd/genaccounts.go @@ -6,8 +6,6 @@ import ( "errors" "fmt" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -18,6 +16,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/spf13/cobra" ) const (