Skip to content

Commit 3ef90c5

Browse files
committed
add rpc url auth
1 parent 82c8eed commit 3ef90c5

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ alloy-sol-types = "0.8.15"
1818
alloy = { version = "0.8.1", features = [
1919
"json-rpc",
2020
"rpc-types",
21+
"rpc-types-eth",
2122
] }
2223
anyhow = "1.0"
2324
bincode = "1.3.3"

src/eth.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{Message, Request as KiRequest};
2+
pub use alloy::rpc::client::Authorization;
23
pub use alloy::rpc::json_rpc::ErrorPayload;
34
pub use alloy::rpc::types::eth::pubsub::SubscriptionResult;
45
pub use alloy::rpc::types::pubsub::Params;
@@ -219,21 +220,67 @@ pub struct ProviderConfig {
219220
pub provider: NodeOrRpcUrl,
220221
}
221222

222-
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
223+
#[derive(Clone, Debug, Serialize, Hash, Eq, PartialEq)]
223224
pub enum NodeOrRpcUrl {
224225
Node {
225226
kns_update: crate::net::KnsUpdate,
226227
use_as_provider: bool, // false for just-routers inside saved config
227228
},
228-
RpcUrl(String),
229+
RpcUrl {
230+
url: String,
231+
auth: Option<Authorization>,
232+
},
229233
}
230234

231235
impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
232236
fn eq(&self, other: &str) -> bool {
233237
match self {
234238
NodeOrRpcUrl::Node { kns_update, .. } => kns_update.name == other,
235-
NodeOrRpcUrl::RpcUrl(url) => url == other,
239+
NodeOrRpcUrl::RpcUrl { url, .. } => url == other,
240+
}
241+
}
242+
}
243+
244+
impl<'de> Deserialize<'de> for NodeOrRpcUrl {
245+
fn deserialize<D>(serde::deserializer: D) -> Result<Self, D::Error>
246+
where
247+
D: serde::Deserializer<'de>,
248+
{
249+
#[derive(Deserialize)]
250+
#[serde(untagged)]
251+
enum RpcUrlHelper {
252+
String(String),
253+
Struct {
254+
url: String,
255+
auth: Option<Authorization>,
256+
},
236257
}
258+
259+
#[derive(Deserialize)]
260+
#[serde(tag = "type")]
261+
enum Helper {
262+
Node {
263+
kns_update: crate::core::KnsUpdate,
264+
use_as_provider: bool,
265+
},
266+
RpcUrl(RpcUrlHelper),
267+
}
268+
269+
let helper = Helper::deserialize(deserializer)?;
270+
271+
Ok(match helper {
272+
Helper::Node {
273+
kns_update,
274+
use_as_provider,
275+
} => NodeOrRpcUrl::Node {
276+
kns_update,
277+
use_as_provider,
278+
},
279+
Helper::RpcUrl(url_helper) => match url_helper {
280+
RpcUrlHelper::String(url) => NodeOrRpcUrl::RpcUrl { url, auth: None },
281+
RpcUrlHelper::Struct { url, auth } => NodeOrRpcUrl::RpcUrl { url, auth },
282+
},
283+
})
237284
}
238285
}
239286

0 commit comments

Comments
 (0)