-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from VeerChaurasia/Implement/config/networks.g…
…o-#13 Implement/config/networks.go #13
- Loading branch information
Showing
1 changed file
with
171 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,180 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/BlocSoc-iitr/selene/common" | ||
"github.com/pkg/errors" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
type Network string | ||
|
||
const ( | ||
MAINNET Network = "MAINNET" | ||
GOERLI Network = "GOERLI" | ||
SEPOLIA Network = "SEPOLIA" | ||
) | ||
|
||
// hardcode the base configurations for each of the networks | ||
// check s and write switch case | ||
func (n Network) base_config(s string) (BaseConfig, error) { | ||
|
||
func (n Network) baseConfig(s string) (BaseConfig, error) { | ||
switch strings.ToUpper(s) { | ||
case "MAINNET": | ||
config, err := Mainnet() | ||
if err != nil { | ||
return BaseConfig{}, err | ||
} | ||
return config, nil | ||
case "GOERLI": | ||
config, err := Goerli() | ||
if err != nil { | ||
return BaseConfig{}, err | ||
} | ||
return config, nil | ||
case "SEPOLIA": | ||
config, err := Sepolia() | ||
if err != nil { | ||
return BaseConfig{}, err | ||
} | ||
return config, nil | ||
default: | ||
return BaseConfig{}, errors.New("network not recognized") | ||
} | ||
} | ||
func (n Network) chainID(s string) (uint64, error) { | ||
switch strings.ToUpper(s) { | ||
case "MAINNET": | ||
return 1, nil | ||
case "GOERLI": | ||
return 5, nil | ||
case "SEPOLIA": | ||
return 11155111, nil | ||
default: | ||
return 0, errors.New("network not recognized") | ||
} | ||
} | ||
func dataDir(network Network) (string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get user home directory: %w", err) | ||
} | ||
path := filepath.Join(homeDir, fmt.Sprintf("selene/data/%s", strings.ToLower(string(network)))) | ||
return path, nil | ||
} | ||
func Mainnet() (BaseConfig, error) { | ||
defaultCheckpoint, err := common.Hex_str_to_bytes("c7fc7b2f4b548bfc9305fa80bc1865ddc6eea4557f0a80507af5dc34db7bd9ce") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse default checkpoint: %w", err) | ||
} | ||
genesisRoot, err := common.Hex_str_to_bytes("4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse genesis root: %w", err) | ||
} | ||
consensusRPC := "https://www.lightclientdata.org" | ||
dataDir := dataDir(MAINNET) | ||
return BaseConfig{ | ||
DefaultCheckpoint: defaultCheckpoint, | ||
RpcPort: 8545, | ||
ConsensusRpc: &consensusRPC, | ||
Chain: ChainConfig{ | ||
ChainID: 1, | ||
GenesisTime: 1606824023, | ||
GenesisRoot: genesisRoot, | ||
}, | ||
Forks: Forks{ | ||
Genesis: Fork{ | ||
Epoch: 0, | ||
ForkVersion: []byte{0x00, 0x00, 0x00, 0x00}}, | ||
Altair: Fork{ | ||
Epoch: 74240, | ||
ForkVersion: []byte{0x01, 0x00, 0x00, 0x00}}, | ||
Bellatrix: Fork{ | ||
Epoch: 144896, | ||
ForkVersion: []byte{0x02, 0x00, 0x00, 0x00}}, | ||
Capella: Fork{ | ||
Epoch: 194048, | ||
ForkVersion: []byte{0x03, 0x00, 0x00, 0x00}}, | ||
Deneb: Fork{ | ||
Epoch: 269568, | ||
ForkVersion: []byte{0x04, 0x00, 0x00, 0x00}}, | ||
}, | ||
MaxCheckpointAge: 1_209_600, // 14 days | ||
DataDir: dataDir, | ||
}, nil | ||
} | ||
func Goerli() (BaseConfig, error) { | ||
defaultCheckpoint, err := common.Hex_str_to_bytes("f6e9d5fdd7c406834e888961beab07b2443b64703c36acc1274ae1ce8bb48839") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse default checkpoint: %w", err) | ||
} | ||
genesisRoot, err := common.Hex_str_to_bytes("043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse genesis root: %w", err) | ||
} | ||
dataDir := dataDir(GOERLI) | ||
return BaseConfig{ | ||
DefaultCheckpoint: defaultCheckpoint, | ||
RpcPort: 8545, | ||
ConsensusRpc: nil, | ||
Chain: ChainConfig{ | ||
ChainID: 5, | ||
GenesisTime: 1616508000, | ||
GenesisRoot: genesisRoot, | ||
}, | ||
Forks: Forks{ | ||
Genesis: Fork{ | ||
Epoch: 0, | ||
ForkVersion: []byte{0x00, 0x10, 0x20, 0x00}}, | ||
Altair: Fork{ | ||
Epoch: 36660, | ||
ForkVersion: []byte{0x01, 0x10, 0x20, 0x00}}, | ||
Bellatrix: Fork{ | ||
Epoch: 112260, | ||
ForkVersion: []byte{0x02, 0x10, 0x20, 0x00}}, | ||
Capella: Fork{ | ||
Epoch: 162304, | ||
ForkVersion: []byte{0x03, 0x10, 0x20, 0x00}}, | ||
Deneb: Fork{ | ||
Epoch: 231680, | ||
ForkVersion: []byte{0x04, 0x10, 0x20, 0x00}}, | ||
}, | ||
MaxCheckpointAge: 1_209_600, // 14 days | ||
DataDir: dataDir, | ||
}, nil | ||
} | ||
|
||
func (n Network) chain_id(s string) (uint64, error) { | ||
|
||
func Sepolia() (BaseConfig, error) { | ||
defaultCheckpoint, err := common.Hex_str_to_bytes("4135bf01bddcfadac11143ba911f1c7f0772fdd6b87742b0bc229887bbf62b48") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse default checkpoint: %w", err) | ||
} | ||
genesisRoot, err := common.Hex_str_to_bytes("d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078") | ||
if err != nil { | ||
return BaseConfig{}, fmt.Errorf("failed to parse genesis root: %w", err) | ||
} | ||
dataDir := dataDir(SEPOLIA) | ||
return BaseConfig{ | ||
DefaultCheckpoint: defaultCheckpoint, | ||
RpcPort: 8545, | ||
ConsensusRpc: nil, | ||
Chain: ChainConfig{ | ||
ChainID: 11155111, | ||
GenesisTime: 1655733600, | ||
GenesisRoot: genesisRoot, | ||
}, | ||
Forks: Forks{ | ||
Genesis: Fork{ | ||
Epoch: 0, | ||
ForkVersion: []byte{0x90, 0x00, 0x00, 0x69}}, | ||
Altair: Fork{ | ||
Epoch: 50, | ||
ForkVersion: []byte{0x90, 0x00, 0x00, 0x70}}, | ||
Bellatrix: Fork{ | ||
Epoch: 100, | ||
ForkVersion: []byte{0x90, 0x00, 0x00, 0x71}}, | ||
Capella: Fork{ | ||
Epoch: 56832, | ||
ForkVersion: []byte{0x90, 0x00, 0x00, 0x72}}, | ||
Deneb: Fork{ | ||
Epoch: 132608, | ||
ForkVersion: []byte{0x90, 0x00, 0x00, 0x73}}, | ||
}, | ||
MaxCheckpointAge: 1_209_600, // 14 days | ||
DataDir: dataDir, | ||
}, nil | ||
} | ||
func data_dir() {} |