This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (78 loc) · 2.15 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
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"fmt"
"github.com/labstack/echo/v4"
_ "github.com/swaggo/echo-swagger/example/docs"
"rosen-bridge/tss/api"
"rosen-bridge/tss/app"
"rosen-bridge/tss/logger"
"rosen-bridge/tss/network"
"rosen-bridge/tss/storage"
"rosen-bridge/tss/utils"
)
func main() {
// parsing cli flags
projectPort := flag.String("port", "4000", "project port (e.g. 4000)")
p2pPort := flag.String("p2pPort", "8080", "p2p port (e.g. 8080)")
publishPath := flag.String(
"publishPath", "/p2p/send", "publish path of p2p (e.g. /p2p/send)",
)
subscriptionPath := flag.String(
"subscriptionPath", "/p2p/channel/subscribe", "subscriptionPath for p2p (e.g. /p2p/channel/subscribe)",
)
getPeerIDPath := flag.String(
"getP2pIDPath", "/p2p/getPeerID", "getP2pIDPath for p2p (e.g. /p2p/getPeerID)",
)
configFile := flag.String(
"configFile", "./conf/conf.env", "config file",
)
flag.Parse()
config, err := utils.InitConfig(*configFile)
if err != nil {
panic(err)
}
absAddress, err := utils.GetAbsoluteAddress(config.HomeAddress)
if err != nil {
panic(err)
}
logFile := fmt.Sprintf("%s/%s", absAddress, "tss.log")
err = logger.Init(logFile, config, false)
if err != nil {
panic(err)
}
logging := logger.NewSugar("main")
defer func() {
err = logger.Sync()
if err != nil {
logging.Error(err)
}
}()
logging.Infof("config: %+v", config)
// creating new instance of echo framework
e := echo.New()
// initiating and reading configs
// creating connection and storage and app instance
conn := network.InitConnection(*publishPath, *subscriptionPath, *p2pPort, *getPeerIDPath)
localStorage := storage.NewStorage()
tss := app.NewRosenTss(conn, localStorage, config)
// setting up peer home based on configs
err = tss.SetPeerHome(config.HomeAddress)
if err != nil {
logging.Fatal(err)
}
// subscribe to p2p
err = tss.GetConnection().Subscribe(*projectPort)
if err != nil {
logging.Fatal(err)
}
// running echo framework
tssController := api.NewTssController(tss)
// get p2pId
err = tss.SetP2pId()
if err != nil {
logging.Fatal(err)
}
api.InitRouting(e, tssController)
logging.Fatal(e.Start(fmt.Sprintf(":%s", *projectPort)))
}