Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NearRPCClient
Browse files Browse the repository at this point in the history
karim-en committed Nov 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 45bbaaf commit 755067c
Showing 4 changed files with 12 additions and 23 deletions.
6 changes: 5 additions & 1 deletion eth2near/contract_wrapper/src/near_rpc_client.rs
Original file line number Diff line number Diff line change
@@ -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<String>) -> 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()?;
2 changes: 1 addition & 1 deletion eth2near/eth2near-block-relay-rs/src/config.rs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs
Original file line number Diff line number Diff line change
@@ -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
25 changes: 5 additions & 20 deletions eth2near/eth2near-block-relay-rs/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 755067c

Please sign in to comment.