Skip to content

Commit

Permalink
get it compiling & running
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Feb 7, 2025
1 parent 95ec0b1 commit b15def2
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 17 deletions.
30 changes: 26 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions kinode/packages/settings/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kinode/packages/settings/settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ simulation-mode = []
anyhow = "1.0"
base64 = "0.22.0"
bincode = "1.3.3"
kinode_process_lib = "1.0.0"
kinode_process_lib = { path = "../../../../../process_lib" }
rmp-serde = "1.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions kinode/packages/settings/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ fn eth_config_convert(
use_as_provider: true,
}
}
SettingsNodeOrRpcUrl::RpcUrl { url, auth } => {
eth::NodeOrRpcUrl::RpcUrl { url, auth }
SettingsNodeOrRpcUrl::RpcUrl(url) => {
eth::NodeOrRpcUrl::RpcUrl { url, auth: None }
}
},
trusted: true,
Expand Down Expand Up @@ -668,7 +668,7 @@ fn make_widget(state: &SettingsState) -> String {
None
}
}
eth::NodeOrRpcUrl::RpcUrl(url) => Some(format!(
eth::NodeOrRpcUrl::RpcUrl { url, .. } => Some(format!( // TODO
"<li style=\"border-bottom: 1px solid black; padding: 2px;\">{}: Chain ID {}</li>",
url,
config.chain_id
Expand Down
1 change: 0 additions & 1 deletion kinode/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloy::providers::{Provider, RootProvider};
use alloy::pubsub::PubSubFrontend;
use alloy::rpc::client::Authorization;
use alloy::rpc::json_rpc::RpcError;
use anyhow::Result;
use dashmap::DashMap;
Expand Down
6 changes: 5 additions & 1 deletion kinode/src/eth/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use url::Url;
pub async fn activate_url_provider(provider: &mut UrlProvider) -> Result<()> {
match Url::parse(&provider.url)?.scheme() {
"ws" | "wss" => {
let ws = WsConnect::new(provider.url.to_string());
let ws = WsConnect {
url: provider.url.to_string(),
auth: provider.auth.clone().map(|a| a.into()),
config: None,
};

let client = tokio::time::timeout(
std::time::Duration::from_secs(10),
Expand Down
29 changes: 28 additions & 1 deletion kinode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use lib::types::core::{
NetworkErrorSender, NodeRouting, PrintReceiver, PrintSender, ProcessId, ProcessVerbosity,
Request, KERNEL_PROCESS_ID,
};
use lib::types::eth::RpcUrlConfigInput;
#[cfg(feature = "simulation-mode")]
use ring::{rand::SystemRandom, signature, signature::KeyPair};
use std::collections::HashMap;
Expand Down Expand Up @@ -84,6 +85,7 @@ async fn main() {
.get_one::<u8>("verbosity")
.expect("verbosity required");
let rpc = matches.get_one::<String>("rpc");
let rpc_config = matches.get_one::<String>("rpc-config");
let password = matches.get_one::<String>("password");

// logging mode is toggled at runtime by CTRL+L
Expand Down Expand Up @@ -129,7 +131,7 @@ async fn main() {
trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl {
url: rpc.to_string(),
auth: None, // TODO
auth: None,
},
},
);
Expand All @@ -141,6 +143,30 @@ async fn main() {
.await
.expect("failed to save new eth provider config!");
}
if let Some(rpc_config) = rpc_config {
let rpc_config = tokio::fs::read_to_string(rpc_config).await.expect("could not read rpc-config");
let rpc_config: Vec<RpcUrlConfigInput> = serde_json::from_str(&rpc_config).expect("rpc-config had invalid format");
for RpcUrlConfigInput { url, auth } in rpc_config {
eth_provider_config.insert(
0,
lib::eth::ProviderConfig {
chain_id: CHAIN_ID,
trusted: true,
provider: lib::eth::NodeOrRpcUrl::RpcUrl {
url,
auth,
},
},
);
}
// save the new provider config
tokio::fs::write(
home_directory_path.join(".eth_providers"),
serde_json::to_string(&eth_provider_config).unwrap(),
)
.await
.expect("failed to save new eth provider config!");
}

#[cfg(feature = "simulation-mode")]
{
Expand Down Expand Up @@ -731,6 +757,7 @@ fn build_command() -> Command {
.action(clap::ArgAction::SetTrue),
)
.arg(arg!(--rpc <RPC> "Add a WebSockets RPC URL at boot"))
.arg(arg!(--"rpc-config" <RPC_CONFIG_PATH> "Add WebSockets RPC URLs specified in config at boot"))
.arg(arg!(--password <PASSWORD> "Node password (in double quotes)"))
.arg(
arg!(--"max-log-size" <MAX_LOG_SIZE_BYTES> "Max size of all logs in bytes; setting to 0 -> no size limit (default 16MB)")
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tokio = { version = "1.28", features = ["rt-multi-thread"] }
[dependencies]
alloy = { version = "0.8.1", features = [
"json-rpc",
"rpc-client",
"rpc-types",
"rpc-types-eth",
] }
Expand Down
28 changes: 25 additions & 3 deletions lib/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy::rpc::client::Authorization;
use alloy::transports::Authorization as AlloyAuthorization;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};

Expand Down Expand Up @@ -227,7 +227,7 @@ impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
}

impl<'de> Deserialize<'de> for NodeOrRpcUrl {
fn deserialize<D>(serde::deserializer: D) -> Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand All @@ -242,7 +242,6 @@ impl<'de> Deserialize<'de> for NodeOrRpcUrl {
}

#[derive(Deserialize)]
#[serde(tag = "type")]
enum Helper {
Node {
kns_update: crate::core::KnsUpdate,
Expand All @@ -268,3 +267,26 @@ impl<'de> Deserialize<'de> for NodeOrRpcUrl {
})
}
}

#[derive(Deserialize, Serialize)]
pub struct RpcUrlConfigInput {
pub url: String,
pub auth: Option<Authorization>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub enum Authorization {
Basic(String),
Bearer(String),
Raw(String),
}

impl From<Authorization> for AlloyAuthorization {
fn from(auth: Authorization) -> AlloyAuthorization {
match auth {
Authorization::Basic(value) => AlloyAuthorization::Basic(value),
Authorization::Bearer(value) => AlloyAuthorization::Bearer(value),
Authorization::Raw(value) => AlloyAuthorization::Raw(value),
}
}
}

0 comments on commit b15def2

Please sign in to comment.