cmd: use config on genaccounts (#483)

* cmd: use config on genaccounts

* update

* c++
This commit is contained in:
Federico Kunze Küllmer 2021-09-30 14:02:58 +02:00 committed by GitHub
parent 27d4ea393d
commit 548bf48d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 23 deletions

View File

@ -41,6 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (deps) [tharsis#610](https://github.com/tharsis/ethermint/pull/610) Bump Cosmos SDK to [v0.44.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.1). * (deps) [tharsis#610](https://github.com/tharsis/ethermint/pull/610) Bump Cosmos SDK to [v0.44.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.1).
### Bug Fixes
* (cmd) [tharsis#483](https://github.com/tharsis/ethermint/pull/483) Use config values on genesis accounts.
## [v0.6.0] - 2021-09-29 ## [v0.6.0] - 2021-09-29
### State Machine Breaking ### State Machine Breaking

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -19,7 +20,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/tharsis/ethermint/crypto/hd" "github.com/tharsis/ethermint/crypto/hd"
ethermint "github.com/tharsis/ethermint/types" ethermint "github.com/tharsis/ethermint/types"
evmtypes "github.com/tharsis/ethermint/x/evm/types" evmtypes "github.com/tharsis/ethermint/x/evm/types"
@ -44,35 +44,37 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.Codec
serverCtx := server.GetServerContextFromCmd(cmd) serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config config := serverCtx.Config
config.SetRoot(clientCtx.HomeDir) config.SetRoot(clientCtx.HomeDir)
var kr keyring.Keyring
addr, err := sdk.AccAddressFromBech32(args[0]) addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil { if err != nil {
inBuf := bufio.NewReader(cmd.InOrStdin()) inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend) keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
return err if keyringBackend != "" && clientCtx.Keyring == nil {
} var err error
// attempt to lookup address from Keybase if no address was provided kr, err = keyring.New(
kb, err := keyring.New( sdk.KeyringServiceName(),
sdk.KeyringServiceName(), keyringBackend,
keyringBackend, clientCtx.HomeDir,
clientCtx.HomeDir, inBuf,
inBuf, hd.EthSecp256k1Option(),
hd.EthSecp256k1Option(), )
) if err != nil {
if err != nil { return err
return err }
} else {
kr = clientCtx.Keyring
} }
info, err := kb.Key(args[0]) info, err := kr.Key(args[0])
if err != nil { 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)
} }
addr = info.GetAddress() addr = info.GetAddress()
@ -142,7 +144,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return fmt.Errorf("failed to unmarshal genesis state: %w", err) 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) accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil { if err != nil {
@ -164,19 +166,19 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
} }
authGenState.Accounts = genAccs authGenState.Accounts = genAccs
authGenStateBz, err := cdc.MarshalJSON(&authGenState) authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState)
if err != nil { if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err) return fmt.Errorf("failed to marshal auth genesis state: %w", err)
} }
appState[authtypes.ModuleName] = authGenStateBz appState[authtypes.ModuleName] = authGenStateBz
bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState) bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
bankGenState.Balances = append(bankGenState.Balances, balances) bankGenState.Balances = append(bankGenState.Balances, balances)
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...) bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
bankGenStateBz, err := cdc.MarshalJSON(bankGenState) bankGenStateBz, err := clientCtx.Codec.MarshalJSON(bankGenState)
if err != nil { if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err) return fmt.Errorf("failed to marshal bank genesis state: %w", err)
} }
@ -194,7 +196,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
} }
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, keyring.BackendFile, "Select keyring's backend (os|file|kwallet|pass|test)") cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")