-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
92 lines (77 loc) · 1.91 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
package main
import (
"log"
"net/http"
"os"
"runtime"
"github.com/bithyve/bithyve-wrapper/electrs"
//"strings"
erpc "github.com/Varunram/essentials/rpc"
flags "github.com/jessevdk/go-flags"
)
var opts struct {
DevEnv bool `short:"d" description:"Start dev env"`
Mainnet bool `short:"m" description:"Connect to mainnet"`
ElectrsURL string `short:"u" description:"Connect to your own electrs instance"`
BackupURL string `short:"b" description:"Connect to your own backup electrs instance"`
Test bool `short:"t" description:"Use for testing"`
Logs bool `short:"l" description:"Testing logs"`
}
func startHandlers() {
MultiData()
MultiBalTxs()
MultiUtxoTxs()
MultiUtxos()
MultiBalances()
MultiTxs()
NewMultiUtxoTxs()
erpc.SetupPingHandler()
GetFees(opts.Mainnet)
GetFeesE(opts.Mainnet)
PostTx()
RelayTxid()
RelayGetRequest()
}
func main() {
log.Println("wrapper is running on: ", runtime.NumCPU(), " cores")
runtime.GOMAXPROCS(runtime.NumCPU() * 2)
_, err := flags.ParseArgs(&opts, os.Args)
if err != nil {
log.Fatal(err)
}
startHandlers()
if opts.Mainnet {
log.Println("connecting to electrs mainnet")
electrs.SetMainnet()
}
if opts.Logs {
log.Println("starting in logs mode")
electrs.ToggleLogs()
}
if opts.DevEnv {
log.Println("starting in devenv mode")
electrs.SetDevEnv()
}
if opts.ElectrsURL != "" {
if opts.BackupURL != "" {
electrs.SetURL(opts.ElectrsURL, opts.BackupURL)
} else {
if opts.Mainnet {
electrs.SetURL(opts.ElectrsURL, "https://api.bithyve.com")
} else {
electrs.SetURL(opts.ElectrsURL, "https://test-wrapper.bithyve.com")
}
}
}
if opts.Test {
err = http.ListenAndServe("localhost:8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
} else {
err = http.ListenAndServeTLS("localhost:445", "ssl/server.crt", "ssl/server.key", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
}