Skip to content

Commit d256570

Browse files
mergify[bot]colin-axnerdamiannolan
authored
fix: update simd gen accounts cmd to perform same functionality as SDK (#2065) (#2067)
## Description There was a bug with trying to add a genesis account using the key name, so I bumped the code to be identical to the latest changes on the SDK [ref](https://github.com/informalsystems/ibc-rs/issues/2581) closes: #XXXX --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes (cherry picked from commit 124cf31) Co-authored-by: colin axnér <[email protected]> Co-authored-by: Damian Nolan <[email protected]>
1 parent cd5ceaa commit d256570

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

testing/simapp/simd/cmd/genaccounts.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,35 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
3838
Args: cobra.ExactArgs(2),
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040
clientCtx := client.GetClientContextFromCmd(cmd)
41-
depCdc := clientCtx.Codec
42-
cdc := depCdc
43-
4441
serverCtx := server.GetServerContextFromCmd(cmd)
4542
config := serverCtx.Config
4643

4744
config.SetRoot(clientCtx.HomeDir)
4845

46+
var kr keyring.Keyring
4947
addr, err := sdk.AccAddressFromBech32(args[0])
5048
if err != nil {
5149
inBuf := bufio.NewReader(cmd.InOrStdin())
5250
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
5351

54-
// attempt to lookup address from Keybase if no address was provided
55-
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec)
56-
if err != nil {
57-
return err
52+
if keyringBackend != "" && clientCtx.Keyring == nil {
53+
var err error
54+
kr, err = keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf, clientCtx.Codec)
55+
if err != nil {
56+
return err
57+
}
58+
} else {
59+
kr = clientCtx.Keyring
5860
}
5961

60-
info, err := kb.Key(args[0])
62+
k, err := kr.Key(args[0])
6163
if err != nil {
62-
return fmt.Errorf("failed to get address from Keybase: %w", err)
64+
return fmt.Errorf("failed to get address from Keyring: %w", err)
6365
}
6466

65-
_, err = info.GetAddress()
67+
addr, err = k.GetAddress()
6668
if err != nil {
67-
return fmt.Errorf("failed to get address from Keybase: %w", err)
69+
return err
6870
}
6971
}
7072

@@ -120,7 +122,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
120122
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
121123
}
122124

123-
authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState)
125+
authGenState := authtypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
124126

125127
accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
126128
if err != nil {
@@ -142,19 +144,19 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
142144
}
143145
authGenState.Accounts = genAccs
144146

145-
authGenStateBz, err := cdc.MarshalJSON(&authGenState)
147+
authGenStateBz, err := clientCtx.Codec.MarshalJSON(&authGenState)
146148
if err != nil {
147149
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
148150
}
149151

150152
appState[authtypes.ModuleName] = authGenStateBz
151153

152-
bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
154+
bankGenState := banktypes.GetGenesisStateFromAppState(clientCtx.Codec, appState)
153155
bankGenState.Balances = append(bankGenState.Balances, balances)
154156
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
155157
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
156158

157-
bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
159+
bankGenStateBz, err := clientCtx.Codec.MarshalJSON(bankGenState)
158160
if err != nil {
159161
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
160162
}

0 commit comments

Comments
 (0)