forked from dgyoshi/cfd-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_pubkey_from_privkey.go
63 lines (51 loc) · 1.58 KB
/
get_pubkey_from_privkey.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
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"context"
"flag"
"fmt"
cfd "github.com/cryptogarageinc/cfd-go"
)
// GetUserListCmd registers a user in the system.
type GetPubkeyFromPrivkeyCmd struct {
cmd string
flagSet *flag.FlagSet
privkey *string
wif *string
isCompress *bool
}
// NewGetPubkeyFromPrivkeyCmd returns a new GetPubkeyFromPrivkeyCmd struct.
func NewGetPubkeyFromPrivkeyCmd() *GetPubkeyFromPrivkeyCmd {
return &GetPubkeyFromPrivkeyCmd{}
}
// Command returns the command name.
func (cmd *GetPubkeyFromPrivkeyCmd) Command() string {
return cmd.cmd
}
// Parse parses the command arguments.
func (cmd *GetPubkeyFromPrivkeyCmd) Parse(args []string) {
cmd.flagSet.Parse(args)
}
// Init initializes the command.
func (cmd *GetPubkeyFromPrivkeyCmd) Init() {
cmd.cmd = "getpubkeyfromprivkey"
cmd.flagSet = flag.NewFlagSet(cmd.cmd, flag.ExitOnError)
cmd.privkey = cmd.flagSet.String("privkey", "", "private key in hex format")
cmd.wif = cmd.flagSet.String("wif", "", "private key in WIF format")
cmd.isCompress = cmd.flagSet.Bool("comp", false, "flag wether compress public key")
}
// GetFlagSet returns the flag set for this command.
func (cmd *GetPubkeyFromPrivkeyCmd) GetFlagSet() *flag.FlagSet {
return cmd.flagSet
}
// Do performs the command action.
func (cmd *GetPubkeyFromPrivkeyCmd) Do(ctx context.Context) {
if *cmd.privkey == "" && *cmd.wif == "" {
fmt.Println("privkey or wif is required")
return
}
pubkey, err := cfd.CfdGoGetPubkeyFromPrivkey(*cmd.privkey, *cmd.wif, *cmd.isCompress)
if err != nil {
fmt.Println(err)
}
fmt.Printf("public key: '%s'\n", pubkey)
}