Merge PR #1540: Tweak Gaia Lite key output
This commit is contained in:
commit
1d12985e56
|
@ -7,7 +7,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -162,12 +161,6 @@ type NewKeyBody struct {
|
||||||
Password string `json:"password"`
|
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
|
// add new key REST handler
|
||||||
func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var kb keys.Keybase
|
var kb keys.Keybase
|
||||||
|
@ -216,22 +209,24 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bech32Account, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes()))
|
|
||||||
|
keyOutput, err := Bech32KeyOutput(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bz, err := json.Marshal(NewKeyResponse{
|
|
||||||
Address: bech32Account,
|
keyOutput.Seed = mnemonic
|
||||||
Mnemonic: mnemonic,
|
|
||||||
})
|
output, err := json.MarshalIndent(keyOutput, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return
|
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
|
// function to just a new seed to display in the UI before actually persisting it in the keybase
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestKeys(t *testing.T) {
|
||||||
res, body = Request(t, port, "POST", "/keys", jsonStr)
|
res, body = Request(t, port, "POST", "/keys", jsonStr)
|
||||||
|
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
var resp keys.NewKeyResponse
|
var resp keys.KeyOutput
|
||||||
err = wire.Cdc.UnmarshalJSON([]byte(body), &resp)
|
err = wire.Cdc.UnmarshalJSON([]byte(body), &resp)
|
||||||
require.Nil(t, err, body)
|
require.Nil(t, err, body)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue