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
23 changes: 20 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"monero-rpc-pool",
"monero-sys",
"monero-tests",
"monero-wallet",
"src-tauri",
"swap",
"swap-asb",
Expand Down
6 changes: 3 additions & 3 deletions bitcoin-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ use tokio::sync::watch;
use tokio::sync::Mutex as TokioMutex;
use tracing::{debug_span, Instrument};

pub type TauriHandle = Option<Arc<Box<dyn BitcoinTauriHandle>>>;
pub type TauriHandle = Option<Arc<dyn BitcoinTauriHandle>>;
pub trait BitcoinTauriHandle: Send + Sync {
/// let progress_handle = tauri_handle.new_background_process_with_initial_progress(
/// TauriBackgroundProgress::FullScanningBitcoinWallet,
/// TauriBitcoinFullScanProgress::Unknown,
/// );
fn start_full_scan(&self) -> Arc<Box<dyn BitcoinTauriBackgroundTask>>;
fn start_full_scan(&self) -> Arc<dyn BitcoinTauriBackgroundTask>;

/// let background_process_handle = self
/// .tauri_handle
/// .new_background_process_with_initial_progress(
/// TauriBackgroundProgress::SyncingBitcoinWallet,
/// TauriBitcoinSyncProgress::Unknown,
/// );
fn start_sync(&self) -> Arc<Box<dyn BitcoinTauriBackgroundTask>>;
fn start_sync(&self) -> Arc<dyn BitcoinTauriBackgroundTask>;
}
pub trait BitcoinTauriBackgroundTask: Send + Sync {
/// progress_handle_clone.update(TauriBitcoinFullScanProgress::Known {
Expand Down
28 changes: 28 additions & 0 deletions monero-wallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "monero-wallet"
version = "0.1.0"
edition = "2021"

[dependencies]
# Error handling
anyhow = { workspace = true }

# Other stuff
monero = { workspace = true }
monero-sys = { path = "../monero-sys" }
swap-core = { path = "../swap-core" }
throttle = { path = "../throttle" }
time = "0.3"
uuid = { workspace = true }

# Tokio
tokio = { workspace = true, features = ["process", "fs", "net", "parking_lot", "rt"] }

# Tracing
tracing = { workspace = true }
tracing-appender = "0.2"
tracing-subscriber = { workspace = true }

# monero-oxide
monero-oxide-rpc = { git = "https://github.com/monero-oxide/monero-oxide.git", package = "monero-rpc" }
monero-simple-request-rpc = { git = "https://github.com/monero-oxide/monero-oxide.git" }
61 changes: 33 additions & 28 deletions swap/src/monero/wallet.rs → monero-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,31 @@ use throttle::{throttle, Throttle};
use tokio::sync::RwLock;
use uuid::Uuid;

use crate::cli::api::{
request::{GetMoneroBalanceResponse, GetMoneroHistoryResponse, GetMoneroSyncProgressResponse},
tauri_bindings::{MoneroWalletUpdate, TauriEmitter, TauriEvent, TauriHandle},
};

use super::{BlockHeight, TxHash, WatchRequest};
use swap_core::monero::primitives::{Amount, BlockHeight, PrivateViewKey, TxHash, WatchRequest};

pub type TauriHandle = Arc<dyn MoneroTauriHandle>;
pub trait MoneroTauriHandle: Send + Sync {
/// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
/// MoneroWalletUpdate::BalanceChange(GetMoneroBalanceResponse {
/// total_balance, unlocked_balance,
/// })
/// ));
fn balance_change(&self, total_balance: Amount, unlocked_balance: Amount);

/// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
/// MoneroWalletUpdate::HistoryUpdate(
/// GetMoneroHistoryResponse { transactions }
/// ),
/// ));
fn history_update(&self, transactions: Vec<monero_sys::TransactionInfo>);

/// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
/// MoneroWalletUpdate::SyncProgress(GetMoneroSyncProgressResponse {
/// current_block, target_block, progress_percentage,
/// }),
/// ));
fn sync_progress(&self, current_block: u64, target_block: u64, progress_percentage: f32);
}

/// Entrance point to the Monero blockchain.
/// You can use this struct to open specific wallets and monitor the blockchain.
Expand Down Expand Up @@ -84,13 +103,7 @@ impl TauriWalletListener {
}
};

let response = GetMoneroBalanceResponse {
total_balance: total_balance.into(),
unlocked_balance: unlocked_balance.into(),
};
tauri.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::BalanceChange(response),
));
tauri.balance_change(total_balance.into(), unlocked_balance.into());
});
}
};
Expand All @@ -111,11 +124,8 @@ impl TauriWalletListener {
return;
}
};
let response = GetMoneroHistoryResponse { transactions };

tauri.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::HistoryUpdate(response),
));
tauri.history_update(transactions);
});
}
};
Expand All @@ -138,16 +148,11 @@ impl TauriWalletListener {
};

let progress_percentage = sync_progress.percentage();

let response = GetMoneroSyncProgressResponse {
current_block: sync_progress.current_block,
target_block: sync_progress.target_block,
progress_percentage: progress_percentage,
};

tauri.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::SyncProgress(response),
));
tauri.sync_progress(
sync_progress.current_block,
sync_progress.target_block,
progress_percentage,
);
});
}
};
Expand Down Expand Up @@ -367,7 +372,7 @@ impl Wallets {
&self,
swap_id: Uuid,
spend_key: monero::PrivateKey,
view_key: super::PrivateViewKey,
view_key: PrivateViewKey,
tx_lock_id: TxHash,
) -> Result<Arc<Wallet>> {
// Derive wallet address from the keys
Expand Down
8 changes: 2 additions & 6 deletions swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ bdk = { workspace = true }
bdk_wallet = { workspace = true }
bitcoin = { workspace = true }

# Bitcoin Wallet
# Wallets
bitcoin-wallet = { path = "../bitcoin-wallet" }
monero-wallet = { path = "../monero-wallet" }

# Tor
arti-client = { workspace = true, features = ["static-sqlite", "tokio", "rustls", "onion-service-service"] }
Expand Down Expand Up @@ -70,7 +71,6 @@ swap-p2p = { path = "../swap-p2p" }
swap-proptest = { path = "../swap-proptest" }
swap-serde = { path = "../swap-serde" }
tauri = { version = "2.0", features = ["config-json5"], optional = true, default-features = false }
throttle = { path = "../throttle" }
time = "0.3"
url = { workspace = true }
uuid = { workspace = true, features = ["serde"] }
Expand All @@ -96,10 +96,6 @@ serde_with = { version = "1", features = ["macros"] }
strum = { workspace = true, features = ["derive"] }
typeshare = { workspace = true }

# monero-oxide
monero-oxide-rpc = { git = "https://github.com/monero-oxide/monero-oxide.git", package = "monero-rpc" }
monero-simple-request-rpc = { git = "https://github.com/monero-oxide/monero-oxide.git" }

# Database
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio-rustls"] }

Expand Down
2 changes: 1 addition & 1 deletion swap/src/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ mod builder {
daemon.clone(),
env_config.monero_network,
false,
self.tauri_handle.clone(),
self.tauri_handle.clone().map(|th| th.into()),
wallet,
wallet_database,
)
Expand Down
57 changes: 44 additions & 13 deletions swap/src/cli/api/tauri_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,26 +454,22 @@ struct BitcoinTauriHandle(TauriHandle);

impl Into<bitcoin_wallet::TauriHandle> for TauriHandle {
fn into(self) -> bitcoin_wallet::TauriHandle {
Some(Arc::new(Box::new(BitcoinTauriHandle(self))))
Some(Arc::new(BitcoinTauriHandle(self)))
}
}

impl bitcoin_wallet::BitcoinTauriHandle for BitcoinTauriHandle {
fn start_full_scan(&self) -> Arc<Box<dyn bitcoin_wallet::BitcoinTauriBackgroundTask>> {
Arc::new(Box::new(
self.0.new_background_process_with_initial_progress(
TauriBackgroundProgress::FullScanningBitcoinWallet,
TauriBitcoinFullScanProgress::Unknown,
),
fn start_full_scan(&self) -> Arc<dyn bitcoin_wallet::BitcoinTauriBackgroundTask> {
Arc::new(self.0.new_background_process_with_initial_progress(
TauriBackgroundProgress::FullScanningBitcoinWallet,
TauriBitcoinFullScanProgress::Unknown,
))
}

fn start_sync(&self) -> Arc<Box<dyn bitcoin_wallet::BitcoinTauriBackgroundTask>> {
Arc::new(Box::new(
self.0.new_background_process_with_initial_progress(
TauriBackgroundProgress::SyncingBitcoinWallet,
TauriBitcoinSyncProgress::Unknown,
),
fn start_sync(&self) -> Arc<dyn bitcoin_wallet::BitcoinTauriBackgroundTask> {
Arc::new(self.0.new_background_process_with_initial_progress(
TauriBackgroundProgress::SyncingBitcoinWallet,
TauriBitcoinSyncProgress::Unknown,
))
}
}
Expand Down Expand Up @@ -505,6 +501,41 @@ impl bitcoin_wallet::BitcoinTauriBackgroundTask
}
}

struct MoneroTauriHandle(TauriHandle);

impl Into<monero_wallet::TauriHandle> for TauriHandle {
fn into(self) -> monero_wallet::TauriHandle {
Arc::new(MoneroTauriHandle(self))
}
}

impl monero_wallet::MoneroTauriHandle for MoneroTauriHandle {
fn balance_change(&self, total_balance: monero::Amount, unlocked_balance: monero::Amount) {
self.0.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::BalanceChange(GetMoneroBalanceResponse {
total_balance,
unlocked_balance,
}),
))
}

fn history_update(&self, transactions: Vec<monero_sys::TransactionInfo>) {
self.0.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::HistoryUpdate(GetMoneroHistoryResponse { transactions }),
))
}

fn sync_progress(&self, current_block: u64, target_block: u64, progress_percentage: f32) {
self.0.emit_unified_event(TauriEvent::MoneroWalletUpdate(
MoneroWalletUpdate::SyncProgress(GetMoneroSyncProgressResponse {
current_block,
target_block,
progress_percentage,
}),
))
}
}

impl Display for ApprovalRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.request {
Expand Down
1 change: 1 addition & 0 deletions swap/src/common/tracing_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ mod crates {
pub const OUR_CRATES: &[&str] = &[
// Library crates
"bitcoin_wallet",
"monero_wallet",
"swap_p2p",
"swap_env",
"swap_core",
Expand Down
2 changes: 1 addition & 1 deletion swap/src/monero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod wallet;
pub use monero_wallet as wallet;
pub mod wallet_rpc;

pub use ::monero::network::Network;
Expand Down
Loading