|
| 1 | +package types |
| 2 | + |
| 3 | +import "fmt" |
| 4 | + |
| 5 | +type ChainConfig struct { |
| 6 | + // ChainId of the chain |
| 7 | + ChainID string `json:"chainId"` |
| 8 | + // Chain name, ethereum-mainnet, ethereum-sepolia.. |
| 9 | + ChainName string `json:"chainName"` |
| 10 | + // Chain rpc url |
| 11 | + ChainRpcURL string `json:"chainRpcUrl"` |
| 12 | + //Chain wss socket |
| 13 | + ChainWssSocket string `json:"chainWssSocket"` |
| 14 | + //Locker Contract Address |
| 15 | + LockerContractAddress string `json:"lockerContractAddress"` |
| 16 | + // Block confirmation number |
| 17 | + BlockConfirmationNumber uint8 `json:"blockConfirmationNumber"` |
| 18 | + //Caip10 prefix |
| 19 | + CAIP10Prefix string `json:"caip10Prefix"` |
| 20 | + |
| 21 | +} |
| 22 | + |
| 23 | +func (c *ChainConfig) Validate() ( error) { |
| 24 | + if c.ChainID == "" { |
| 25 | + return fmt.Errorf("ChainID cannot be empty") |
| 26 | + } |
| 27 | + if c.ChainName == "" { |
| 28 | + return fmt.Errorf("ChainName cannot be empty") |
| 29 | + } |
| 30 | + if c.ChainRpcURL == "" { |
| 31 | + return fmt.Errorf("ChainRpcURL cannot be empty") |
| 32 | + } |
| 33 | + if c.ChainWssSocket == "" { |
| 34 | + return fmt.Errorf("ChainWssSocket cannot be empty") |
| 35 | + } |
| 36 | + if c.LockerContractAddress == "" { |
| 37 | + return fmt.Errorf("LockerContractAddress cannot be empty") |
| 38 | + } |
| 39 | + if c.BlockConfirmationNumber == 0 { |
| 40 | + return fmt.Errorf("BlockConfirmationNumber cannot be 0") |
| 41 | + } |
| 42 | + if c.CAIP10Prefix == "" { |
| 43 | + return fmt.Errorf("CAIP10Prefix cannot be empty") |
| 44 | + } |
| 45 | + return nil |
| 46 | +} |
| 47 | + |
| 48 | +func generateConfigForEthereumSepolia() ChainConfig { |
| 49 | + return ChainConfig{ |
| 50 | + ChainID: "11155111", |
| 51 | + ChainName: "ethereum-sepolia", |
| 52 | + ChainRpcURL: "https://sepolia.infura.io/v3/XXXXXXXXXX", |
| 53 | + ChainWssSocket: "wss://sepolia.infura.io/ws/v3/XXXXXXXXXX", |
| 54 | + LockerContractAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd", |
| 55 | + BlockConfirmationNumber: 12, |
| 56 | + CAIP10Prefix: "eip155:11155111", |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +func GenerateConfig() []ChainConfig { |
| 61 | + configs := []ChainConfig{generateConfigForEthereumSepolia()} |
| 62 | + return configs |
| 63 | +} |
0 commit comments