added rest server and status endpoint added get block endpoint added latest block endpoint add 404 if height is out of bounds add version endpoint add validators endpoint export GetBlockHeight add keys endpoints add txs endpoints added verb limiters to ednpoints only output node info + json structure improvement fixed wrong body parsing github PR template crypto.Address -> sdk.Address revert to old go-wire update glide remove print statement and update glide fix #554 add .DS_Store to .gitignore Massive consolidation: queue, data storage struct, store, logic, ... Small fixes
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package keys
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/gorilla/mux"
|
|
"github.com/pkg/errors"
|
|
keys "github.com/tendermint/go-crypto/keys"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func deleteKeyCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "delete <name>",
|
|
Short: "Delete the given key",
|
|
RunE: runDeleteCmd,
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
|
if len(args) != 1 || len(args[0]) == 0 {
|
|
return errors.New("You must provide a name for the key")
|
|
}
|
|
name := args[0]
|
|
|
|
buf := client.BufferStdin()
|
|
oldpass, err := client.GetPassword(
|
|
"DANGER - enter password to permanently delete key:", buf)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
kb, err := GetKeyBase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = kb.Delete(name, oldpass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("Password deleted forever (uh oh!)")
|
|
return nil
|
|
}
|
|
|
|
// REST
|
|
|
|
type DeleteKeyBody struct {
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func DeleteKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
name := vars["name"]
|
|
var kb keys.Keybase
|
|
var m DeleteKeyBody
|
|
|
|
decoder := json.NewDecoder(r.Body)
|
|
err := decoder.Decode(&m)
|
|
if err != nil {
|
|
w.WriteHeader(400)
|
|
w.Write([]byte(err.Error()))
|
|
return
|
|
}
|
|
|
|
kb, err = GetKeyBase()
|
|
if err != nil {
|
|
w.WriteHeader(500)
|
|
w.Write([]byte(err.Error()))
|
|
return
|
|
}
|
|
|
|
// TODO handle error if key is not available or pass is wrong
|
|
err = kb.Delete(name, m.Password)
|
|
if err != nil {
|
|
w.WriteHeader(500)
|
|
w.Write([]byte(err.Error()))
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(200)
|
|
}
|