diff --git a/CHANGELOG.md b/CHANGELOG.md index a9d9d2f104..ecba003625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ BREAKING CHANGES to an infraction, slash them proportional to their stake at the time * Add REST endpoint to unrevoke a validator previously revoked for downtime * Add REST endpoint to retrieve liveness signing information for a validator +* [lcd] Switch key creation output to return bech32 FEATURES * [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag diff --git a/client/keys/add.go b/client/keys/add.go index 12ad97ee8a..216f84c2ac 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -215,8 +216,14 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte(err.Error())) return } + bech32Account, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes())) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return + } bz, err := json.Marshal(NewKeyResponse{ - Address: info.GetPubKey().Address().String(), + Address: bech32Account, Mnemonic: mnemonic, }) if err != nil { diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 2c46c5ffb7..bb2a205a96 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/spf13/viper" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys" @@ -59,9 +58,11 @@ func TestKeys(t *testing.T) { require.Equal(t, http.StatusOK, res.StatusCode, body) var resp keys.NewKeyResponse err = wire.Cdc.UnmarshalJSON([]byte(body), &resp) - require.Nil(t, err) - addr2 := resp.Address - assert.Len(t, addr2, 40, "Returned address has wrong format", addr2) + require.Nil(t, err, body) + + addr2Bech32 := resp.Address + _, err = sdk.GetAccAddressBech32(addr2Bech32) + require.NoError(t, err, "Failed to return a correct bech32 address") // existing keys res, body = Request(t, port, "GET", "/keys", nil) @@ -70,9 +71,6 @@ func TestKeys(t *testing.T) { err = cdc.UnmarshalJSON([]byte(body), &m) require.Nil(t, err) - addr2Acc, err := sdk.GetAccAddressHex(addr2) - require.Nil(t, err) - addr2Bech32 := sdk.MustBech32ifyAcc(addr2Acc) addrBech32 := sdk.MustBech32ifyAcc(addr) require.Equal(t, name, m[0].Name, "Did not serve keys name correctly")