|
1 | 1 | package networks |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strconv" |
| 5 | + |
4 | 6 | "github.com/0xsequence/ethkit/ethproviders" |
5 | 7 | ) |
6 | 8 |
|
7 | | -type Networks map[string]*Network |
8 | | - |
9 | | -type Network struct { |
10 | | - ID uint64 `toml:"id"` |
11 | | - Name string `toml:"name"` |
12 | | - Title string `toml:"title"` |
13 | | - Type NetworkType `toml:"type"` |
14 | | - |
15 | | - LogoURL string `toml:"logoUrl"` |
16 | | - |
17 | | - ENSAddress string `toml:"ensAddress"` |
18 | | - |
19 | | - AuthChain bool `toml:"authChain"` |
20 | | - Deprecated bool `toml:"deprecated"` |
21 | | - Disabled bool `toml:"disabled"` |
22 | | - |
23 | | - NodeURL string `toml:"nodeUrl"` |
24 | | - IndexerURL string `toml:"indexerUrl"` |
25 | | - RelayerURL string `toml:"relayerUrl"` |
26 | | - |
27 | | - InternalNodeURL string `toml:"internalNodeUrl"` |
28 | | - InternalIndexerURL string `toml:"internalIndexerUrl"` |
29 | | - InternalRelayerURL string `toml:"internalRelayerUrl"` |
| 9 | +type Networks map[ChainID]*Network |
30 | 10 |
|
31 | | - WSEnabled bool `toml:"wsEnabled"` |
32 | | - WSURL string `toml:"wsUrl"` |
| 11 | +type ChainID string |
33 | 12 |
|
34 | | - BlockExplorer *BlockExplorerConfig `toml:"blockExplorer"` |
35 | | - |
36 | | - NativeToken *Currency `toml:"nativeToken"` |
37 | | - Currencies []*Currency `toml:"currencies"` |
| 13 | +func (c ChainID) Uint64() uint64 { |
| 14 | + u, _ := strconv.ParseUint(c.String(), 10, 64) |
| 15 | + return u |
| 16 | +} |
38 | 17 |
|
39 | | - NodeGateway *NodeGatewayNetwork `toml:"nodeGateway"` |
| 18 | +func (c ChainID) String() string { |
| 19 | + return string(c) |
40 | 20 | } |
41 | 21 |
|
42 | | -type Currency struct { |
43 | | - ContractAddress *string `toml:"contractAddress"` |
44 | | - Name string `toml:"name"` |
45 | | - Symbol string `toml:"symbol"` |
46 | | - Decimals uint64 `toml:"decimals"` |
47 | | - ImageURL string `toml:"imageUrl"` |
48 | | - Native bool `toml:"native"` |
49 | | - Default bool `toml:"default"` |
50 | | - Group CurrencyGroup `toml:"group"` |
| 22 | +type Network struct { |
| 23 | + ChainID uint64 `toml:"chain_id" json:"chainId,omitempty"` |
| 24 | + Name string `toml:"name" json:"name,omitempty"` |
| 25 | + Title string `toml:"title" json:"title,omitempty"` |
| 26 | + Type NetworkType `toml:"type" json:"type,omitempty"` |
| 27 | + LogoURL string `toml:"logo_url" json:"logoUrl,omitempty"` |
| 28 | + ENSAddress string `toml:"ens_address" json:"ensAddress,omitempty"` |
| 29 | + AuthChain bool `toml:"auth_chain" json:"authChain,omitempty"` |
| 30 | + Deprecated bool `toml:"deprecated" json:"deprecated,omitempty"` |
| 31 | + Disabled bool `toml:"disabled" json:"disabled,omitempty"` |
| 32 | + WSEnabled bool `toml:"ws_enabled" json:"wsEnabled,omitempty"` |
| 33 | + WSURL string `toml:"ws_url" json:"wsUrl,omitempty"` |
| 34 | + |
| 35 | + BlockExplorer *BlockExplorerConfig `toml:"block_explorer" json:"blockExplorer,omitempty"` |
| 36 | + NodeGateway *NodeGatewayNetwork `toml:"node_gateway" json:"nodeGateway,omitempty"` |
| 37 | + |
| 38 | + NodeURL string `toml:"node_url" json:"nodeUrl,omitempty"` |
| 39 | + IndexerURL string `toml:"indexer_url" json:"indexerUrl,omitempty"` |
| 40 | + RelayerURL string `toml:"relayer_url" json:"relayerUrl,omitempty"` |
| 41 | + InternalNodeURL string `toml:"internal_node_url" json:"-"` |
| 42 | + InternalIndexerURL string `toml:"internal_indexer_url" json:"-"` |
| 43 | + InternalRelayerURL string `toml:"internal_relayer_url" json:"-"` |
| 44 | + |
| 45 | + NativeToken *Currency `toml:"native_token" json:"nativeToken,omitempty"` |
| 46 | + Currencies []*Currency `toml:"currencies" json:"currencies,omitempty"` |
51 | 47 | } |
52 | 48 |
|
53 | 49 | type BlockExplorerConfig struct { |
54 | | - Name string `toml:"name"` |
55 | | - RootURL string `toml:"rootUrl"` |
56 | | - AddressURL string `toml:"addressUrl"` |
57 | | - TxnHashURL string `toml:"txnHashUrl"` |
| 50 | + Name string `toml:"name" json:"name,omitempty"` |
| 51 | + RootURL string `toml:"root_url" json:"rootUrl,omitempty"` |
| 52 | + AddressURL string `toml:"address_url" json:"addressUrl,omitempty"` |
| 53 | + TxnHashURL string `toml:"txn_hash_url" json:"txnHashUrl,omitempty"` |
58 | 54 | } |
59 | 55 |
|
60 | 56 | type NodeGatewayNetwork struct { |
61 | | - Endpoints []*NodeGatewayEndpoint `toml:"endpoints"` |
62 | | - Finality uint64 `toml:"finality"` |
63 | | - MonitorDisabled bool `toml:"monitorDisabled"` |
64 | | - MonitorPollInterval string `toml:"monitorPollInterval"` |
65 | | - MonitorBlockRetention uint64 `toml:"monitorBlockRetention"` |
66 | | - AlertsOff bool `toml:"alertsOff"` |
67 | | - Important bool `toml:"important"` |
| 57 | + Endpoints []*NodeGatewayEndpoint `toml:"endpoints" json:"endpoints,omitempty"` |
| 58 | + Finality uint64 `toml:"finality" json:"finality,omitempty"` |
| 59 | + MonitorDisabled bool `toml:"monitor_disabled" json:"monitorDisabled,omitempty"` |
| 60 | + MonitorPollInterval string `toml:"monitor_poll_interval" json:"monitorPollInterval,omitempty"` |
| 61 | + MonitorBlockRetention uint64 `toml:"monitor_block_retention" json:"monitorBlockRetention,omitempty"` |
| 62 | + AlertsOff bool `toml:"alerts_off" json:"alertsOff,omitempty"` |
| 63 | + Important bool `toml:"important" json:"important,omitempty"` |
68 | 64 | } |
69 | 65 |
|
70 | 66 | type NodeGatewayEndpoint struct { |
71 | | - Label string `toml:"label"` |
72 | | - Priority int `toml:"priority"` |
73 | | - URL string `toml:"url"` |
74 | | - WSURL string `toml:"wsurl"` |
75 | | - SkipMethods []string `toml:"skipMethods"` |
76 | | - AuxMethodNs []string `toml:"auxMethodNs"` |
77 | | - Disabled bool `toml:"disabled"` |
| 67 | + Label string `toml:"label" json:"label,omitempty"` |
| 68 | + Priority int `toml:"priority" json:"priority,omitempty"` |
| 69 | + URL string `toml:"url" json:"url,omitempty"` |
| 70 | + WSURL string `toml:"ws_url" json:"wsUrl,omitempty"` |
| 71 | + SkipMethods []string `toml:"skip_methods" json:"skipMethods,omitempty"` |
| 72 | + AuxMethodNs []string `toml:"aux_method_ns" json:"auxMethodNs,omitempty"` |
| 73 | + Disabled bool `toml:"disabled" json:"disabled,omitempty"` |
| 74 | +} |
| 75 | + |
| 76 | +type Currency struct { |
| 77 | + ContractAddress *string `toml:"contract_address" json:"contractAddress,omitempty"` |
| 78 | + Name string `toml:"name" json:"name,omitempty"` |
| 79 | + Symbol string `toml:"symbol" json:"symbol,omitempty"` |
| 80 | + Decimals uint64 `toml:"decimals" json:"decimals,omitempty"` |
| 81 | + ImageURL string `toml:"image_url" json:"imageUrl,omitempty"` |
| 82 | + Native bool `toml:"native" json:"native,omitempty"` |
| 83 | + Default bool `toml:"default" json:"default,omitempty"` |
| 84 | + Group CurrencyGroup `toml:"group" json:"group,omitempty"` |
78 | 85 | } |
79 | 86 |
|
80 | 87 | type NetworkType uint8 |
@@ -170,7 +177,7 @@ func (n Networks) EthProvidersConfig() ethproviders.Config { |
170 | 177 | res := ethproviders.Config{} |
171 | 178 | for _, network := range n { |
172 | 179 | res[network.Name] = ethproviders.NetworkConfig{ |
173 | | - ID: network.ID, |
| 180 | + ID: network.ChainID, |
174 | 181 | URL: network.NodeURL, |
175 | 182 | WSEnabled: network.WSEnabled, |
176 | 183 | WSURL: network.WSURL, |
|
0 commit comments