Skip to content

Commit a506e5c

Browse files
json tags
1 parent e698d80 commit a506e5c

File tree

1 file changed

+65
-58
lines changed

1 file changed

+65
-58
lines changed

networks/networks.go

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,87 @@
11
package networks
22

33
import (
4+
"strconv"
5+
46
"github.com/0xsequence/ethkit/ethproviders"
57
)
68

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
3010

31-
WSEnabled bool `toml:"wsEnabled"`
32-
WSURL string `toml:"wsUrl"`
11+
type ChainID string
3312

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+
}
3817

39-
NodeGateway *NodeGatewayNetwork `toml:"nodeGateway"`
18+
func (c ChainID) String() string {
19+
return string(c)
4020
}
4121

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"`
5147
}
5248

5349
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"`
5854
}
5955

6056
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"`
6864
}
6965

7066
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"`
7885
}
7986

8087
type NetworkType uint8
@@ -170,7 +177,7 @@ func (n Networks) EthProvidersConfig() ethproviders.Config {
170177
res := ethproviders.Config{}
171178
for _, network := range n {
172179
res[network.Name] = ethproviders.NetworkConfig{
173-
ID: network.ID,
180+
ID: network.ChainID,
174181
URL: network.NodeURL,
175182
WSEnabled: network.WSEnabled,
176183
WSURL: network.WSURL,

0 commit comments

Comments
 (0)