forked from dgyoshi/cfd-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (68 loc) · 1.54 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
cfd "github.com/cryptogarageinc/cfd-go"
)
// Command represent a command that can be invoked.
type Command interface {
Command() string
GetFlagSet() *flag.FlagSet
Init()
Do(context.Context)
}
var commandMap map[string]Command
func init() {
ret := cfd.CfdInitialize()
if ret == (int)(cfd.KCfdIllegalArgumentError) {
panic("Fail Initialize CFD")
}
commandMap = make(map[string]Command)
for _, cmd := range [...]Command{
NewGetPubkeyFromPrivkeyCmd(),
NewGetExtkeypairFromSeedCmd(),
NewGenPrivkeyFromStringsCmd(),
NewDecodeRawTransactionCmd(),
NewVerifySignTransactionCmd(),
NewEncodeDerFromSignatureCmd(),
NewInitializeTransactionCmd(),
NewAppendTxInCmd(),
NewAppendTxOutCmd(),
NewSetRawReissueAssetCmd(),
NewBlindRawTransactionCmd(),
NewEstimateFeeCmd(),
NewCreateSignatureHashCmd(),
NewGetSignatureCmd(),
NewAddSignTransactionCmd(),
NewSignWithPrivkeyCmd(),
NewVerifySignatureCmd(),
NewGetCommitmentCmd(),
NewCreatePubkeyFromParentPathCmd(),
} {
cmd.Init()
commandMap[cmd.Command()] = cmd
}
}
func main() {
if len(os.Args) == 1 {
fmt.Println("Need to specify a command. Available commands are:")
for name := range commandMap {
fmt.Println(name)
}
return
}
cmdName := os.Args[1]
cmd, ok := commandMap[cmdName]
if !ok {
fmt.Println("Unknown command ", cmdName)
return
}
if err := cmd.GetFlagSet().Parse(os.Args[2:]); err != nil {
log.Fatalf("Error parsing flags %v", err)
}
ctx := context.Background()
cmd.Do(ctx)
}