-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (62 loc) · 1.77 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
package main
import (
"fmt"
"os"
"syscall"
"github.com/hyperledger/sawtooth-sdk-go/logging"
"github.com/hyperledger/sawtooth-sdk-go/processor"
"github.com/jessevdk/go-flags"
"github.com/yellowssi/SeaStorage-TP/handler"
)
const (
FamilyName string = "SeaStorage"
FamilyVersion string = "1.0"
)
type Opts struct {
Version bool `short:"V" long:"version" description:"Display version"`
Verbose []bool `short:"v" long:"verbose" description:"Increase verbosity"`
Connect string `short:"C" long:"connect" description:"Validator component endpoint to connect to" default:"tcp://localhost:4004"`
}
func main() {
var opts Opts
logger := logging.Get()
parser := flags.NewParser(&opts, flags.Default)
remaining, err := parser.Parse()
if err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
logger.Error("Failed to parse args: %v", err)
os.Exit(2)
}
}
if len(remaining) > 0 {
fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining)
os.Exit(2)
}
if opts.Version {
fmt.Println("SeaStorage Transaction Processor")
fmt.Println("Version: " + FamilyVersion)
os.Exit(0)
}
endpoint := opts.Connect
switch len(opts.Verbose) {
case 2:
logger.SetLevel(logging.DEBUG)
case 1:
logger.SetLevel(logging.INFO)
default:
logger.SetLevel(logging.WARN)
}
logger.Debugf("command line arguments: %v\n", os.Args)
logger.Debugf("verbose = %v\n", len(opts.Verbose))
logger.Debugf("endpoint = %v\n", endpoint)
hd := handler.NewSeaStorageHandler(FamilyName, []string{FamilyVersion})
proc := processor.NewTransactionProcessor(endpoint)
proc.AddHandler(hd)
proc.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM)
err = proc.Start()
if err != nil {
logger.Error("Processor stopped: ", err)
}
}