-
Notifications
You must be signed in to change notification settings - Fork 28
/
delete.go
51 lines (43 loc) · 1.02 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package keys
import (
"fmt"
"github.com/QOSGroup/qbase/client/context"
"github.com/QOSGroup/qbase/client/utils"
"github.com/spf13/cobra"
go_amino "github.com/tendermint/go-amino"
)
func deleteKeyCommand(cdc *go_amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "delete <name>",
Short: "Delete the given key",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
return runDeleteCmd(cliCtx, cmd, args)
},
}
return cmd
}
func runDeleteCmd(ctx context.CLIContext, cmd *cobra.Command, args []string) error {
name := args[0]
kb, err := GetKeyBase(ctx)
if err != nil {
return err
}
_, err = kb.Get(name)
if err != nil {
return err
}
buf := utils.BufferStdin()
oldpass, err := utils.GetPassword(
"DANGER - enter password to permanently delete key:", buf)
if err != nil {
return err
}
err = kb.Delete(name, oldpass)
if err != nil {
return err
}
fmt.Println("Password deleted forever (uh oh!)")
return nil
}