From 755067c8df409a0c4a11da714bd80dd5540b3165 Mon Sep 17 00:00:00 2001 From: karim-en Date: Thu, 30 Nov 2023 03:23:06 +0000 Subject: [PATCH] Fix `NearRPCClient` --- .../contract_wrapper/src/near_rpc_client.rs | 6 ++++- .../eth2near-block-relay-rs/src/config.rs | 2 +- .../src/eth2near_relay.rs | 2 +- .../eth2near-block-relay-rs/src/test_utils.rs | 25 ++++--------------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/eth2near/contract_wrapper/src/near_rpc_client.rs b/eth2near/contract_wrapper/src/near_rpc_client.rs index 6fd4f2e84..f767d8795 100644 --- a/eth2near/contract_wrapper/src/near_rpc_client.rs +++ b/eth2near/contract_wrapper/src/near_rpc_client.rs @@ -5,13 +5,15 @@ use std::error::Error; pub struct NearRPCClient { endpoint_url: String, client: Client, + api_key: String, } impl NearRPCClient { - pub fn new(endpoint_url: &str) -> Self { + pub fn new(endpoint_url: &str, api_key: &Option) -> Self { Self { endpoint_url: endpoint_url.to_string(), client: reqwest::blocking::Client::new(), + api_key: api_key.clone().unwrap_or_default(), } } @@ -30,6 +32,7 @@ impl NearRPCClient { let res = self .client .post(&self.endpoint_url) + .header("x-api-key", self.api_key.clone()) .json(&json_value) .send()? .text()?; @@ -50,6 +53,7 @@ impl NearRPCClient { let res = self .client .post(&self.endpoint_url) + .header("x-api-key", self.api_key.clone()) .json(&json_value) .send()? .text()?; diff --git a/eth2near/eth2near-block-relay-rs/src/config.rs b/eth2near/eth2near-block-relay-rs/src/config.rs index ef6c89a27..3910f4803 100644 --- a/eth2near/eth2near-block-relay-rs/src/config.rs +++ b/eth2near/eth2near-block-relay-rs/src/config.rs @@ -125,7 +125,7 @@ impl Config { } fn check_account_id(&self) { - let near_rpc_client = NearRPCClient::new(&self.near_endpoint); + let near_rpc_client = NearRPCClient::new(&self.near_endpoint, &self.near_endpoint_api_key); // check `signer_account_id` let _signer_account_id: near_sdk::AccountId = self diff --git a/eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs b/eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs index c30f622d4..ac73587bf 100644 --- a/eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs +++ b/eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs @@ -116,7 +116,7 @@ impl Eth2NearRelay { beacon_rpc_client, eth1_rpc_client: Eth1RPCClient::new(&config.eth1_endpoint), eth_client_contract: eth_contract, - near_rpc_client: NearRPCClient::new(&config.near_endpoint), + near_rpc_client: NearRPCClient::new(&config.near_endpoint, &config.near_endpoint_api_key), headers_batch_size: config.headers_batch_size as u64, ethereum_network: config.ethereum_network.to_string(), interval_between_light_client_updates_submission_in_epochs: config diff --git a/eth2near/eth2near-block-relay-rs/src/test_utils.rs b/eth2near/eth2near-block-relay-rs/src/test_utils.rs index d6756f3c9..b8428d0c2 100644 --- a/eth2near/eth2near-block-relay-rs/src/test_utils.rs +++ b/eth2near/eth2near-block-relay-rs/src/test_utils.rs @@ -247,15 +247,9 @@ pub fn get_client_contract( Box::new(eth_client_contract) } -pub fn get_relay( - from_file: bool, - config_for_test: &ConfigForTests, -) -> Eth2NearRelay { +pub fn get_relay(from_file: bool, config_for_test: &ConfigForTests) -> Eth2NearRelay { let config = get_config(config_for_test); - Eth2NearRelay::init( - &config, - get_client_contract(from_file, config_for_test) - ) + Eth2NearRelay::init(&config, get_client_contract(from_file, config_for_test)) } pub fn get_relay_with_update_from_file( @@ -270,16 +264,10 @@ pub fn get_relay_with_update_from_file( config.include_next_sync_committee_to_light_client = true; } - Eth2NearRelay::init( - &config, - get_client_contract(from_file, config_for_test) - ) + Eth2NearRelay::init(&config, get_client_contract(from_file, config_for_test)) } -pub fn get_relay_from_slot( - slot: u64, - config_for_test: &ConfigForTests, -) -> Eth2NearRelay { +pub fn get_relay_from_slot(slot: u64, config_for_test: &ConfigForTests) -> Eth2NearRelay { let config = get_config(config_for_test); let (relay_account, contract) = create_contract(&config_for_test); @@ -289,8 +277,5 @@ pub fn get_relay_from_slot( init_contract_from_specific_slot(&mut eth_client_contract, slot, config_for_test); - Eth2NearRelay::init( - &config, - Box::new(eth_client_contract) - ) + Eth2NearRelay::init(&config, Box::new(eth_client_contract)) }