added sunnys changes
This commit is contained in:
parent
270e216262
commit
2c697c982b
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user