Skip to content

Commit 4ddd217

Browse files
committed
Set User-Agent header for coingecko requests
1 parent 3c97623 commit 4ddd217

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

core/lib/external_price_api/src/coingecko_api.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,30 @@ pub struct CoinGeckoPriceAPIClient {
1717

1818
const DEFAULT_COINGECKO_API_URL: &str = "https://pro-api.coingecko.com";
1919
const COINGECKO_AUTH_HEADER: &str = "x-cg-pro-api-key";
20+
const USER_AGENT_HEADER: &str = "User-Agent";
21+
const USER_AGENT_VALUE: &str = "zksync-era-node/0.1 (https://github.com/matter-labs/zksync-era)";
2022
const ETH_ID: &str = "eth";
2123
const ZKSYNC_ID: &str = "zksync";
2224

2325
impl CoinGeckoPriceAPIClient {
2426
pub fn new(config: ExternalPriceApiClientConfig) -> Self {
25-
let client = if let Some(api_key) = &config.api_key {
26-
let mut headers = reqwest::header::HeaderMap::new();
27+
let mut headers = reqwest::header::HeaderMap::new();
28+
headers.insert(
29+
reqwest::header::HeaderName::from_static(USER_AGENT_HEADER),
30+
reqwest::header::HeaderValue::from_static(USER_AGENT_VALUE),
31+
);
32+
if let Some(api_key) = &config.api_key {
2733
headers.insert(
2834
reqwest::header::HeaderName::from_static(COINGECKO_AUTH_HEADER),
2935
reqwest::header::HeaderValue::from_str(api_key)
3036
.expect("Failed to create header value"),
3137
);
32-
33-
reqwest::Client::builder()
34-
.default_headers(headers)
35-
.timeout(config.client_timeout)
36-
.build()
37-
.expect("Failed to build reqwest client")
38-
} else {
39-
reqwest::Client::new()
40-
};
38+
}
39+
let client = reqwest::Client::builder()
40+
.default_headers(headers)
41+
.timeout(config.client_timeout)
42+
.build()
43+
.expect("Failed to build reqwest client");
4144

4245
let base_url = config
4346
.base_url

0 commit comments

Comments
 (0)