From dfcff00de3d72ccf48a6ee0dca7c807ac2d59635 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Thu, 23 Feb 2023 16:31:16 +0800 Subject: [PATCH 1/5] move to lib --- Cargo.toml | 2 +- src/config/mod.rs | 13 ++++++------- src/jsonrpc/mod.rs | 4 ++-- src/lib.rs | 7 +++++++ src/main.rs | 7 ------- src/server/jsonrpc.rs | 6 +++--- 6 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 200d1904..4953b780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ipc-client" +name = "ipc-agent" version = "0.1.0" edition = "2021" diff --git a/src/config/mod.rs b/src/config/mod.rs index 5bca34f3..af415f6f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -21,29 +21,28 @@ pub const JSON_RPC_VERSION: &str = "2.0"; /// The top-level struct representing the config. Calls to [`Config::from_file`] deserialize into /// this struct. #[derive(Deserialize)] -pub(crate) struct Config { +pub struct Config { pub server: Server, pub subnets: HashMap, } impl Config { /// Reads a TOML configuration in the `s` string and returns a [`Config`] struct. - pub fn from_str(s: &str) -> Result { - let config = toml::from_str(&s)?; + pub fn from_string(s: &str) -> Result { + let config = toml::from_str(s)?; Ok(config) } /// Reads a TOML configuration file specified in the `path` and returns a [`Config`] struct. pub fn from_file(path: &str) -> Result { let contents = fs::read_to_string(path)?; - let config: Config = Config::from_str(contents.as_str())?; + let config: Config = Config::from_string(contents.as_str())?; Ok(config) } } #[cfg(test)] mod tests { - use std::collections::HashMap; use std::net::SocketAddr; use std::str::FromStr; @@ -52,7 +51,7 @@ mod tests { use ipc_sdk::subnet_id::{ROOTNET_ID, SubnetID}; use url::Url; - use crate::config::{Config, Server, Subnet}; + use crate::config::Config; // Arguments for the config's fields const SERVER_JSON_RPC_ADDR: &str = "127.0.0.1:3030"; @@ -134,6 +133,6 @@ mod tests { "# ); - Config::from_str(config_str.as_str()).unwrap() + Config::from_string(config_str.as_str()).unwrap() } } diff --git a/src/jsonrpc/mod.rs b/src/jsonrpc/mod.rs index 306d0d57..0e27d37c 100644 --- a/src/jsonrpc/mod.rs +++ b/src/jsonrpc/mod.rs @@ -43,7 +43,7 @@ pub trait JsonRpcClient { /// /// # Examples /// ```no_run -/// use ipc_client::{JsonRpcClientImpl, LotusClient, LotusJsonRPCClient}; +/// use ipc_agent::{jsonrpc::JsonRpcClientImpl, lotus::LotusClient, lotus::LotusJsonRPCClient}; /// /// #[tokio::main] /// async fn main() { @@ -51,7 +51,7 @@ pub trait JsonRpcClient { /// let n = LotusJsonRPCClient::new(h); /// println!( /// "wallets: {:?}", -/// n.wallet_new(ipc_client::WalletKeyType::Secp256k1).await +/// n.wallet_new(ipc_agent::lotus::WalletKeyType::Secp256k1).await /// ); /// } /// ``` diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..0bfbb0d0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +pub mod cli; +pub mod config; +pub mod jsonrpc; +pub mod lotus; +pub mod manager; +pub mod server; + diff --git a/src/main.rs b/src/main.rs index 6399c09d..f328e4d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1 @@ -mod cli; -mod config; -mod jsonrpc; -mod lotus; -mod manager; -mod server; - fn main() {} diff --git a/src/server/jsonrpc.rs b/src/server/jsonrpc.rs index 87df0a8d..64f30d93 100644 --- a/src/server/jsonrpc.rs +++ b/src/server/jsonrpc.rs @@ -15,12 +15,12 @@ use crate::config::JSON_RPC_ENDPOINT; /// /// # Examples /// ```no_run -/// use agent::config::Config; -/// use agent::node::jsonrpc::JsonRPCServer; +/// use ipc_agent::config::Config; +/// use ipc_agent::server::jsonrpc::JsonRPCServer; /// /// #[tokio::main] /// async fn main() { -/// let config = Config::from_file("PATH TO YOUR CONFIG FILE"); +/// let config = Config::from_file("PATH TO YOUR CONFIG FILE").unwrap(); /// let n = JsonRPCServer::new(config.server); /// n.run().await; /// } From 980a6a46d1f091532efdf91afb9ade1393a462ee Mon Sep 17 00:00:00 2001 From: cryptoAtwill <108330426+cryptoAtwill@users.noreply.github.com> Date: Thu, 23 Feb 2023 22:22:46 +0800 Subject: [PATCH 2/5] Update src/config/mod.rs Co-authored-by: Akosh Farkash --- src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index af415f6f..b2114910 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -34,7 +34,7 @@ impl Config { } /// Reads a TOML configuration file specified in the `path` and returns a [`Config`] struct. - pub fn from_file(path: &str) -> Result { + pub fn from_file(path: impl AsRef) -> Result { let contents = fs::read_to_string(path)?; let config: Config = Config::from_string(contents.as_str())?; Ok(config) From a01d45b50b9a38293a9ec1dd2e45c41b2adf4fe3 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Fri, 24 Feb 2023 09:30:53 +0800 Subject: [PATCH 3/5] rename config function name --- src/config/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index af415f6f..15fa97ab 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -28,7 +28,7 @@ pub struct Config { impl Config { /// Reads a TOML configuration in the `s` string and returns a [`Config`] struct. - pub fn from_string(s: &str) -> Result { + pub fn from_toml_str(s: &str) -> Result { let config = toml::from_str(s)?; Ok(config) } @@ -36,7 +36,7 @@ impl Config { /// Reads a TOML configuration file specified in the `path` and returns a [`Config`] struct. pub fn from_file(path: &str) -> Result { let contents = fs::read_to_string(path)?; - let config: Config = Config::from_string(contents.as_str())?; + let config: Config = Config::from_toml_str(contents.as_str())?; Ok(config) } } @@ -133,6 +133,6 @@ mod tests { "# ); - Config::from_string(config_str.as_str()).unwrap() + Config::from_toml_str(config_str.as_str()).unwrap() } } From 10ff69d3a864f58429b17f5dbbe37be2b1073aad Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Fri, 24 Feb 2023 09:32:01 +0800 Subject: [PATCH 4/5] import path --- src/config/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/mod.rs b/src/config/mod.rs index e97b74b7..4baac8db 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -9,6 +9,7 @@ mod subnet; use std::collections::HashMap; use std::fs; +use std::path::Path; use anyhow::Result; use serde::Deserialize; From 7fd7f0ab4193e8505ab516d17b5245500e639906 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Fri, 24 Feb 2023 19:37:53 +0800 Subject: [PATCH 5/5] rename crate --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 12ea096f..9dd89477 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" license-file = "LICENSE" [package] -name = "ipc-agent" +name = "ipc_agent" version = "0.1.0" edition.workspace = true license-file.workspace = true