From 9fb691af676e595e655fea9e654e623f2b0e7776 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 13 May 2024 18:25:43 +0800 Subject: [PATCH] feat(client): add consensus address for debug cmd (#20328) Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> (cherry picked from commit 11de280625849b1409e7bc862268ec686c815317) # Conflicts: # CHANGELOG.md # client/debug/main.go --- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ client/debug/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e280ccadb73..94894ea4d1e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,34 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +<<<<<<< HEAD +======= +Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. + +### Features + +* (tests) [#20013](https://github.com/cosmos/cosmos-sdk/pull/20013) Introduce system tests to run multi node local testnet in CI +* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime. +* (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. +* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` in runtime. This service is present in all modules (when using depinject). +* (types) [#19164](https://github.com/cosmos/cosmos-sdk/pull/19164) Add a ValueCodec for the math.Uint type that can be used in collections maps. +* (types) [#19281](https://github.com/cosmos/cosmos-sdk/pull/19281) Added a new method, `IsGT`, for `types.Coin`. This method is used to check if a `types.Coin` is greater than another `types.Coin`. +* (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code. +* (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. +* (client) [#17513](https://github.com/cosmos/cosmos-sdk/pull/17513) Allow overwriting `client.toml`. Use `client.CreateClientConfig` in place of `client.ReadFromClientConfig` and provide a custom template and a custom config. +* (runtime) [#18475](https://github.com/cosmos/cosmos-sdk/pull/18475) Adds an implementation for core.branch.Service. +* (baseapp) [#18499](https://github.com/cosmos/cosmos-sdk/pull/18499) Add `MsgRouter` response type from message name function. +* (types) [#18768](https://github.com/cosmos/cosmos-sdk/pull/18768) Add MustValAddressFromBech32 function. +* (gRPC) [#19049](https://github.com/cosmos/cosmos-sdk/pull/19049) Add debug log prints for each gRPC request. +* (x/consensus) [#19483](https://github.com/cosmos/cosmos-sdk/pull/19483) Add consensus messages registration to consensus module. +* (types) [#19759](https://github.com/cosmos/cosmos-sdk/pull/19759) Align SignerExtractionAdapter in PriorityNonceMempool Remove. +* (client) [#19870](https://github.com/cosmos/cosmos-sdk/pull/19870) Add new query command `wait-tx`. Alias `event-query-tx-for` to `wait-tx` for backward compatibility. +* (crypto/keyring) [#20212](https://github.com/cosmos/cosmos-sdk/pull/20212) Expose the db keyring used in the keystore. +* (genutil) [#19971](https://github.com/cosmos/cosmos-sdk/pull/19971) Allow manually setting the consensus key type in genesis +* (debug) [#20328](https://github.com/cosmos/cosmos-sdk/pull/20328) Add consensus address for debug cmd. + +>>>>>>> 11de28062 (feat(client): add consensus address for debug cmd (#20328)) ### Improvements * (runtime) [#20264](https://github.com/cosmos/cosmos-sdk/pull/20264) Expose grpc query router via depinject. diff --git a/client/debug/main.go b/client/debug/main.go index e1048a427524..2b654ab89103 100644 --- a/client/debug/main.go +++ b/client/debug/main.go @@ -256,6 +256,7 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg var addr []byte // try hex, then bech32 +<<<<<<< HEAD var err error addr, err = hex.DecodeString(addrString) if err != nil { @@ -268,13 +269,55 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg if err3 != nil { return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3) } +======= + var ( + addr []byte + err error + ) + decodeFns := []func(text string) ([]byte, error){ + hex.DecodeString, + clientCtx.AddressCodec.StringToBytes, + clientCtx.ValidatorAddressCodec.StringToBytes, + clientCtx.ConsensusAddressCodec.StringToBytes, + } + errs := make([]any, 0, len(decodeFns)) + for _, fn := range decodeFns { + if addr, err = fn(addrString); err == nil { + break +>>>>>>> 11de28062 (feat(client): add consensus address for debug cmd (#20328)) + } + errs = append(errs, err) + } + if len(errs) == len(decodeFns) { + errTags := []string{ + "hex", "bech32 acc", "bech32 val", "bech32 con", + } + format := "" + for i := range errs { + if format != "" { + format += ", " + } + format += errTags[i] + ": %w" } + return fmt.Errorf("expected hex or bech32. Got errors: "+format, errs...) } +<<<<<<< HEAD cmd.Println("Address:", addr) cmd.Printf("Address (hex): %X\n", addr) cmd.Printf("Bech32 Acc: %s\n", sdk.AccAddress(addr)) cmd.Printf("Bech32 Val: %s\n", sdk.ValAddress(addr)) +======= + acc, _ := clientCtx.AddressCodec.BytesToString(addr) + val, _ := clientCtx.ValidatorAddressCodec.BytesToString(addr) + con, _ := clientCtx.ConsensusAddressCodec.BytesToString(addr) + + cmd.Println("Address:", addr) + cmd.Printf("Address (hex): %X\n", addr) + cmd.Printf("Bech32 Acc: %s\n", acc) + cmd.Printf("Bech32 Val: %s\n", val) + cmd.Printf("Bech32 Con: %s\n", con) +>>>>>>> 11de28062 (feat(client): add consensus address for debug cmd (#20328)) return nil }, }