forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
allocs.go
76 lines (60 loc) · 1.55 KB
/
allocs.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
package allocs
import (
"encoding/json"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/netconf"
"github.com/ethereum/go-ethereum/core/types"
_ "embed"
)
var (
//go:embed devnet.json
devnetJSON []byte
//go:embed staging.json
stagingJSON []byte
//go:embed omega.json
omegaJSON []byte
//go:embed mainnet.json
mainnetJSON []byte
devnetAlloc = mustUnmarshalAlloc(devnetJSON)
stagingAlloc = mustUnmarshalAlloc(stagingJSON)
omegaAlloc = mustUnmarshalAlloc(omegaJSON)
mainnetAlloc = mustUnmarshalAlloc(mainnetJSON)
)
// locked maps network ID to whether the network's allocations are locked.
// Once a persistent network has been deployed, its allocs should be locked,
// so that allocs here are consistent with the live network's genesis.
var locked = map[netconf.ID]bool{
netconf.Omega: true,
netconf.Mainnet: true,
}
func IsLocked(network netconf.ID) bool {
return locked[network]
}
func Alloc(network netconf.ID) (types.GenesisAlloc, error) {
switch network {
case netconf.Devnet:
return devnetAlloc, nil
case netconf.Staging:
return stagingAlloc, nil
case netconf.Omega:
return omegaAlloc, nil
case netconf.Mainnet:
return mainnetAlloc, nil
default:
return nil, errors.New("unknown network")
}
}
func MustAlloc(network netconf.ID) types.GenesisAlloc {
alloc, err := Alloc(network)
if err != nil {
panic(err)
}
return alloc
}
func mustUnmarshalAlloc(data []byte) types.GenesisAlloc {
var alloc types.GenesisAlloc
if err := json.Unmarshal(data, &alloc); err != nil {
panic(err)
}
return alloc
}