Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

move to lib #30

Merged
merged 7 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ipc-client"
name = "ipc-agent"
cryptoAtwill marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
edition = "2021"

Expand Down
13 changes: 6 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Subnet>,
}

impl Config {
/// Reads a TOML configuration in the `s` string and returns a [`Config`] struct.
pub fn from_str(s: &str) -> Result<Self> {
let config = toml::from_str(&s)?;
pub fn from_string(s: &str) -> Result<Self> {
cryptoAtwill marked this conversation as resolved.
Show resolved Hide resolved
cryptoAtwill marked this conversation as resolved.
Show resolved Hide resolved
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<Self> {
cryptoAtwill marked this conversation as resolved.
Show resolved Hide resolved
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;

Expand All @@ -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";
Expand Down Expand Up @@ -134,6 +133,6 @@ mod tests {
"#
);

Config::from_str(config_str.as_str()).unwrap()
Config::from_string(config_str.as_str()).unwrap()
}
}
4 changes: 2 additions & 2 deletions src/jsonrpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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() {
/// let h = JsonRpcClientImpl::new("<DEFINE YOUR URL HERE>".parse().unwrap(), None);
/// let n = LotusJsonRPCClient::new(h);
/// println!(
/// "wallets: {:?}",
/// n.wallet_new(ipc_client::WalletKeyType::Secp256k1).await
/// n.wallet_new(ipc_agent::lotus::WalletKeyType::Secp256k1).await
/// );
/// }
/// ```
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod cli;
pub mod config;
pub mod jsonrpc;
pub mod lotus;
pub mod manager;
pub mod server;

7 changes: 0 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
mod cli;
mod config;
mod jsonrpc;
mod lotus;
mod manager;
mod server;

fn main() {}
6 changes: 3 additions & 3 deletions src/server/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/// }
Expand Down