forked from vythuy0979/autonity-oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (44 loc) · 1.47 KB
/
main.go
File metadata and controls
50 lines (44 loc) · 1.47 KB
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
package main
import (
"autonity-oracle/config"
contract "autonity-oracle/contract_binder/contract"
"autonity-oracle/helpers"
"autonity-oracle/oracle_server"
"autonity-oracle/types"
"log"
"os"
"os/signal"
"syscall"
)
func main() { //nolint
conf := config.MakeConfig()
log.Printf("\n\n\n \tRunning autonity oracle server %s\n\twith plugin directory: %s\n "+
"\tby connecting to L1 node: %s\n \ton oracle contract address: %s \n\n\n",
config.Version, conf.PluginDIR, conf.AutonityWSUrl, types.OracleContractAddress)
dialer := &types.L1Dialer{}
client, err := dialer.Dial(conf.AutonityWSUrl)
if err != nil {
log.Printf("Cannot connect to Autonity network via web socket: %s", err.Error())
helpers.PrintUsage()
os.Exit(1)
}
oc, err := contract.NewOracle(types.OracleContractAddress, client)
if err != nil {
log.Printf("Cannot bind to oracle contract in Autonity network via web socket: %s", err.Error())
helpers.PrintUsage()
os.Exit(1)
}
oracle := oracleserver.NewOracleServer(conf, dialer, client, oc)
go oracle.Start()
defer oracle.Stop()
// Wait for interrupt signal to gracefully shut down the server with
// a timeout of 5 seconds.
quit := make(chan os.Signal, 1)
// kill (no param) default send syscall.SIGTERM
// kill -2 is syscall.SIGINT
// kill -9 is syscall.SIGKILL but can't be caught, so don't need to add it
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down oracle server...")
log.Println("Server exiting")
}