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

Commit

Permalink
move to lib (#30)
Browse files Browse the repository at this point in the history
* move to lib

* Update src/config/mod.rs

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>

* rename config function name

* import path

* rename crate

---------

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>
  • Loading branch information
cryptoAtwill and aakoshh committed Feb 24, 2023
1 parent bfef61d commit 52795ff
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
license-file = "LICENSE"

[package]
name = "ipc-client"
name = "ipc_agent"
version = "0.1.0"
edition.workspace = true
license-file.workspace = true
Expand Down
16 changes: 8 additions & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod subnet;

use std::collections::HashMap;
use std::fs;
use std::path::Path;

use anyhow::Result;
use serde::Deserialize;
Expand All @@ -21,29 +22,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_toml_str(s: &str) -> Result<Self> {
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> {
pub fn from_file(path: impl AsRef<Path>) -> Result<Self> {
let contents = fs::read_to_string(path)?;
let config: Config = Config::from_str(contents.as_str())?;
let config: Config = Config::from_toml_str(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 +52,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 +134,6 @@ mod tests {
"#
);

Config::from_str(config_str.as_str()).unwrap()
Config::from_toml_str(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: 1 addition & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
mod cli;
mod config;
mod jsonrpc;
mod lotus;
mod manager;
mod server;
use ipc_agent::cli;

#[tokio::main]
async fn main() {
Expand Down
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

0 comments on commit 52795ff

Please sign in to comment.