Skip to content

Commit

Permalink
feat(client): add consensus address for debug cmd (#20328)
Browse files Browse the repository at this point in the history
Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com>
  • Loading branch information
mmsqe and hieuvubk committed May 13, 2024
1 parent ab1dbe1 commit 11de280
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (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.

### Improvements

Expand Down
34 changes: 25 additions & 9 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,42 @@ func AddrCmd() *cobra.Command {
addr []byte
err error
)
addr, err = hex.DecodeString(addrString)
if err != nil {
var err2 error
addr, err2 = clientCtx.AddressCodec.StringToBytes(addrString)
if err2 != nil {
var err3 error
addr, err3 = clientCtx.ValidatorAddressCodec.StringToBytes(addrString)
if err3 != nil {
return fmt.Errorf("expected hex or bech32. Got errors: hex: %w, bech32 acc: %w, bech32 val: %w", err, err2, err3)
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
}
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...)
}

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)
return nil
},
}
Expand Down

0 comments on commit 11de280

Please sign in to comment.