diff --git a/client/keys/add.go b/client/keys/add.go index 216f84c2ac..4d4dee0b9c 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -7,7 +7,6 @@ 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" @@ -162,12 +161,6 @@ type NewKeyBody struct { Password string `json:"password"` } -// new key response REST body -type NewKeyResponse struct { - Address string `json:"address"` - Mnemonic string `json:"mnemonic"` -} - // add new key REST handler func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { var kb keys.Keybase @@ -216,22 +209,18 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte(err.Error())) return } - bech32Account, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes())) + + keyOutput, err := Bech32KeyOutput(info) + keyOutput.Seed = mnemonic + + output, err := json.MarshalIndent(keyOutput, "", " ") if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error())) return } - bz, err := json.Marshal(NewKeyResponse{ - Address: bech32Account, - Mnemonic: mnemonic, - }) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) - return - } - w.Write(bz) + + w.Write(output) } // function to just a new seed to display in the UI before actually persisting it in the keybase diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index bb2a205a96..234ed57b01 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -56,7 +56,7 @@ func TestKeys(t *testing.T) { res, body = Request(t, port, "POST", "/keys", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) - var resp keys.NewKeyResponse + var resp keys.KeyOutput err = wire.Cdc.UnmarshalJSON([]byte(body), &resp) require.Nil(t, err, body)