-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_extkey_from_parent_path.go
72 lines (59 loc) · 1.66 KB
/
create_extkey_from_parent_path.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
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"flag"
"fmt"
cfd "github.com/cryptogarageinc/cfd-go"
)
type CreatePubkeyFromParentPathCmd struct {
cmd string
flagSet *flag.FlagSet
xkey *string
path *string
networkType *string
}
func NewCreatePubkeyFromParentPathCmd() *CreatePubkeyFromParentPathCmd {
return &CreatePubkeyFromParentPathCmd{}
}
func (cmd *CreatePubkeyFromParentPathCmd) Command() string {
return cmd.cmd
}
func (cmd *CreatePubkeyFromParentPathCmd) Parse(args []string) {
cmd.flagSet.Parse(args)
}
func (cmd *CreatePubkeyFromParentPathCmd) Init() {
cmd.cmd = "createpubkeyfromparentpath"
cmd.flagSet = flag.NewFlagSet(cmd.cmd, flag.ExitOnError)
cmd.xkey = cmd.flagSet.String("k", "", "")
cmd.path = cmd.flagSet.String("p", "", "")
cmd.networkType = cmd.flagSet.String("n", "", "")
}
func (cmd *CreatePubkeyFromParentPathCmd) GetFlagSet() *flag.FlagSet {
return cmd.flagSet
}
func (cmd *CreatePubkeyFromParentPathCmd) Do(ctx context.Context) {
networkType := cfd.KCfdNetworkMainnet
if len(*cmd.networkType) > 0 {
switch *cmd.networkType {
case "mainnet":
networkType = cfd.KCfdNetworkMainnet
case "testnet":
networkType = cfd.KCfdNetworkTestnet
case "regtest":
networkType = cfd.KCfdNetworkRegtest
case "liquid":
networkType = cfd.KCfdNetworkLiquidv1
case "elementsregtest":
networkType = cfd.KCfdNetworkElementsRegtest
}
}
childKey, err := cfd.CfdGoCreateExtkeyFromParentPath(*cmd.xkey, *cmd.path, int(networkType), 1)
if err != nil {
panic(err)
}
pubkey, err := cfd.CfdGoGetPubkeyFromExtkey(childKey, int(networkType))
if err != nil {
panic(err)
}
fmt.Printf("xpub: %s\npubkey: %s\n", childKey, pubkey)
}