Skip to content

Commit

Permalink
Add feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
crodas committed Jan 10, 2025
1 parent 76755c5 commit e5f97f3
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 270 deletions.
5 changes: 4 additions & 1 deletion crates/cashu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ description = "Cashu shared types and crypto utilities, used as the foundation f
rust-version = "1.63.0" # MSRV

[features]
default = ["mint", "wallet"]
swagger = ["dep:utoipa"]
mint = ["dep:uuid"]
wallet = []
bench = []

[dependencies]
uuid = { version = "1", features = ["v4", "serde"], optional = true }
bitcoin = { version = "0.32.2", features = [
"base64",
"serde",
Expand All @@ -24,7 +28,6 @@ lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
thiserror = "2"
tracing = "0.1"
url = "2.3"
uuid = { version = "1", features = ["v4", "serde"] }
utoipa = { version = "4", optional = true }
serde_json = "1"
serde_with = "3"
Expand Down
3 changes: 3 additions & 0 deletions crates/cashu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
//!
pub mod amount;
pub mod dhke;
#[cfg(feature = "mint")]
pub mod mint;
pub mod mint_url;
pub mod nuts;
pub mod secret;
pub mod util;
#[cfg(feature = "wallet")]
pub mod wallet;

pub use lightning_invoice::{self, Bolt11Invoice};

Expand Down
4 changes: 3 additions & 1 deletion crates/cashu/src/nuts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub use nut00::{
Proofs, ProofsMethods, Token, TokenV3, TokenV4, Witness,
};
pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse, MintKeySet};
#[cfg(feature = "mint")]
pub use nut02::MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
pub use nut03::{PreSwap, SwapRequest, SwapResponse};
pub use nut04::{
MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
Expand Down
1 change: 1 addition & 0 deletions crates/cashu/src/nuts/nut00/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub enum CurrencyUnit {
Custom(String),
}

#[cfg(feature = "mint")]
impl CurrencyUnit {
/// Derivation index mint will use for unit
pub fn derivation_index(&self) -> Option<u32> {
Expand Down
4 changes: 4 additions & 0 deletions crates/cashu/src/nuts/nut04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[cfg(feature = "mint")]
use uuid::Uuid;

use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
Expand Down Expand Up @@ -115,6 +116,7 @@ impl<Q: ToString> MintQuoteBolt11Response<Q> {
}
}

#[cfg(feature = "mint")]
impl From<MintQuoteBolt11Response<Uuid>> for MintQuoteBolt11Response<String> {
fn from(value: MintQuoteBolt11Response<Uuid>) -> Self {
Self {
Expand All @@ -127,6 +129,7 @@ impl From<MintQuoteBolt11Response<Uuid>> for MintQuoteBolt11Response<String> {
}
}

#[cfg(feature = "mint")]
impl From<crate::mint::MintQuote> for MintQuoteBolt11Response<Uuid> {
fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt11Response<Uuid> {
MintQuoteBolt11Response {
Expand Down Expand Up @@ -155,6 +158,7 @@ pub struct MintBolt11Request<Q> {
pub signature: Option<String>,
}

#[cfg(feature = "mint")]
impl TryFrom<MintBolt11Request<String>> for MintBolt11Request<Uuid> {
type Error = uuid::Error;

Expand Down
6 changes: 6 additions & 0 deletions crates/cashu/src/nuts/nut05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use thiserror::Error;
#[cfg(feature = "mint")]
use uuid::Uuid;

use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
use super::nut15::Mpp;
#[cfg(feature = "mint")]
use crate::mint::{self, MeltQuote};
use crate::nuts::MeltQuoteState;
use crate::{Amount, Bolt11Invoice};
Expand Down Expand Up @@ -192,6 +194,7 @@ impl<Q: ToString> MeltQuoteBolt11Response<Q> {
}
}

#[cfg(feature = "mint")]
impl From<MeltQuoteBolt11Response<Uuid>> for MeltQuoteBolt11Response<String> {
fn from(value: MeltQuoteBolt11Response<Uuid>) -> Self {
Self {
Expand All @@ -207,6 +210,7 @@ impl From<MeltQuoteBolt11Response<Uuid>> for MeltQuoteBolt11Response<String> {
}
}

#[cfg(feature = "mint")]
impl From<&MeltQuote> for MeltQuoteBolt11Response<Uuid> {
fn from(melt_quote: &MeltQuote) -> MeltQuoteBolt11Response<Uuid> {
MeltQuoteBolt11Response {
Expand Down Expand Up @@ -306,6 +310,7 @@ impl<'de, Q: DeserializeOwned> Deserialize<'de> for MeltQuoteBolt11Response<Q> {
}
}

#[cfg(feature = "mint")]
impl From<mint::MeltQuote> for MeltQuoteBolt11Response<Uuid> {
fn from(melt_quote: mint::MeltQuote) -> MeltQuoteBolt11Response<Uuid> {
let paid = melt_quote.state == QuoteState::Paid;
Expand Down Expand Up @@ -337,6 +342,7 @@ pub struct MeltBolt11Request<Q> {
pub outputs: Option<Vec<BlindedMessage>>,
}

#[cfg(feature = "mint")]
impl TryFrom<MeltBolt11Request<String>> for MeltBolt11Request<Uuid> {
type Error = uuid::Error;

Expand Down
4 changes: 4 additions & 0 deletions crates/cashu/src/nuts/nut17/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Specific Subscription for the cdk crate
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
#[cfg(feature = "mint")]
use uuid::Uuid;

#[cfg(feature = "mint")]
use super::PublicKey;
use crate::nuts::{
CurrencyUnit, MeltQuoteBolt11Response, MintQuoteBolt11Response, PaymentMethod, ProofState,
Expand Down Expand Up @@ -97,6 +99,7 @@ impl<T> From<MintQuoteBolt11Response<T>> for NotificationPayload<T> {
}
}

#[cfg(feature = "mint")]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
/// A parsed notification
pub enum Notification {
Expand Down Expand Up @@ -129,6 +132,7 @@ impl<I> AsRef<I> for Params<I> {
/// Parsing error
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[cfg(feature = "mint")]
#[error("Uuid Error: {0}")]
/// Uuid Error
Uuid(#[from] uuid::Error),
Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions crates/cdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ description = "CDK common types and traits"
rust-version = "1.63.0" # MSRV

[features]
default = ["mint", "wallet"]
swagger = ["dep:utoipa", "cashu/swagger"]
bench = []
wallet = ["cashu/wallet"]
mint = ["cashu/mint", "dep:uuid"]

[dependencies]
async-trait = "0.1"
Expand All @@ -17,7 +20,7 @@ bitcoin = { version = "0.32.2", features = [
"rand",
"rand-std",
] }
cashu = { path = "../cashu", version = "0.6.0" }
cashu = { path = "../cashu", default-features = false, version = "0.6.0" }
cbor-diag = "0.1.12"
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
once_cell = "1.20.2"
Expand All @@ -26,7 +29,7 @@ lightning-invoice = { version = "0.32.0", features = ["serde", "std"] }
thiserror = "2"
tracing = "0.1"
url = "2.3"
uuid = { version = "1", features = ["v4", "serde"] }
uuid = { version = "1", features = ["v4", "serde"], optional = true }
utoipa = { version = "4", optional = true }
futures = "0.3.31"
anyhow = "1.0"
Expand Down
Loading

0 comments on commit e5f97f3

Please sign in to comment.