Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpc options #278

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ The relayer is configured via a JSON file, the path to which is passed in via th

- Additional query parameters to include in the API requests.

`"http-headers": map[string]string`

- Additional HTTP headers to include in the API requests.

`"info-api": APIConfig`

- The configuration for the Avalanche Info API node. The `InfoAPI` object has the following configuration:
Expand All @@ -150,6 +154,10 @@ The relayer is configured via a JSON file, the path to which is passed in via th

- Additional query parameters to include in the API requests.

`"http-headers": map[string]string`

- Additional HTTP headers to include in the API requests.

`"storage-location": string`

- The path to the directory in which the relayer will store its state. Defaults to `./awm-relayer-storage`.
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type WarpQuorum struct {
type APIConfig struct {
BaseURL string `mapstructure:"base-url" json:"base-url"`
QueryParams map[string]string `mapstructure:"query-parameters" json:"query-parameters"`
HTTPHeaders map[string]string `mapstructure:"http-headers" json:"http-headers"`
}

// Top-level configuration
Expand Down
5 changes: 5 additions & 0 deletions config/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var (
testPk2 string = "0x12389e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8123"
queryParamKey1 string = "key1"
queryParamVal1 string = "val1"
httpHeaderKey1 string = "keyheader1"
httpHeaderVal1 string = "valheader1"
)

// Valid configuration objects to be used by tests in external packages
Expand All @@ -24,6 +26,9 @@ var (
QueryParams: map[string]string{
queryParamKey1: queryParamVal1,
},
HTTPHeaders: map[string]string{
httpHeaderKey1: httpHeaderVal1,
},
},
InfoAPI: &APIConfig{
BaseURL: "http://test.avax.network",
Expand Down
5 changes: 4 additions & 1 deletion peers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (

// InitializeOptions initializes the rpc options for an API
func InitializeOptions(apiConfig *config.APIConfig) []rpc.Option {
options := make([]rpc.Option, 0, len(apiConfig.QueryParams))
options := make([]rpc.Option, 0, len(apiConfig.QueryParams)+len(apiConfig.HTTPHeaders))
for key, value := range apiConfig.QueryParams {
options = append(options, rpc.WithQueryParam(key, value))
}
for key, value := range apiConfig.HTTPHeaders {
options = append(options, rpc.WithHeader(key, value))
}
return options
}