mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-25 06:39:53 -04:00
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:
parent
1d300ddcbc
commit
ec053404f7
8 changed files with 347 additions and 1563 deletions
1868
Cargo.lock
generated
1868
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
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]
|
[profile.release]
|
||||||
opt-level = 0
|
opt-level = 0
|
||||||
|
@ -8,6 +8,7 @@ opt-level = 0
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
# patch until new release https://github.com/thomaseizinger/rust-jsonrpc-client/pull/51
|
# 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" }
|
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
|
# 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" }
|
bdk_wallet = { git = "https://github.com/Einliterflasche/bdk", branch = "bump/rusqlite-0.32", package = "bdk_wallet" }
|
||||||
|
|
17
electrum-pool/Cargo.toml
Normal file
17
electrum-pool/Cargo.toml
Normal 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"
|
|
@ -197,7 +197,7 @@ where
|
||||||
&self,
|
&self,
|
||||||
kind: &str,
|
kind: &str,
|
||||||
f: F,
|
f: F,
|
||||||
) -> Result<T, crate::bitcoin::electrum_balancer::MultiError>
|
) -> Result<T, MultiError>
|
||||||
where
|
where
|
||||||
F: Fn(&C) -> Result<T, Error> + Send + Sync + Clone + 'static,
|
F: Fn(&C) -> Result<T, Error> + Send + Sync + Clone + 'static,
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
|
@ -4,9 +4,9 @@
|
||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"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",
|
"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 && dprint fmt ./src/models/tauriModel.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 && 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": "vitest",
|
||||||
"test:ui": "vitest --ui",
|
"test:ui": "vitest --ui",
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|
|
@ -13,7 +13,7 @@ tauri = ["dep:tauri"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
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-compression = { version = "0.3", features = ["bzip2", "tokio"] }
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
asynchronous-codec = "0.7.0"
|
asynchronous-codec = "0.7.0"
|
||||||
|
@ -40,12 +40,13 @@ ed25519-dalek = "1"
|
||||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||||
hex = "0.4"
|
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 = { 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"] }
|
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 = { path = "../monero-rpc" }
|
||||||
monero-rpc-pool = { path = "../monero-rpc-pool" }
|
monero-rpc-pool = { path = "../monero-rpc-pool" }
|
||||||
monero-sys = { path = "../monero-sys" }
|
monero-sys = { path = "../monero-sys" }
|
||||||
|
electrum-pool = { path = "../electrum-pool" }
|
||||||
once_cell = "1.19"
|
once_cell = "1.19"
|
||||||
pem = "3.0"
|
pem = "3.0"
|
||||||
proptest = "1"
|
proptest = "1"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod electrum_balancer;
|
|
||||||
pub mod wallet;
|
pub mod wallet;
|
||||||
|
|
||||||
mod cancel;
|
mod cancel;
|
||||||
|
@ -458,7 +457,7 @@ impl From<RpcErrorCode> for i64 {
|
||||||
|
|
||||||
pub fn parse_rpc_error_code(error: &anyhow::Error) -> anyhow::Result<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
|
// 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
|
// Try to find the first Electrum error in the MultiError
|
||||||
for single_error in multi_error.iter() {
|
for single_error in multi_error.iter() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ use tracing::{debug_span, Instrument};
|
||||||
|
|
||||||
use super::bitcoin_address::revalidate_network;
|
use super::bitcoin_address::revalidate_network;
|
||||||
use super::BlockHeight;
|
use super::BlockHeight;
|
||||||
use crate::bitcoin::electrum_balancer::ElectrumBalancer;
|
use electrum_pool::ElectrumBalancer;
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use moka;
|
use moka;
|
||||||
|
|
||||||
|
@ -754,7 +754,7 @@ impl Wallet {
|
||||||
kind, txid, total_count
|
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));
|
return Err(anyhow::Error::from(multi_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue