Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions orange-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.1.0"
edition = "2024"

[features]
_test-utils = ["corepc-node"]
default = ["spark"]
spark = ["spark-wallet", "uuid"]
cashu = ["cdk", "serde_json"]
_test-utils = ["corepc-node", "cashu", "uuid/v7"]

[dependencies]
graduated-rebalancer = { path = "../graduated-rebalancer", version = "0.1.0" }
Expand All @@ -14,8 +17,11 @@ bitcoin-payment-instructions = { version = "0.4.0", features = ["http"] }
chrono = { version = "0.4", default-features = false }
rand = "0.8.5"
reqwest = { version = "0.12.23", default-features = false, features = ["rustls-tls"] }
spark-wallet = { path = "../../rust-spark/crates/spark-wallet" }
spark-wallet = { path = "../../rust-spark/crates/spark-wallet", optional = true }
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "sync"] }
uuid = { version = "1.0", default-features = false }
uuid = { version = "1.0", default-features = false, optional = true }
cdk = { version = "0.12.0", default-features = false, features = ["wallet"], optional = true }
serde_json = { version = "1.0", optional = true }
async-trait = "0.1"

corepc-node = { version = "0.8.0", features = ["29_0", "download"], optional = true }
13 changes: 5 additions & 8 deletions orange-sdk/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Builder for constructing [`Wallet`] instances with a fluent API.

#[cfg(feature = "spark")]
use crate::trusted_wallet::TrustedError;
use crate::{
ChainSource, ExtraConfig, InitFailure, Seed, StorageConfig, Tunables, Wallet, WalletConfig,
Expand All @@ -8,7 +9,6 @@ use crate::{
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::{Network, io};
use ldk_node::lightning::ln::msgs::SocketAddress;
use spark_wallet::SparkWalletConfig;
use std::fmt;
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -264,11 +264,7 @@ impl WalletBuilder {
},
};

match &config.extra_config {
ExtraConfig::Spark(_) => Wallet::new(runtime, config).await,
#[cfg(feature = "_test-utils")]
ExtraConfig::Dummy(_) => Wallet::new(runtime, config).await,
}
Wallet::new(runtime, config).await
}

/// Builds and initializes the wallet with the configured parameters for Spark wallet.
Expand All @@ -289,14 +285,15 @@ impl WalletBuilder {
/// - Network connection fails
/// - Trusted wallet initialization fails
/// - LDK node fails to start
#[cfg(feature = "spark")]
pub async fn build_spark(
self, spark_config: Option<SparkWalletConfig>,
self, spark_config: Option<spark_wallet::SparkWalletConfig>,
) -> Result<Wallet, InitFailure> {
let spark_config = match spark_config {
Some(cfg) => cfg,
None => {
let network = self.network.ok_or(BuilderError::MissingNetwork)?;
SparkWalletConfig::default_config(
spark_wallet::SparkWalletConfig::default_config(
network
.try_into()
.map_err(|_| InitFailure::TrustedFailure(TrustedError::InvalidNetwork))?,
Expand Down
25 changes: 23 additions & 2 deletions orange-sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(missing_docs)]
#![deny(missing_docs)]

//! A library implementing the full backend for a modern, highly usable, Bitcoin wallet focusing on
//! maximizing security and self-custody without trading off user experience.
Expand All @@ -21,8 +21,11 @@ use bitcoin_payment_instructions::amount::Amount;

use crate::rebalancer::{OrangeRebalanceEventHandler, OrangeTrigger};
use crate::store::{PaymentId, TxMetadata, TxMetadataStore, TxType};
#[cfg(feature = "cashu")]
use crate::trusted_wallet::cashu::Cashu;
#[cfg(feature = "_test-utils")]
use crate::trusted_wallet::dummy::DummyTrustedWallet;
#[cfg(feature = "spark")]
use crate::trusted_wallet::spark::Spark;
use crate::trusted_wallet::{DynTrustedWalletInterface, WalletTrusted};
use graduated_rebalancer::GraduatedRebalancer;
Expand Down Expand Up @@ -59,12 +62,17 @@ use lightning_wallet::LightningWallet;
use logging::Logger;
use trusted_wallet::TrustedError;

#[cfg(feature = "cashu")]
pub use crate::trusted_wallet::cashu::CashuConfig;
pub use bitcoin_payment_instructions;
pub use builder::{BuilderError, WalletBuilder};
#[cfg(feature = "cashu")]
pub use cdk::nuts::nut00::CurrencyUnit;
pub use event::{Event, EventQueue};
pub use ldk_node::bip39::Mnemonic;
pub use ldk_node::bitcoin;
pub use ldk_node::payment::ConfirmationStatus;
#[cfg(feature = "spark")]
pub use spark_wallet::{OperatorPoolConfig, ServiceProviderConfig, SparkWalletConfig};
pub use store::{PaymentType, Transaction, TxStatus};
pub use trusted_wallet::ExtraConfig;
Expand Down Expand Up @@ -495,9 +503,22 @@ impl Wallet {
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));

let trusted: Arc<Box<DynTrustedWalletInterface>> = match &config.extra_config {
ExtraConfig::Spark(_) => Arc::new(Box::new(
#[cfg(feature = "spark")]
ExtraConfig::Spark(sp) => Arc::new(Box::new(
Spark::init(
&config,
sp.clone(),
Arc::clone(&store),
Arc::clone(&event_queue),
Arc::clone(&logger),
)
.await?,
)),
#[cfg(feature = "cashu")]
ExtraConfig::Cashu(cashu) => Arc::new(Box::new(
Cashu::init(
&config,
cashu.clone(),
Arc::clone(&store),
Arc::clone(&event_queue),
Arc::clone(&logger),
Expand Down
1 change: 1 addition & 0 deletions orange-sdk/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub struct Transaction {
/// A [Transaction] that is stored in the database. We have to modify the `Transaction` type
/// to have types that all implement `Writeable` and `Readable` so that we can store it in the database.
#[derive(Debug, Clone)]
#[allow(dead_code)] // Some trusted backends don't use this
pub(crate) struct StoreTransaction {
pub status: TxStatus,
pub outbound: bool,
Expand Down
Loading
Loading