Skip to content

Commit

Permalink
separate info API cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Oct 24, 2023
1 parent 5b5decb commit 7c28d55
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The relayer is configured via a JSON file, the path to which is passed in via th
`"p-chain-api-url": string`
- The URL of the Avalanche P-Chain API node to which the relayer will connect. Defaults to `https://api.avax.network`.

`info-api-url": string`
- The URL of the Avalanche API node to which the relayer will connect to get information about the network. The Info API must be enabled on the node.

`"encrypt-connection": boolean`
- Whether or not to encrypt the connection to the P-Chain API node. Defaults to `true`.

Expand Down
15 changes: 13 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Config struct {
LogLevel string `mapstructure:"log-level" json:"log-level"`
NetworkID uint32 `mapstructure:"network-id" json:"network-id"`
PChainAPIURL string `mapstructure:"p-chain-api-url" json:"p-chain-api-url"`
InfoAPIURL string `mapstructure:"info-api-url" json:"info-api-url"`
EncryptConnection bool `mapstructure:"encrypt-connection" json:"encrypt-connection"`
StorageLocation string `mapstructure:"storage-location" json:"storage-location"`
SourceSubnets []SourceSubnet `mapstructure:"source-subnets" json:"source-subnets"`
Expand Down Expand Up @@ -109,6 +110,7 @@ func BuildConfig(v *viper.Viper) (Config, bool, error) {
cfg.LogLevel = v.GetString(LogLevelKey)
cfg.NetworkID = v.GetUint32(NetworkIDKey)
cfg.PChainAPIURL = v.GetString(PChainAPIURLKey)
cfg.InfoAPIURL = v.GetString(InfoAPIURLKey)
cfg.EncryptConnection = v.GetBool(EncryptConnectionKey)
cfg.StorageLocation = v.GetString(StorageLocationKey)
if err := v.UnmarshalKey(DestinationSubnetsKey, &cfg.DestinationSubnets); err != nil {
Expand Down Expand Up @@ -153,11 +155,17 @@ func BuildConfig(v *viper.Viper) (Config, bool, error) {
protocol = "http"
}

pChainapiUrl, err := utils.ConvertProtocol(cfg.PChainAPIURL, protocol)
pChainApiUrl, err := utils.ConvertProtocol(cfg.PChainAPIURL, protocol)
if err != nil {
return Config{}, false, err
}
cfg.PChainAPIURL = pChainapiUrl
cfg.PChainAPIURL = pChainApiUrl

infoApiUrl, err := utils.ConvertProtocol(cfg.InfoAPIURL, protocol)
if err != nil {
return Config{}, false, err
}
cfg.InfoAPIURL = infoApiUrl

globalConfig = cfg

Expand All @@ -174,6 +182,9 @@ func (c *Config) Validate() error {
if _, err := url.ParseRequestURI(c.PChainAPIURL); err != nil {
return err
}
if _, err := url.ParseRequestURI(c.InfoAPIURL); err != nil {
return err
}

// Validate the destination chains
destinationChains := set.NewSet[string](len(c.DestinationSubnets))
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
LogLevel: "info",
NetworkID: 1337,
PChainAPIURL: "http://test.avax.network",
InfoAPIURL: "http://info.avax.network",
EncryptConnection: false,
SourceSubnets: []SourceSubnet{
{
Expand Down
1 change: 1 addition & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
LogLevelKey = "log-level"
NetworkIDKey = "network-id"
PChainAPIURLKey = "p-chain-api-url"
InfoAPIURLKey = "info-api-url"
SourceSubnetsKey = "source-subnets"
DestinationSubnetsKey = "destination-subnets"
EncryptConnectionKey = "encrypt-connection"
Expand Down
2 changes: 1 addition & 1 deletion main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
panic(err)
}

network, responseChans, err := peers.NewNetwork(logger, registerer, cfg.NetworkID, sourceSubnetIDs, sourceChainIDs, cfg.PChainAPIURL)
network, responseChans, err := peers.NewNetwork(logger, registerer, cfg.NetworkID, sourceSubnetIDs, sourceChainIDs, cfg.InfoAPIURL)
if err != nil {
logger.Error(
"Failed to create app request network",
Expand Down
1 change: 1 addition & 0 deletions tests/basic_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func BasicRelay() {
LogLevel: logging.Info.LowerString(),
NetworkID: peers.LocalNetworkID,
PChainAPIURL: subnetAInfo.ChainNodeURIs[0],
InfoAPIURL: subnetAInfo.ChainNodeURIs[0],
EncryptConnection: false,
StorageLocation: storageLocation,
SourceSubnets: []config.SourceSubnet{
Expand Down

0 comments on commit 7c28d55

Please sign in to comment.