Skip to content

Commit

Permalink
Add endpoint api key to config
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Mar 11, 2024
1 parent 81a01bd commit c89e605
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions eth2near/contract_wrapper/src/dao_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions eth2near/contract_wrapper/src/dao_eth_client_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion eth2near/contract_wrapper/src/near_contract_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ impl NearContractWrapper {
signer_secret_key: &str,
contract_account_id: &str,
timeout: Option<std::time::Duration>,
api_key: Option<String>,
) -> 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");
Expand Down Expand Up @@ -80,6 +86,7 @@ impl NearContractWrapper {
path_to_signer_secret_key: &str,
contract_account_id: &str,
timeout: Option<std::time::Duration>,
api_key: Option<String>,
) -> NearContractWrapper {
let v: Value = serde_json::from_str(
&std::fs::read_to_string(path_to_signer_secret_key).expect("Unable to read file"),
Expand All @@ -96,6 +103,7 @@ impl NearContractWrapper {
&signer_secret_key,
contract_account_id,
timeout,
api_key,
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions eth2near/eth2near-block-relay-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

// Account id from which relay make requests
pub signer_account_id: String,

Expand Down
2 changes: 2 additions & 0 deletions eth2near/eth2near-block-relay-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn get_eth_contract_wrapper(config: &Config) -> Box<dyn ContractWrapper> {
Some(std::time::Duration::from_secs(
config.near_requests_timeout_seconds,
)),
config.near_endpoint_api_key.clone(),
))
}

Expand All @@ -48,6 +49,7 @@ fn get_dao_contract_wrapper(config: &Config) -> Box<dyn ContractWrapper> {
Some(std::time::Duration::from_secs(
config.near_requests_timeout_seconds,
)),
config.near_endpoint_api_key.clone(),
))
}

Expand Down

0 comments on commit c89e605

Please sign in to comment.