Skip to content

Commit

Permalink
use auth for url rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Feb 5, 2025
1 parent e99c8c5 commit bd927c2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion kinode/packages/settings/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ fn eth_config_convert(
use_as_provider: true,
}
}
SettingsNodeOrRpcUrl::RpcUrl(url) => eth::NodeOrRpcUrl::RpcUrl(url),
SettingsNodeOrRpcUrl::RpcUrl { url, auth } => eth::NodeOrRpcUrl::RpcUrl { url, auth },
},
trusted: true,
}))
Expand Down
4 changes: 2 additions & 2 deletions kinode/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl ActiveProviders {
},
);
}
NodeOrRpcUrl::RpcUrl(url) => {
NodeOrRpcUrl::RpcUrl { url, auth } => {
self.remove_provider(&url);
self.urls.insert(
0,
UrlProvider {
trusted: new.trusted,
url,
pubsub: vec![],
auth: None,
auth,
},
);
}
Expand Down
5 changes: 4 additions & 1 deletion kinode/src/eth/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pub fn providers_to_saved_configs(providers: &Providers) -> SavedConfigs {
.iter()
.map(|url_provider| ProviderConfig {
chain_id: *entry.key(),
provider: NodeOrRpcUrl::RpcUrl(url_provider.url.clone()),
provider: NodeOrRpcUrl::RpcUrl {
url: url_provider.url.clone(),
auth: url_provider.auth.clone(),
},
trusted: url_provider.trusted,
})
.chain(entry.nodes.iter().map(|node_provider| ProviderConfig {
Expand Down
13 changes: 8 additions & 5 deletions kinode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ async fn main() {
lib::eth::ProviderConfig {
chain_id: CHAIN_ID,
trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl(rpc.to_string()),
provider: lib::eth::NodeOrRpcUrl::RpcUrl {
url: rpc.to_string(),
auth: None, // TODO
},
},
);
// save the new provider config
Expand All @@ -150,10 +153,10 @@ async fn main() {
lib::eth::ProviderConfig {
chain_id: 31337,
trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl(format!(
"ws://localhost:{}",
local_chain_port
)),
provider: lib::eth::NodeOrRpcUrl::RpcUrl {
url: format!("ws://localhost:{local_chain_port}"),
auth: None,
},
},
);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ pub struct ProviderConfig {
pub chain_id: u64,
pub trusted: bool,
pub provider: NodeOrRpcUrl,
pub auth: Option<Authorization>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
Expand All @@ -212,14 +211,17 @@ pub enum NodeOrRpcUrl {
kns_update: crate::core::KnsUpdate,
use_as_provider: bool, // false for just-routers inside saved config
},
RpcUrl(String),
RpcUrl {
url: String,
auth: Option<Authorization>,
},
}

impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
fn eq(&self, other: &str) -> bool {
match self {
NodeOrRpcUrl::Node { kns_update, .. } => kns_update.name == other,
NodeOrRpcUrl::RpcUrl(url) => url == other,
NodeOrRpcUrl::RpcUrl { url, .. } => url == other,
}
}
}

0 comments on commit bd927c2

Please sign in to comment.