From 16471c965381feecf1b877554e7af787912c7bae Mon Sep 17 00:00:00 2001 From: Ethan Tuttle Date: Mon, 26 Feb 2024 22:48:52 -0500 Subject: [PATCH] chore: add cfg throughout for espidf --- moksha-wallet/Cargo.toml | 10 +++++----- moksha-wallet/src/btcprice.rs | 1 + moksha-wallet/src/config_path.rs | 3 +++ moksha-wallet/src/error.rs | 4 ++++ moksha-wallet/src/http/mod.rs | 2 ++ moksha-wallet/src/localstore/mod.rs | 2 ++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/moksha-wallet/Cargo.toml b/moksha-wallet/Cargo.toml index 62479676..bdf2a50c 100644 --- a/moksha-wallet/Cargo.toml +++ b/moksha-wallet/Cargo.toml @@ -24,26 +24,26 @@ async-trait = "0.1.77" lightning-invoice = "0.29.0" url = "2.5.0" +[target.'cfg(not(target_os="espidf"))'.dependencies] +dirs = "5.0.1" + [target.'cfg(target_family = "wasm")'.dependencies] gloo-net = { version = "0.5.0" } serde-wasm-bindgen = "0.6.3" wasm-bindgen = "0.2.90" rexie = "0.5.0" tokio = { version = "1.35.1", features = ["rt", "sync"] } -dirs = "5.0.1" [target.'cfg(all(not(target_family="wasm"), not(target_os="espidf")))'.dependencies] reqwest = { version = "0.11.23", features = ["serde_json", "json", "rustls-tls"], default-features = false } tokio = { version = "1.35.1", features = ["rt", "rt-multi-thread", "macros"] } sqlx = { version = "0.7.3", default-features = false, features = ["sqlite", "runtime-tokio", "tls-rustls", "migrate", "macros"] } -dirs = "5.0.1" - -[target.xtensa-esp32s3-none-elf.dependencies] +[target.'cfg(target_os="espidf")'.dependencies] gloo-net = { version = "0.5.0" } rexie = "0.5.0" tokio = { version = "1.35.1", features = ["rt", "sync"] } [dev-dependencies] tempfile = "3.9.0" -mockall = "0.12.1" +mockall = "0.12.1" \ No newline at end of file diff --git a/moksha-wallet/src/btcprice.rs b/moksha-wallet/src/btcprice.rs index f72d560c..58c254b2 100644 --- a/moksha-wallet/src/btcprice.rs +++ b/moksha-wallet/src/btcprice.rs @@ -1,6 +1,7 @@ use crate::error::MokshaWalletError; async fn execute_request(url: &str) -> Result { + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] { let request_client = reqwest::Client::new(); diff --git a/moksha-wallet/src/config_path.rs b/moksha-wallet/src/config_path.rs index 14256218..b8a51ac8 100644 --- a/moksha-wallet/src/config_path.rs +++ b/moksha-wallet/src/config_path.rs @@ -1,3 +1,4 @@ +#[cfg(not(target_os = "espidf"))] use dirs::home_dir; use std::{fs::create_dir, path::PathBuf}; @@ -15,6 +16,7 @@ pub const ENV_DB_PATH: &str = "WALLET_DB_PATH"; /// let db_path = moksha_wallet::config_path::db_path(); /// println!("Database path: {}", db_path); /// ``` +#[cfg(not(target_os = "espidf"))] pub fn db_path() -> String { std::env::var(ENV_DB_PATH).map_or_else( |_| { @@ -43,6 +45,7 @@ pub fn db_path() -> String { ) } +#[cfg(not(target_os = "espidf"))] pub fn config_dir() -> PathBuf { let home = home_dir() .expect("home dir not found") diff --git a/moksha-wallet/src/error.rs b/moksha-wallet/src/error.rs index ef77cde0..985c772c 100644 --- a/moksha-wallet/src/error.rs +++ b/moksha-wallet/src/error.rs @@ -12,10 +12,12 @@ pub enum MokshaWalletError { #[error("SerdeJsonError - {0}")] Json(#[from] serde_json::Error), + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] #[error("ReqwestError - {0}")] Reqwest(#[from] reqwest::Error), + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] #[error("InvalidHeaderValueError - {0}")] InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue), @@ -31,10 +33,12 @@ pub enum MokshaWalletError { #[error("MokshaCoreError - {0}")] MokshaCore(#[from] moksha_core::error::MokshaCoreError), + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] #[error("DB Error {0}")] Db(#[from] sqlx::Error), + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] #[error("Sqlite Error {0}")] Sqlite(#[from] sqlx::sqlite::SqliteError), diff --git a/moksha-wallet/src/http/mod.rs b/moksha-wallet/src/http/mod.rs index 07284311..b5f7b036 100644 --- a/moksha-wallet/src/http/mod.rs +++ b/moksha-wallet/src/http/mod.rs @@ -1,3 +1,4 @@ +#[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] pub mod reqwest; @@ -6,6 +7,7 @@ pub mod wasm; #[derive(Debug, Clone)] pub struct CrossPlatformHttpClient { + #[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] client: ::reqwest::Client, } diff --git a/moksha-wallet/src/localstore/mod.rs b/moksha-wallet/src/localstore/mod.rs index 54dd196d..ace3490d 100644 --- a/moksha-wallet/src/localstore/mod.rs +++ b/moksha-wallet/src/localstore/mod.rs @@ -3,6 +3,7 @@ use moksha_core::proof::Proofs; use crate::error::MokshaWalletError; +#[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] pub mod sqlite; @@ -15,6 +16,7 @@ pub struct WalletKeyset { pub mint_url: String, } +#[cfg(not(target_os = "espidf"))] #[cfg(not(target_arch = "wasm32"))] #[async_trait(?Send)] pub trait LocalStore {