From 942ed093febf5999da3c3d9967dbceef65661d93 Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 12:06:14 +0800 Subject: [PATCH 1/9] feat: add --qrcode flag to keys show command --- client/keys/show.go | 6 ++++++ client/keys/show_test.go | 15 +++++++++++++++ go.mod | 2 ++ go.sum | 4 ++++ testutil/ioutil.go | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/client/keys/show.go b/client/keys/show.go index 55be5a116e90..bfa03e71aef1 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -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 keys payment 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 { diff --git a/client/keys/show_test.go b/client/keys/show_test.go index ed20567afa72..9236e1ec4360 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -174,6 +174,21 @@ 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)) } func Test_validateMultisigThreshold(t *testing.T) { diff --git a/go.mod b/go.mod index 6882e16dd4b2..0b9c5753f865 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index ffc8d504206c..83a24869ff78 100644 --- a/go.sum +++ b/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= diff --git a/testutil/ioutil.go b/testutil/ioutil.go index 4413c16e215e..a6a1a5233ce4 100644 --- a/testutil/ioutil.go +++ b/testutil/ioutil.go @@ -44,7 +44,7 @@ func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader { mockIn := strings.NewReader("") c.SetIn(mockIn) - c.SetOut(io.Discard) + //c.SetOut(io.Discard) c.SetErr(io.Discard) return mockIn From e5d6ee1a555d2b04c53c846cf197006cc88ebeb9 Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 12:14:08 +0800 Subject: [PATCH 2/9] fix: revert changes of c.SetOut(io.Discard) --- testutil/ioutil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil/ioutil.go b/testutil/ioutil.go index a6a1a5233ce4..4413c16e215e 100644 --- a/testutil/ioutil.go +++ b/testutil/ioutil.go @@ -44,7 +44,7 @@ func ApplyMockIODiscardOutErr(c *cobra.Command) BufferReader { mockIn := strings.NewReader("") c.SetIn(mockIn) - //c.SetOut(io.Discard) + c.SetOut(io.Discard) c.SetErr(io.Discard) return mockIn From 66e340727dc4d185d12c874c72cd3435b619785e Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 12:23:21 +0800 Subject: [PATCH 3/9] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b37ba4013414..49c6c3a0d273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 payment for 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. From b0fd38115a354d907a2243d55c5a48c4dabffdfc Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 12:27:51 +0800 Subject: [PATCH 4/9] add test for multi account --- client/keys/show_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 9236e1ec4360..676385525974 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -181,7 +181,21 @@ func Test_runShowCmd(t *testing.T) { 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. + // 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), From ec27187f1ab031801c247d7729eaf0aae3df3575 Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 22:26:55 +0800 Subject: [PATCH 5/9] fix: go mod tidy --- simapp/go.mod | 2 ++ simapp/go.sum | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/simapp/go.mod b/simapp/go.mod index 60c12be1b642..725f0c109613 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -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 ) diff --git a/simapp/go.sum b/simapp/go.sum index 8040fbbc146b..000cdac9d503 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -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= From a94ec2d8ae9aa90a5411f765a350bcd9cefa3fed Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 22:30:26 +0800 Subject: [PATCH 6/9] change payment qr code to address qr code --- client/keys/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/keys/show.go b/client/keys/show.go index bfa03e71aef1..c091c42679e2 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -51,7 +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 keys payment QR code, will be ignored if -a or --address is false") + f.Bool(flagQRCode, false, "Display keys address QR code, will be ignored if -a or --address is false") return cmd } From 327047bf2870b0ca2714a2fcf2b109b63c7a69d4 Mon Sep 17 00:00:00 2001 From: levisyin Date: Sun, 26 Nov 2023 22:32:14 +0800 Subject: [PATCH 7/9] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c6c3a0d273..e8ebfdc12cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +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 payment for QR code. +* (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. From 79cff1208f812612040bb6c952fac87b3e4c392b Mon Sep 17 00:00:00 2001 From: levisyin <150114626+levisyin@users.noreply.github.com> Date: Mon, 27 Nov 2023 08:33:16 +0800 Subject: [PATCH 8/9] Update client/keys/show.go Co-authored-by: Aleksandr Bezobchuk --- client/keys/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/keys/show.go b/client/keys/show.go index c091c42679e2..582e6ec9c1a5 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -51,7 +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 keys address QR code, will be ignored if -a or --address is false") + f.Bool(flagQRCode, false, "Display key address QR code (will be ignored if -a or --address is false)") return cmd } From bfe9c10762ce79514927d28d8322924be63c0d59 Mon Sep 17 00:00:00 2001 From: levisyin Date: Mon, 27 Nov 2023 09:54:02 +0800 Subject: [PATCH 9/9] fix: fix ci failed --- simapp/gomod2nix.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simapp/gomod2nix.toml b/simapp/gomod2nix.toml index 5c9376557963..894c8c983c8c 100644 --- a/simapp/gomod2nix.toml +++ b/simapp/gomod2nix.toml @@ -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="