-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_config.go
57 lines (45 loc) · 1.06 KB
/
app_config.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
package main
import (
"fmt"
"os"
"time"
)
type config struct {
Address string
Gateways map[string]string
GatewayTimeout time.Duration
GatewaysMinimumClients int
}
func newConfig(address string) (config, error) {
gateways, err := lookupEnvGateways()
if err != nil {
return config{}, err
}
cfg := config{
Address: address,
Gateways: gateways,
GatewayTimeout: 5 * time.Second,
GatewaysMinimumClients: 4,
}
return cfg, nil
}
func lookupEnvGateways() (map[string]string, error) {
urlMap := map[string]string{}
if url, ok := os.LookupEnv("ALCHEMY"); ok {
urlMap["Alchemy"] = url
}
if url, ok := os.LookupEnv("INFURA"); ok {
urlMap["Infura"] = url
}
if url, ok := os.LookupEnv("CHAINSTACK"); ok {
urlMap["Chainstack"] = url
}
if url, ok := os.LookupEnv("TENDERLY"); ok {
urlMap["Tenderly"] = url
}
const networks = 4
if len(urlMap) != networks {
return urlMap, fmt.Errorf("you must configure four Ethereum networks in the .env file")
}
return urlMap, nil
}