refactor(workspace): extract logic into electrum-pool crate (#433)

* feat(workspace): add electrum-pool crate

* use patched monero crate, remove changelog entry for refactor

* fix deps

* fix
This commit is contained in:
Mohan 2025-06-23 15:53:43 +02:00 committed by GitHub
parent 1d300ddcbc
commit ec053404f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 347 additions and 1563 deletions

1868
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["monero-rpc", "monero-rpc-pool", "monero-sys", "src-tauri", "swap"]
members = ["monero-rpc", "monero-rpc-pool", "monero-sys", "src-tauri", "swap", "electrum-pool"]
[profile.release]
opt-level = 0
@ -8,6 +8,7 @@ opt-level = 0
[patch.crates-io]
# patch until new release https://github.com/thomaseizinger/rust-jsonrpc-client/pull/51
jsonrpc_client = { git = "https://github.com/delta1/rust-jsonrpc-client.git", rev = "3b6081697cd616c952acb9c2f02d546357d35506" }
monero = { git = "https://github.com/comit-network/monero-rs", rev = "818f38b" }
# patch until new release https://github.com/bitcoindevkit/bdk/pull/1766
bdk_wallet = { git = "https://github.com/Einliterflasche/bdk", branch = "bump/rusqlite-0.32", package = "bdk_wallet" }

17
electrum-pool/Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "electrum-pool"
version = "0.1.0"
edition = "2021"
authors = ["UnstoppableSwap Team <help@unstoppableswap.net>"]
[dependencies]
backoff = { version = "0.4", features = ["tokio"] }
bdk_electrum = { version = "0.19", default-features = false, features = ["use-rustls-ring"] }
bitcoin = { version = "0.32", features = ["rand", "serde"] }
futures = { version = "0.3", default-features = false, features = ["std"] }
once_cell = "1.19"
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync"] }
tracing = { version = "0.1", features = ["attributes"] }
[dev-dependencies]
serde_json = "1"

View file

@ -197,7 +197,7 @@ where
&self,
kind: &str,
f: F,
) -> Result<T, crate::bitcoin::electrum_balancer::MultiError>
) -> Result<T, MultiError>
where
F: Fn(&C) -> Result<T, Error> + Send + Sync + Clone + 'static,
T: Send + 'static,

View file

@ -4,9 +4,9 @@
"version": "0.7.0",
"type": "module",
"scripts": {
"check-bindings": "typeshare --lang=typescript --output-file __temp_bindings.ts ../swap/src ../monero-rpc-pool/src && dprint fmt __temp_bindings.ts && diff -wbB __temp_bindings.ts ./src/models/tauriModel.ts && rm __temp_bindings.ts",
"gen-bindings-verbose": "RUST_LOG=debug RUST_BACKTRACE=1 typeshare --lang=typescript --output-file ./src/models/tauriModel.ts ../swap/src ../monero-rpc-pool/src && dprint fmt ./src/models/tauriModel.ts",
"gen-bindings": "typeshare --lang=typescript --output-file ./src/models/tauriModel.ts ../swap/src ../monero-rpc-pool/src && dprint fmt ./src/models/tauriModel.ts",
"check-bindings": "typeshare --lang=typescript --output-file __temp_bindings.ts ../swap/src ../monero-rpc-pool/src ../electrum-pool/src && dprint fmt __temp_bindings.ts && diff -wbB __temp_bindings.ts ./src/models/tauriModel.ts && rm __temp_bindings.ts",
"gen-bindings-verbose": "RUST_LOG=debug RUST_BACKTRACE=1 typeshare --lang=typescript --output-file ./src/models/tauriModel.ts ../swap/src ../monero-rpc-pool/src ../electrum-pool/src && dprint fmt ./src/models/tauriModel.ts",
"gen-bindings": "typeshare --lang=typescript --output-file ./src/models/tauriModel.ts ../swap/src ../monero-rpc-pool/src ../electrum-pool/src && dprint fmt ./src/models/tauriModel.ts",
"test": "vitest",
"test:ui": "vitest --ui",
"dev": "vite",

View file

@ -13,7 +13,7 @@ tauri = ["dep:tauri"]
[dependencies]
anyhow = "1"
arti-client = { version = "0.25.0", features = ["static-sqlite", "tokio", "rustls"], default-features = false }
arti-client = { version = "0.25.0", features = ["static-sqlite", "tokio", "rustls", "onion-service-service"], default-features = false }
async-compression = { version = "0.3", features = ["bzip2", "tokio"] }
async-trait = "0.1"
asynchronous-codec = "0.7.0"
@ -40,12 +40,13 @@ ed25519-dalek = "1"
futures = { version = "0.3", default-features = false, features = ["std"] }
hex = "0.4"
libp2p = { version = "0.53.2", features = ["tcp", "yamux", "dns", "noise", "request-response", "ping", "rendezvous", "identify", "macros", "cbor", "json", "tokio", "serde", "rsa"] }
libp2p-community-tor = { git = "https://github.com/umgefahren/libp2p-tor", branch = "main", features = ["listen-onion-service"] }
libp2p-community-tor = { git = "https://github.com/umgefahren/libp2p-tor", rev = "e6b913e0f1ac1fc90b3ee4dd31b5511140c4a9af", features = ["listen-onion-service"] }
moka = { version = "0.12", features = ["sync", "future"] }
monero = { version = "0.21" }
monero = { version = "0.12", features = ["serde_support"] }
monero-rpc = { path = "../monero-rpc" }
monero-rpc-pool = { path = "../monero-rpc-pool" }
monero-sys = { path = "../monero-sys" }
electrum-pool = { path = "../electrum-pool" }
once_cell = "1.19"
pem = "3.0"
proptest = "1"

View file

@ -1,4 +1,3 @@
pub mod electrum_balancer;
pub mod wallet;
mod cancel;
@ -458,7 +457,7 @@ impl From<RpcErrorCode> for i64 {
pub fn parse_rpc_error_code(error: &anyhow::Error) -> anyhow::Result<i64> {
// First try to extract an Electrum error from a MultiError if present
if let Some(multi_error) = error.downcast_ref::<crate::bitcoin::electrum_balancer::MultiError>()
if let Some(multi_error) = error.downcast_ref::<electrum_pool::MultiError>()
{
// Try to find the first Electrum error in the MultiError
for single_error in multi_error.iter() {

View file

@ -41,7 +41,7 @@ use tracing::{debug_span, Instrument};
use super::bitcoin_address::revalidate_network;
use super::BlockHeight;
use crate::bitcoin::electrum_balancer::ElectrumBalancer;
use electrum_pool::ElectrumBalancer;
use derive_builder::Builder;
use moka;
@ -754,7 +754,7 @@ impl Wallet {
kind, txid, total_count
);
let multi_error = crate::bitcoin::electrum_balancer::MultiError::new(errors, context);
let multi_error = electrum_pool::MultiError::new(errors, context);
return Err(anyhow::Error::from(multi_error));
}