|
| 1 | +package seiconfig |
| 2 | + |
| 3 | +import ( |
| 4 | + "embed" |
| 5 | + "fmt" |
| 6 | + "path" |
| 7 | +) |
| 8 | + |
| 9 | +//go:embed chains/*/genesis.json |
| 10 | +var chainFS embed.FS |
| 11 | + |
| 12 | +// ChainInfo describes a well-known Sei network whose genesis is embedded in |
| 13 | +// this binary. Callers that need a chain not listed here must supply their own |
| 14 | +// genesis configuration. |
| 15 | +type ChainInfo struct { |
| 16 | + ChainID string |
| 17 | + RPC string |
| 18 | + GenesisTime string |
| 19 | +} |
| 20 | + |
| 21 | +// knownChains is the authoritative set of chains with embedded genesis data. |
| 22 | +var knownChains = map[string]ChainInfo{ |
| 23 | + "pacific-1": { |
| 24 | + ChainID: "pacific-1", |
| 25 | + RPC: "https://rpc.sei-apis.com", |
| 26 | + GenesisTime: "2023-05-22T15:00:00Z", |
| 27 | + }, |
| 28 | + "atlantic-2": { |
| 29 | + ChainID: "atlantic-2", |
| 30 | + RPC: "https://rpc-testnet.sei-apis.com", |
| 31 | + GenesisTime: "2023-02-24T01:00:00Z", |
| 32 | + }, |
| 33 | + "arctic-1": { |
| 34 | + ChainID: "arctic-1", |
| 35 | + RPC: "https://rpc-arctic-1.sei-apis.com", |
| 36 | + GenesisTime: "2024-01-25T20:18:30.242526108Z", |
| 37 | + }, |
| 38 | +} |
| 39 | + |
| 40 | +// KnownChain returns metadata for a well-known chain, or nil if the chain ID |
| 41 | +// is not recognised. |
| 42 | +func KnownChain(chainID string) *ChainInfo { |
| 43 | + info, ok := knownChains[chainID] |
| 44 | + if !ok { |
| 45 | + return nil |
| 46 | + } |
| 47 | + return &info |
| 48 | +} |
| 49 | + |
| 50 | +// KnownChainIDs returns the set of chain IDs that have embedded genesis data. |
| 51 | +func KnownChainIDs() []string { |
| 52 | + ids := make([]string, 0, len(knownChains)) |
| 53 | + for id := range knownChains { |
| 54 | + ids = append(ids, id) |
| 55 | + } |
| 56 | + return ids |
| 57 | +} |
| 58 | + |
| 59 | +// GenesisForChain returns the embedded genesis.json bytes for a well-known |
| 60 | +// chain. Returns an error if the chain ID is not recognised — the caller must |
| 61 | +// provide their own genesis source for unknown chains. |
| 62 | +func GenesisForChain(chainID string) ([]byte, error) { |
| 63 | + if _, ok := knownChains[chainID]; !ok { |
| 64 | + return nil, fmt.Errorf("unknown chain %q: provide a custom genesis source", chainID) |
| 65 | + } |
| 66 | + return chainFS.ReadFile(path.Join("chains", chainID, "genesis.json")) |
| 67 | +} |
0 commit comments