-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: Kerying migration #9222
Changes from all commits
c727fa6
7505e5a
9160257
16eebea
6ae658d
bcd9f81
36311a3
c9ae124
2421d02
ea31d04
23a2316
1f0ae05
059aa39
3a420d2
52426d4
9a4bd80
51afe76
6edb399
c99594a
0aca25f
e9e0b4f
9a61180
cb8c94f
2bc9cfc
83c290a
5a5a9c6
fba942d
2059243
860e0d0
f9b32f0
f18de4c
ebc6d44
e465ac6
26d4672
990cee7
3f00b76
79ebb56
ab4480f
c9f6911
0778fdf
cab7c66
35aea35
7365334
5865d9d
d5c3c88
a56cf27
6440a36
fe26c52
f5d5e6b
3dc26a5
6fd3fed
c684f59
372cc34
6ed3edd
1b16f94
d362139
68816b7
3df8c9b
5bf2889
36764e3
e3fe793
17b45ae
241feb6
7815f41
c538c57
0a92755
9f5678d
23b33b2
520cc56
7a4b74e
d717da0
7cd88cb
45fdfcb
f74cf65
fe68c74
e690fde
f9965e7
4c48fea
8109936
303e7fe
9d87490
dbd041c
0c751ed
fe39205
35dbe9c
f5af15c
f0988b1
381dc27
89764ba
b232cea
599b413
8dcefee
a8856d3
4468f7d
4235a58
1214b2e
0ebbfaf
654e34e
d1bccca
e0b0073
4735d9f
c728543
41b0d03
4d88638
e0e4915
78d81be
42a5c62
d272991
c03be48
c736b8f
fcf1b70
baaeda0
39cd82c
b6cb87f
4c45144
5ff7551
f209635
faf232e
30d7f3c
f1e2084
3117ce9
4882db8
c691246
5514769
b0685fe
4d8c0e8
24f44e8
fe572c9
dda1851
8f239df
1401291
7beebb2
8652e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -118,8 +118,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
} | ||||||||
|
||||||||
if dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun); dryRun { | ||||||||
// use in memory keybase | ||||||||
kb = keyring.NewInMemory() | ||||||||
kb = keyring.NewInMemory(ctx.Codec) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} else { | ||||||||
_, err = kb.Key(name) | ||||||||
if err == nil { | ||||||||
|
@@ -153,7 +152,11 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
return err | ||||||||
} | ||||||||
|
||||||||
pks[i] = k.GetPubKey() | ||||||||
key, err := k.GetPubKey() | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
pks[i] = key | ||||||||
} | ||||||||
|
||||||||
if noSort, _ := cmd.Flags().GetBool(flagNoSort); !noSort { | ||||||||
|
@@ -163,12 +166,12 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
} | ||||||||
|
||||||||
pk := multisig.NewLegacyAminoPubKey(multisigThreshold, pks) | ||||||||
info, err := kb.SaveMultisig(name, pk) | ||||||||
k, err := kb.SaveMultisig(name, pk) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
return printCreate(cmd, info, false, "", outputFormat) | ||||||||
return printCreate(cmd, k, false, "", outputFormat) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -179,13 +182,8 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
info, err := kb.SavePubKey(name, pk, algo.Name()) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
return printCreate(cmd, info, false, "", outputFormat) | ||||||||
_, err := kb.SaveOfflineKey(name, pk) | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
coinType, _ := cmd.Flags().GetUint32(flagCoinType) | ||||||||
|
@@ -203,13 +201,12 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
// If we're using ledger, only thing we need is the path and the bech32 prefix. | ||||||||
if useLedger { | ||||||||
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix() | ||||||||
info, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index) | ||||||||
|
||||||||
k, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
||||||||
return printCreate(cmd, info, false, "", outputFormat) | ||||||||
return printCreate(cmd, k, false, "", outputFormat) | ||||||||
} | ||||||||
|
||||||||
// Get bip39 mnemonic | ||||||||
|
@@ -271,7 +268,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
} | ||||||||
} | ||||||||
|
||||||||
info, err := kb.NewAccount(name, mnemonic, bip39Passphrase, hdPath, algo) | ||||||||
k, err := kb.NewAccount(name, mnemonic, bip39Passphrase, hdPath, algo) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
@@ -283,14 +280,14 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf | |||||||
mnemonic = "" | ||||||||
} | ||||||||
|
||||||||
return printCreate(cmd, info, showMnemonic, mnemonic, outputFormat) | ||||||||
return printCreate(cmd, k, showMnemonic, mnemonic, outputFormat) | ||||||||
} | ||||||||
|
||||||||
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string, outputFormat string) error { | ||||||||
func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemonic, outputFormat string) error { | ||||||||
switch outputFormat { | ||||||||
case OutputFormatText: | ||||||||
cmd.PrintErrln() | ||||||||
printKeyInfo(cmd.OutOrStdout(), info, keyring.MkAccKeyOutput, outputFormat) | ||||||||
printKeyringRecord(cmd.OutOrStdout(), k, keyring.MkAccKeyOutput, outputFormat) | ||||||||
|
||||||||
// print mnemonic unless requested not to. | ||||||||
if showMnemonic { | ||||||||
|
@@ -300,7 +297,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo | |||||||
fmt.Fprintln(cmd.ErrOrStderr(), mnemonic) | ||||||||
} | ||||||||
case OutputFormatJSON: | ||||||||
out, err := keyring.MkAccKeyOutput(info) | ||||||||
out, err := keyring.MkAccKeyOutput(k) | ||||||||
if err != nil { | ||||||||
return err | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,12 @@ func Test_runAddCmdBasic(t *testing.T) { | |
mockIn := testutil.ApplyMockIODiscardOutErr(cmd) | ||
kbHome := t.TempDir() | ||
|
||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) | ||
encCfg := simapp.MakeTestEncodingConfig() | ||
|
||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, encCfg.Codec) | ||
require.NoError(t, err) | ||
|
||
clientCtx := client.Context{}.WithKeyringDir(kbHome) | ||
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithKeyring(kb).WithCodec(encCfg.Codec) | ||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) | ||
|
||
t.Cleanup(func() { | ||
|
@@ -43,7 +45,6 @@ func Test_runAddCmdBasic(t *testing.T) { | |
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), | ||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyAlgorithm, string(hd.Secp256k1Type)), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), | ||
}) | ||
mockIn.Reset("y\n") | ||
require.NoError(t, cmd.ExecuteContext(ctx)) | ||
|
@@ -56,7 +57,6 @@ func Test_runAddCmdBasic(t *testing.T) { | |
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), | ||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyAlgorithm, string(hd.Secp256k1Type)), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
}) | ||
|
||
require.NoError(t, cmd.ExecuteContext(ctx)) | ||
|
@@ -70,7 +70,6 @@ func Test_runAddCmdBasic(t *testing.T) { | |
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), | ||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyAlgorithm, string(hd.Secp256k1Type)), | ||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), | ||
}) | ||
|
||
require.NoError(t, cmd.ExecuteContext(ctx)) | ||
|
@@ -188,7 +187,8 @@ func Test_runAddCmdDryRun(t *testing.T) { | |
|
||
kbHome := t.TempDir() | ||
mockIn := testutil.ApplyMockIODiscardOutErr(cmd) | ||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) | ||
encCfg := simapp.MakeTestEncodingConfig() | ||
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, encCfg.Codec) | ||
require.NoError(t, err) | ||
|
||
appCodec := simapp.MakeTestEncodingConfig().Codec | ||
|
@@ -216,13 +216,13 @@ func Test_runAddCmdDryRun(t *testing.T) { | |
_, err = kb.Key("testkey") | ||
require.NoError(t, err) | ||
|
||
out, err := ioutil.ReadAll(b) | ||
_, err := ioutil.ReadAll(b) | ||
require.NoError(t, err) | ||
require.Contains(t, string(out), "name: testkey") | ||
|
||
} else { | ||
_, err = kb.Key("testkey") | ||
require.Error(t, err) | ||
require.Equal(t, "testkey.info: key not found", err.Error()) | ||
require.Equal(t, "testkey: key not found", err.Error()) | ||
} | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.