feat: add --qrcode flag to keys show command (#18557)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
8a2c9084ba
commit
536bd3a955
@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Features
|
||||
|
||||
* (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code.
|
||||
* (x/staking) [#18142](https://github.com/cosmos/cosmos-sdk/pull/18142) Introduce `key_rotation_fee` param to calculate fees while rotating the keys
|
||||
* (client) [#18101](https://github.com/cosmos/cosmos-sdk/pull/18101) Add a `keyring-default-keyname` in `client.toml` for specifying a default key name, and skip the need to use the `--from` flag when signing transactions.
|
||||
* (tests) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) Added helper method `SubmitTestTx` in testutil to broadcast test txns to test e2e tests.
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/mdp/qrterminal/v3"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
@ -30,6 +31,7 @@ const (
|
||||
FlagDevice = "device"
|
||||
|
||||
flagMultiSigThreshold = "multisig-threshold"
|
||||
flagQRCode = "qrcode"
|
||||
)
|
||||
|
||||
// ShowKeysCmd shows key information for a given key name.
|
||||
@ -49,6 +51,7 @@ consisting of all the keys provided by name and multisig threshold.`,
|
||||
f.BoolP(FlagPublicKey, "p", false, "Output the public key only (overrides --output)")
|
||||
f.BoolP(FlagDevice, "d", false, "Output the address in a ledger device")
|
||||
f.Int(flagMultiSigThreshold, 1, "K out of N required signatures")
|
||||
f.Bool(flagQRCode, false, "Display key address QR code (will be ignored if -a or --address is false)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -96,6 +99,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
isShowAddr, _ := cmd.Flags().GetBool(FlagAddress)
|
||||
isShowPubKey, _ := cmd.Flags().GetBool(FlagPublicKey)
|
||||
isShowDevice, _ := cmd.Flags().GetBool(FlagDevice)
|
||||
isShowQRCode, _ := cmd.Flags().GetBool(flagQRCode)
|
||||
|
||||
isOutputSet := false
|
||||
tmp := cmd.Flag(flags.FlagOutput)
|
||||
@ -126,6 +130,8 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
out := ko.Address
|
||||
if isShowPubKey {
|
||||
out = ko.PubKey
|
||||
} else if isShowQRCode {
|
||||
qrterminal.GenerateHalfBlock(out, qrterminal.H, cmd.OutOrStdout())
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintln(cmd.OutOrStdout(), out); err != nil {
|
||||
|
||||
@ -174,6 +174,35 @@ func Test_runShowCmd(t *testing.T) {
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
require.EqualError(t, cmd.ExecuteContext(ctx), "the device flag (-d) can only be used for addresses not pubkeys")
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
fakeKeyName1,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome),
|
||||
fmt.Sprintf("--%s=true", FlagAddress),
|
||||
fmt.Sprintf("--%s=true", flagQRCode),
|
||||
// we have to reset following flags as they were set to true above, and won't be auto reset to false if we skip to specify these flags.
|
||||
// Note: this maybe a bug about spf13/cobra as cmd.flags's value won't be reset by changing cmd.args with cmd.SetArgs.
|
||||
fmt.Sprintf("--%s=false", FlagDevice),
|
||||
fmt.Sprintf("--%s=false", FlagPublicKey),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
|
||||
// try fetch by name
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
fakeKeyName1, fakeKeyName2,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome),
|
||||
fmt.Sprintf("--%s=true", FlagAddress),
|
||||
fmt.Sprintf("--%s=true", flagQRCode),
|
||||
fmt.Sprintf("--%s=2", flagMultiSigThreshold),
|
||||
fmt.Sprintf("--%s=false", FlagDevice),
|
||||
fmt.Sprintf("--%s=false", FlagPublicKey),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
|
||||
// try fetch by name
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
}
|
||||
|
||||
func Test_validateMultisigThreshold(t *testing.T) {
|
||||
|
||||
2
go.mod
2
go.mod
@ -42,6 +42,7 @@ require (
|
||||
github.com/improbable-eng/grpc-web v0.15.0
|
||||
github.com/magiconair/properties v1.8.7
|
||||
github.com/mattn/go-isatty v0.0.20
|
||||
github.com/mdp/qrterminal/v3 v3.2.0
|
||||
github.com/prometheus/client_golang v1.17.0
|
||||
github.com/prometheus/common v0.45.0
|
||||
github.com/rs/zerolog v1.31.0
|
||||
@ -157,6 +158,7 @@ require (
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
nhooyr.io/websocket v1.8.6 // indirect
|
||||
rsc.io/qr v0.2.0 // indirect
|
||||
)
|
||||
|
||||
// Here are the short-lived replace from the Cosmos SDK
|
||||
|
||||
4
go.sum
4
go.sum
@ -549,6 +549,8 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
|
||||
github.com/mdp/qrterminal/v3 v3.2.0 h1:qteQMXO3oyTK4IHwj2mWsKYYRBOp1Pj2WRYFYYNTCdk=
|
||||
github.com/mdp/qrterminal/v3 v3.2.0/go.mod h1:XGGuua4Lefrl7TLEsSONiD+UEjQXJZ4mPzF+gWYIJkk=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
|
||||
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
||||
@ -1297,6 +1299,8 @@ pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
|
||||
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
|
||||
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
||||
@ -150,6 +150,7 @@ require (
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
|
||||
github.com/mdp/qrterminal/v3 v3.2.0 // indirect
|
||||
github.com/minio/highwayhash v1.0.2 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||
@ -204,6 +205,7 @@ require (
|
||||
gotest.tools/v3 v3.5.1 // indirect
|
||||
nhooyr.io/websocket v1.8.6 // indirect
|
||||
pgregory.net/rapid v1.1.0 // indirect
|
||||
rsc.io/qr v0.2.0 // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
||||
|
||||
@ -772,6 +772,8 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
|
||||
github.com/mdp/qrterminal/v3 v3.2.0 h1:qteQMXO3oyTK4IHwj2mWsKYYRBOp1Pj2WRYFYYNTCdk=
|
||||
github.com/mdp/qrterminal/v3 v3.2.0/go.mod h1:XGGuua4Lefrl7TLEsSONiD+UEjQXJZ4mPzF+gWYIJkk=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
|
||||
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
|
||||
@ -1716,6 +1718,8 @@ pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
|
||||
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
|
||||
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
||||
@ -341,6 +341,9 @@ schema = 3
|
||||
[mod."github.com/matttproud/golang_protobuf_extensions/v2"]
|
||||
version = "v2.0.0"
|
||||
hash = "sha256-gcAN8jKL0ve8pcgDkxr2Lc8CUBG39ri9QAp0zrzchEs="
|
||||
[mod."github.com/mdp/qrterminal/v3"]
|
||||
version = "v3.2.0"
|
||||
hash = "sha256-2ZcpLFu6P+a3qHH32uiFKUwzgza1NF0Bmayl41GQCEI="
|
||||
[mod."github.com/minio/highwayhash"]
|
||||
version = "v1.0.2"
|
||||
hash = "sha256-UeHeepKtToyA5e/w3KdmpbCn+4medesZG0cAcU6P2cY="
|
||||
@ -522,6 +525,9 @@ schema = 3
|
||||
[mod."pgregory.net/rapid"]
|
||||
version = "v1.1.0"
|
||||
hash = "sha256-sVQY9EQ9Y5blYyVYfaOa+y12e+399OqdHiEY3BaDnqo="
|
||||
[mod."rsc.io/qr"]
|
||||
version = "v0.2.0"
|
||||
hash = "sha256-I3fAJwwZhIrgBbCjWvIElAE9JqG2y59KRBc78EYi3RM="
|
||||
[mod."sigs.k8s.io/yaml"]
|
||||
version = "v1.4.0"
|
||||
hash = "sha256-Hd/M0vIfIVobDd87eb58p1HyVOjYWNlGq2bRXfmtVno="
|
||||
|
||||
Loading…
Reference in New Issue
Block a user