From c89e605a4cd65ec72245d67c186fa0d4071d4e04 Mon Sep 17 00:00:00 2001 From: karim-en Date: Thu, 30 Nov 2023 02:55:10 +0000 Subject: [PATCH] Add endpoint api key to config --- eth2near/contract_wrapper/src/dao_contract.rs | 1 + .../contract_wrapper/src/dao_eth_client_contract.rs | 1 + eth2near/contract_wrapper/src/near_contract_wrapper.rs | 10 +++++++++- eth2near/eth2near-block-relay-rs/src/config.rs | 3 +++ eth2near/eth2near-block-relay-rs/src/main.rs | 2 ++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/eth2near/contract_wrapper/src/dao_contract.rs b/eth2near/contract_wrapper/src/dao_contract.rs index 6825557c..3129dc43 100644 --- a/eth2near/contract_wrapper/src/dao_contract.rs +++ b/eth2near/contract_wrapper/src/dao_contract.rs @@ -720,6 +720,7 @@ mod tests { SIGNER_PRIVATE_KEY, DAO_CONTRACT_ACCOUNT_ID, None, + None, ); let mut dao_contract = DAOContract::new(Box::new(near_contract_wrapper)); diff --git a/eth2near/contract_wrapper/src/dao_eth_client_contract.rs b/eth2near/contract_wrapper/src/dao_eth_client_contract.rs index 33039e69..477d12d7 100644 --- a/eth2near/contract_wrapper/src/dao_eth_client_contract.rs +++ b/eth2near/contract_wrapper/src/dao_eth_client_contract.rs @@ -169,6 +169,7 @@ mod tests { &signer_private_key, CONTRACT_ACCOUNT_ID, None, + None, )); let eth_client = eth_client_contract::EthClientContract::new(near_contract_wrapper); diff --git a/eth2near/contract_wrapper/src/near_contract_wrapper.rs b/eth2near/contract_wrapper/src/near_contract_wrapper.rs index 18daa9cd..9400901a 100644 --- a/eth2near/contract_wrapper/src/near_contract_wrapper.rs +++ b/eth2near/contract_wrapper/src/near_contract_wrapper.rs @@ -42,12 +42,18 @@ impl NearContractWrapper { signer_secret_key: &str, contract_account_id: &str, timeout: Option, + api_key: Option, ) -> NearContractWrapper { let signer_account_id = account_id .parse() .expect("Error on parsing account id during creation near contract wrapper"); - let client = + let mut client = JsonRpcClient::with(utils::new_near_rpc_client(timeout)).connect(near_endpoint); + + if let Some(api_key) = api_key { + client = client.header(near_jsonrpc_client::auth::ApiKey::new(api_key).unwrap()); + } + let contract_account = contract_account_id .parse() .expect("Error on parsing contract account id during creation near contract wrapper"); @@ -80,6 +86,7 @@ impl NearContractWrapper { path_to_signer_secret_key: &str, contract_account_id: &str, timeout: Option, + api_key: Option, ) -> NearContractWrapper { let v: Value = serde_json::from_str( &std::fs::read_to_string(path_to_signer_secret_key).expect("Unable to read file"), @@ -96,6 +103,7 @@ impl NearContractWrapper { &signer_secret_key, contract_account_id, timeout, + api_key, ) } } diff --git a/eth2near/eth2near-block-relay-rs/src/config.rs b/eth2near/eth2near-block-relay-rs/src/config.rs index cd629bdd..ef6c89a2 100644 --- a/eth2near/eth2near-block-relay-rs/src/config.rs +++ b/eth2near/eth2near-block-relay-rs/src/config.rs @@ -22,6 +22,9 @@ pub struct Config { // endpoint for a full node on the NEAR chain pub near_endpoint: String, + // api key for the NEAR endpoint + pub near_endpoint_api_key: Option, + // Account id from which relay make requests pub signer_account_id: String, diff --git a/eth2near/eth2near-block-relay-rs/src/main.rs b/eth2near/eth2near-block-relay-rs/src/main.rs index 6bf76cd1..c9132b09 100644 --- a/eth2near/eth2near-block-relay-rs/src/main.rs +++ b/eth2near/eth2near-block-relay-rs/src/main.rs @@ -33,6 +33,7 @@ fn get_eth_contract_wrapper(config: &Config) -> Box { Some(std::time::Duration::from_secs( config.near_requests_timeout_seconds, )), + config.near_endpoint_api_key.clone(), )) } @@ -48,6 +49,7 @@ fn get_dao_contract_wrapper(config: &Config) -> Box { Some(std::time::Duration::from_secs( config.near_requests_timeout_seconds, )), + config.near_endpoint_api_key.clone(), )) }