Skip to content

Commit

Permalink
More fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Oct 7, 2024
1 parent 9ecb45f commit 6032085
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
9 changes: 6 additions & 3 deletions cmd/soroban-cli/src/config/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::arg;
use http::{HeaderName, HeaderValue};
use phf::phf_map;
use reqwest::header::{HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::str::FromStr;
Expand Down Expand Up @@ -32,9 +32,9 @@ pub enum Error {
#[error("funding failed: {0}")]
FundingFailed(String),
#[error(transparent)]
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
InvalidHeaderName(#[from] InvalidHeaderName),
#[error(transparent)]
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
InvalidHeaderValue(#[from] InvalidHeaderValue),
#[error("Invalid header: {0}")]
InvalidHeader(String),
}
Expand Down Expand Up @@ -251,6 +251,7 @@ mod tests {
let network = Network {
rpc_url: "http://localhost:8000".to_string(),
network_passphrase: passphrase::LOCAL.to_string(),
rpc_headers: Vec::new(),
};

let result = network
Expand Down Expand Up @@ -288,6 +289,7 @@ mod tests {
let network = Network {
rpc_url: server.url(),
network_passphrase: passphrase::TESTNET.to_string(),
rpc_headers: Vec::new(),
};
let url = network
.helper_url("GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI")
Expand Down Expand Up @@ -318,6 +320,7 @@ mod tests {
let network = Network {
rpc_url: server.url(),
network_passphrase: passphrase::TESTNET.to_string(),
rpc_headers: Vec::new(),
};
let url = network
.helper_url("GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI")
Expand Down
26 changes: 13 additions & 13 deletions cmd/soroban-cli/src/rpc_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

use http::{HeaderMap, HeaderName, HeaderValue};
use jsonrpsee_http_client::HeaderMap;

use crate::config::network::Network;
use crate::rpc;
Expand All @@ -9,10 +10,8 @@ use crate::rpc;
pub enum Error {
#[error(transparent)]
Rpc(#[from] rpc::Error),
#[error(transparent)]
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
#[error(transparent)]
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
#[error("invalid HTTP header: {0}")]
InvalidHeader(String),
}

#[derive(Debug)]
Expand All @@ -22,15 +21,16 @@ pub struct RpcClient {

impl RpcClient {
pub fn new(network: &Network) -> Result<Self, Error> {
let mut additional_headers = HeaderMap::new();
for header in &network.rpc_headers {
let header_name = HeaderName::from_bytes(header.0.as_bytes())?;
let header_value = HeaderValue::from_str(&header.1)?;

additional_headers.insert(header_name, header_value);
let mut header_hash_map = HashMap::new();
for (header_name, header_value) in &network.rpc_headers {
header_hash_map.insert(header_name.to_string(), header_value.to_string());
}

let client = rpc::Client::new_with_headers(&network.rpc_url, additional_headers)?;
let header_map: HeaderMap = (&header_hash_map)
.try_into()
.map_err(|e| Error::InvalidHeader(format!("{:?}", e)))?;

let client = rpc::Client::new_with_headers(&network.rpc_url, header_map)?;
Ok(Self { client })
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ mod tests {
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
format!("invalid HTTP header name")
format!("invalid HTTP header: http::Error(InvalidHeaderName)")
);
}

Expand Down

0 comments on commit 6032085

Please sign in to comment.