-
Notifications
You must be signed in to change notification settings - Fork 14
/
init.go
63 lines (55 loc) · 1.09 KB
/
init.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
package findaccount
import (
"embed"
"encoding/json"
"io"
"log"
"os"
)
var (
//go:embed chains/*.json
chainsFs embed.FS
//go:embed static/*
StaticFs embed.FS
infos = make(map[string]*ChainInfo)
)
func init() {
log.SetOutput(os.Stderr)
log.SetFlags(log.Lshortfile)
// parse out the embedded json files for RPC endpoints
for k := range Prefixes {
f, e := chainsFs.Open("chains/" + k + "-chain.json")
if e != nil {
log.Println(e)
continue
}
b, e := io.ReadAll(f)
if e != nil {
log.Println(e)
continue
}
_ = f.Close()
chainInfo := &ChainInfo{}
e = json.Unmarshal(b, chainInfo)
if e != nil {
log.Println(e)
continue
}
if chainInfo != nil && len(chainInfo.Apis.Rpc) > 0 {
infos[k] = chainInfo
}
}
// add extra known-good RPC servers....
for k, v := range additional {
if infos[k] == nil {
log.Println(k, "is not defined skipping addition of RPC")
continue
}
if infos[k].Apis.Rpc == nil {
infos[k].Apis.Rpc = make([]Rpc, 0)
}
for _, node := range v {
infos[k].Apis.Rpc = append(infos[k].Apis.Rpc, Rpc{Address: node})
}
}
}