github.com/0xsequence/ethkit@v1.25.0/ethproviders/config.go (about)

     1  package ethproviders
     2  
     3  import "strings"
     4  
     5  type Config map[string]NetworkConfig
     6  
     7  type NetworkConfig struct {
     8  	ID  uint64 `toml:"id" json:"id"`
     9  	URL string `toml:"url" json:"url"`
    10  
    11  	WSEnabled bool   `toml:"ws_enabled" json:"wsEnabled"`
    12  	WSURL     string `toml:"ws_url" json:"wsUrl"`
    13  
    14  	AuthChain bool `toml:"auth_chain" json:"authChain"`
    15  	Testnet   bool `toml:"testnet" json:"testnet"`
    16  	Disabled  bool `toml:"disabled" json:"disabled"`
    17  }
    18  
    19  func (n Config) GetByID(id uint64) (NetworkConfig, bool) {
    20  	for _, v := range n {
    21  		if v.ID == id {
    22  			return v, true
    23  		}
    24  	}
    25  	return NetworkConfig{}, false
    26  }
    27  
    28  func (n Config) GetByName(name string) (NetworkConfig, bool) {
    29  	name = strings.ToLower(name)
    30  	for k, v := range n {
    31  		if k == name {
    32  			return v, true
    33  		}
    34  	}
    35  	return NetworkConfig{}, false
    36  }
    37  
    38  func (n Config) AuthChain() (NetworkConfig, bool) {
    39  	for _, v := range n {
    40  		if v.AuthChain && !v.Testnet {
    41  			return v, true
    42  		}
    43  	}
    44  	return NetworkConfig{}, false
    45  }
    46  
    47  func (n Config) TestAuthChain() (NetworkConfig, bool) {
    48  	for _, v := range n {
    49  		if v.AuthChain && v.Testnet {
    50  			return v, true
    51  		}
    52  	}
    53  	return NetworkConfig{}, false
    54  }