Skip to content

Commit

Permalink
Make hyper dependencies optional for v1 only
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Aug 10, 2024
1 parent 5bc96c9 commit ca02d14
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions payjoin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = "src/main.rs"
[features]
native-certs = ["reqwest/rustls-tls-native-roots"]
danger-local-https = ["rcgen", "reqwest/rustls-tls", "rustls", "hyper-rustls", "payjoin/danger-local-https", "tokio-rustls"]
v1 = ["hyper", "hyper-util", "http-body-util"]
v2 = ["payjoin/v2", "payjoin/io"]

[dependencies]
Expand All @@ -31,10 +32,10 @@ bitcoincore-rpc = "0.19.0"
clap = { version = "~4.0.32", features = ["derive"] }
config = "0.13.3"
env_logger = "0.9.0"
http-body-util = "0.1"
hyper = { version = "1", features = ["full"] }
http-body-util = { version = "0.1", optional = true }
hyper = { version = "1", features = ["full"], optional = true }
hyper-rustls = { version = "0.26", optional = true }
hyper-util = "0.1"
hyper-util = { version = "0.1", optional = true }
log = "0.4.7"
payjoin = { version = "0.19.0", features = ["send", "receive", "base64"] }
rcgen = { version = "0.11.1", optional = true }
Expand Down
9 changes: 1 addition & 8 deletions payjoin-cli/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use payjoin::{bitcoin, PjUri};
pub mod config;
use crate::app::config::AppConfig;

#[cfg(not(feature = "v2"))]
#[cfg(all(not(feature = "v2"), feature = "v1"))]
pub(crate) mod v1;
#[cfg(feature = "v2")]
pub(crate) mod v2;
Expand Down Expand Up @@ -126,13 +126,6 @@ fn try_contributing_inputs(
Ok(())
}

struct Headers<'a>(&'a hyper::HeaderMap);
impl payjoin::receive::Headers for Headers<'_> {
fn get_header(&self, key: &str) -> Option<&str> {
self.0.get(key).map(|v| v.to_str()).transpose().ok().flatten()
}
}

#[cfg(feature = "danger-local-https")]
fn http_agent() -> Result<reqwest::Client> { Ok(http_agent_builder()?.build()?) }

Expand Down
9 changes: 8 additions & 1 deletion payjoin-cli/src/app/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ use tokio::net::TcpListener;

use super::config::AppConfig;
use super::App as AppTrait;
use crate::app::{http_agent, try_contributing_inputs, Headers};
use crate::app::{http_agent, try_contributing_inputs};
use crate::db::Database;
#[cfg(feature = "danger-local-https")]
pub const LOCAL_CERT_FILE: &str = "localhost.der";

struct Headers<'a>(&'a hyper::HeaderMap);
impl payjoin::receive::Headers for Headers<'_> {
fn get_header(&self, key: &str) -> Option<&str> {
self.0.get(key).map(|v| v.to_str()).transpose().ok().flatten()
}
}

#[derive(Clone)]
pub(crate) struct App {
config: AppConfig,
Expand Down
2 changes: 1 addition & 1 deletion payjoin-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use url::Url;
mod app;
mod db;

#[cfg(not(feature = "v2"))]
#[cfg(all(not(feature = "v2"), feature = "v1"))]
use app::v1::App;
#[cfg(feature = "v2")]
use app::v2::App;
Expand Down

0 comments on commit ca02d14

Please sign in to comment.