-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathuns_config.go
70 lines (59 loc) · 1.35 KB
/
uns_config.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
package resolution
import (
"embed"
"encoding/json"
)
// contracts struct of contracts
type contracts map[string]struct {
Address string
Implementation string
LegacyAddresses []string
DeploymentBlock string
}
// networks struct of contracts
type networks map[string]struct {
Contracts contracts
}
const (
Mainnet string = "mainnet"
Polygon string = "polygon"
Mumbai string = "mumbai"
Goerli string = "goerli"
)
const (
Layer1 string = "Layer 1"
Layer2 string = "Layer 2"
)
type NetworkContracts map[string]contracts
var NetworkNameToId = map[string]int{
Mainnet: 1,
Polygon: 137,
Mumbai: 80001,
Goerli: 5,
}
//go:embed uns/uns-config.json
var unsConfigEmbed embed.FS
var unsConfigJSON, _ = unsConfigEmbed.ReadFile("uns/uns-config.json")
func parseAllContracts(data []byte) (networks, error) {
var networksObject struct {
Networks networks
}
err := json.Unmarshal(data, &networksObject)
if err != nil {
return nil, err
}
return networksObject.Networks, nil
}
func newContracts() (NetworkContracts, error) {
networks := make(NetworkContracts)
var err error
net, err := parseAllContracts(unsConfigJSON)
if err != nil {
return nil, err
}
networks[Mainnet] = net["1"].Contracts
networks[Polygon] = net["137"].Contracts
networks[Mumbai] = net["80001"].Contracts
networks[Goerli] = net["5"].Contracts
return networks, nil
}