-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchains.go
More file actions
67 lines (60 loc) · 1.81 KB
/
chains.go
File metadata and controls
67 lines (60 loc) · 1.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package seiconfig
import (
"embed"
"fmt"
"path"
)
//go:embed chains/*/genesis.json
var chainFS embed.FS
// ChainInfo describes a well-known Sei network whose genesis is embedded in
// this binary. Callers that need a chain not listed here must supply their own
// genesis configuration.
type ChainInfo struct {
ChainID string
RPC string
GenesisTime string
}
// knownChains is the authoritative set of chains with embedded genesis data.
var knownChains = map[string]ChainInfo{
"pacific-1": {
ChainID: "pacific-1",
RPC: "https://rpc.sei-apis.com",
GenesisTime: "2023-05-22T15:00:00.000000Z",
},
"atlantic-2": {
ChainID: "atlantic-2",
RPC: "https://rpc-testnet.sei-apis.com",
GenesisTime: "2023-02-22T23:45:12.575885043Z",
},
"arctic-1": {
ChainID: "arctic-1",
RPC: "https://rpc-arctic-1.sei-apis.com",
GenesisTime: "2024-01-25T20:18:30.242526108Z",
},
}
// KnownChain returns metadata for a well-known chain, or nil if the chain ID
// is not recognised.
func KnownChain(chainID string) *ChainInfo {
info, ok := knownChains[chainID]
if !ok {
return nil
}
return &info
}
// KnownChainIDs returns the set of chain IDs that have embedded genesis data.
func KnownChainIDs() []string {
ids := make([]string, 0, len(knownChains))
for id := range knownChains {
ids = append(ids, id)
}
return ids
}
// GenesisForChain returns the embedded genesis.json bytes for a well-known
// chain. Returns an error if the chain ID is not recognised — the caller must
// provide their own genesis source for unknown chains.
func GenesisForChain(chainID string) ([]byte, error) {
if _, ok := knownChains[chainID]; !ok {
return nil, fmt.Errorf("unknown chain %q: provide a custom genesis source", chainID)
}
return chainFS.ReadFile(path.Join("chains", chainID, "genesis.json"))
}