mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-05 21:01:07 -05:00
add broadcast channel to handle shutdowns gracefully and prepare for RPC server test
This commit is contained in:
parent
aeeffccda2
commit
cf5efa8ad0
143
Cargo.lock
generated
143
Cargo.lock
generated
@ -1658,9 +1658,12 @@ checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"http",
|
"http",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
"log",
|
||||||
"rustls 0.20.2",
|
"rustls 0.20.2",
|
||||||
|
"rustls-native-certs 0.6.2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls 0.23.1",
|
"tokio-rustls 0.23.1",
|
||||||
|
"webpki-roots 0.22.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1810,14 +1813,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee"
|
name = "jsonrpsee"
|
||||||
version = "0.15.1"
|
version = "0.16.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8bd0d559d5e679b1ab2f869b486a11182923863b1b3ee8b421763cdd707b783a"
|
checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jsonrpsee-core",
|
"jsonrpsee-core 0.16.2",
|
||||||
"jsonrpsee-http-server",
|
"jsonrpsee-server",
|
||||||
"jsonrpsee-types",
|
"jsonrpsee-types 0.16.2",
|
||||||
"jsonrpsee-ws-server",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1825,6 +1827,25 @@ name = "jsonrpsee-core"
|
|||||||
version = "0.15.1"
|
version = "0.15.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3dc3e9cf2ba50b7b1d7d76a667619f82846caa39e8e8daa8a4962d74acaddca"
|
checksum = "f3dc3e9cf2ba50b7b1d7d76a667619f82846caa39e8e8daa8a4962d74acaddca"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
|
"beef",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-util",
|
||||||
|
"hyper",
|
||||||
|
"jsonrpsee-types 0.15.1",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jsonrpsee-core"
|
||||||
|
version = "0.16.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"arrayvec 0.7.2",
|
"arrayvec 0.7.2",
|
||||||
@ -1833,10 +1854,8 @@ dependencies = [
|
|||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"globset",
|
"globset",
|
||||||
"http",
|
|
||||||
"hyper",
|
"hyper",
|
||||||
"jsonrpsee-types",
|
"jsonrpsee-types 0.16.2",
|
||||||
"lazy_static",
|
|
||||||
"parking_lot 0.12.0",
|
"parking_lot 0.12.0",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
@ -1846,27 +1865,50 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"unicase",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-http-server"
|
name = "jsonrpsee-http-client"
|
||||||
version = "0.15.1"
|
version = "0.15.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "03802f0373a38c2420c70b5144742d800b509e2937edc4afb116434f07120117"
|
checksum = "52f7c0e2333ab2115c302eeb4f137c8a4af5ab609762df68bbda8f06496677c9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel",
|
"async-trait",
|
||||||
"futures-util",
|
|
||||||
"hyper",
|
"hyper",
|
||||||
"jsonrpsee-core",
|
"hyper-rustls",
|
||||||
"jsonrpsee-types",
|
"jsonrpsee-core 0.15.1",
|
||||||
|
"jsonrpsee-types 0.15.1",
|
||||||
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jsonrpsee-server"
|
||||||
|
version = "0.16.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fb69dad85df79527c019659a992498d03f8495390496da2f07e6c24c2b356fc"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"hyper",
|
||||||
|
"jsonrpsee-core 0.16.2",
|
||||||
|
"jsonrpsee-types 0.16.2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"soketto",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"tokio-util 0.7.3",
|
||||||
|
"tower",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-types"
|
name = "jsonrpsee-types"
|
||||||
version = "0.15.1"
|
version = "0.15.1"
|
||||||
@ -1882,23 +1924,17 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-ws-server"
|
name = "jsonrpsee-types"
|
||||||
version = "0.15.1"
|
version = "0.16.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d488ba74fb369e5ab68926feb75a483458b88e768d44319f37e4ecad283c7325"
|
checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel",
|
"anyhow",
|
||||||
"futures-util",
|
"beef",
|
||||||
"http",
|
"serde",
|
||||||
"jsonrpsee-core",
|
|
||||||
"jsonrpsee-types",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"soketto",
|
"thiserror",
|
||||||
"tokio",
|
|
||||||
"tokio-stream",
|
|
||||||
"tokio-util 0.7.3",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-futures",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2277,9 +2313,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.14"
|
version = "0.4.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
]
|
]
|
||||||
@ -3464,6 +3500,18 @@ dependencies = [
|
|||||||
"security-framework",
|
"security-framework",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-native-certs"
|
||||||
|
version = "0.6.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50"
|
||||||
|
dependencies = [
|
||||||
|
"openssl-probe",
|
||||||
|
"rustls-pemfile",
|
||||||
|
"schannel",
|
||||||
|
"security-framework",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-pemfile"
|
name = "rustls-pemfile"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@ -3908,6 +3956,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures",
|
"futures",
|
||||||
|
"http",
|
||||||
"httparse",
|
"httparse",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
@ -4161,7 +4210,8 @@ dependencies = [
|
|||||||
"hyper",
|
"hyper",
|
||||||
"itertools",
|
"itertools",
|
||||||
"jsonrpsee",
|
"jsonrpsee",
|
||||||
"jsonrpsee-core",
|
"jsonrpsee-core 0.16.2",
|
||||||
|
"jsonrpsee-http-client",
|
||||||
"libp2p",
|
"libp2p",
|
||||||
"monero",
|
"monero",
|
||||||
"monero-harness",
|
"monero-harness",
|
||||||
@ -4550,6 +4600,23 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
||||||
|
dependencies = [
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-layer"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@ -4563,6 +4630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
|
"log",
|
||||||
"pin-project-lite 0.2.9",
|
"pin-project-lite 0.2.9",
|
||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
@ -4737,7 +4805,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"rand 0.8.3",
|
"rand 0.8.3",
|
||||||
"rustls 0.19.0",
|
"rustls 0.19.0",
|
||||||
"rustls-native-certs",
|
"rustls-native-certs 0.5.0",
|
||||||
"sha-1",
|
"sha-1",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"url",
|
"url",
|
||||||
@ -4769,15 +4837,6 @@ dependencies = [
|
|||||||
"static_assertions",
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicase"
|
|
||||||
version = "2.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
|
||||||
dependencies = [
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
@ -31,8 +31,8 @@ ed25519-dalek = "1"
|
|||||||
futures = { version = "0.3", default-features = false }
|
futures = { version = "0.3", default-features = false }
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
jsonrpsee = { version = "0.15.1", features = [ "server" ] }
|
jsonrpsee = { version = "0.16.2", features = [ "server" ] }
|
||||||
jsonrpsee-core = "0.15.1"
|
jsonrpsee-core = "0.16.2"
|
||||||
libp2p = { version = "0.42.2", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
|
libp2p = { version = "0.42.2", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
|
||||||
monero = { version = "0.12", features = [ "serde_support" ] }
|
monero = { version = "0.12", features = [ "serde_support" ] }
|
||||||
monero-rpc = { path = "../monero-rpc" }
|
monero-rpc = { path = "../monero-rpc" }
|
||||||
@ -81,6 +81,7 @@ get-port = "3"
|
|||||||
hyper = "0.14"
|
hyper = "0.14"
|
||||||
monero-harness = { path = "../monero-harness" }
|
monero-harness = { path = "../monero-harness" }
|
||||||
port_check = "0.1"
|
port_check = "0.1"
|
||||||
|
jsonrpsee-http-client = "0.15.1"
|
||||||
proptest = "1"
|
proptest = "1"
|
||||||
serde_cbor = "0.11"
|
serde_cbor = "0.11"
|
||||||
spectral = "0.6"
|
spectral = "0.6"
|
||||||
|
@ -11,9 +11,10 @@ use anyhow::{Context as AnyContext, Result};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
static START: Once = Once::new();
|
static START: Once = Once::new();
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ pub struct Context {
|
|||||||
monero_wallet: Option<Arc<monero::Wallet>>,
|
monero_wallet: Option<Arc<monero::Wallet>>,
|
||||||
monero_rpc_process: Option<monero::WalletRpcProcess>,
|
monero_rpc_process: Option<monero::WalletRpcProcess>,
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
|
pub shutdown: Arc<broadcast::Sender<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +50,7 @@ impl Context {
|
|||||||
debug: bool,
|
debug: bool,
|
||||||
json: bool,
|
json: bool,
|
||||||
server_address: Option<SocketAddr>,
|
server_address: Option<SocketAddr>,
|
||||||
|
shutdown: broadcast::Sender<()>,
|
||||||
) -> Result<Context> {
|
) -> Result<Context> {
|
||||||
let data_dir = data::data_dir_from(data, is_testnet)?;
|
let data_dir = data::data_dir_from(data, is_testnet)?;
|
||||||
let env_config = env_config_from(is_testnet);
|
let env_config = env_config_from(is_testnet);
|
||||||
@ -113,6 +116,7 @@ impl Context {
|
|||||||
json,
|
json,
|
||||||
is_testnet,
|
is_testnet,
|
||||||
},
|
},
|
||||||
|
shutdown: Arc::new(shutdown),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(init)
|
Ok(init)
|
||||||
@ -126,6 +130,7 @@ impl fmt::Debug for Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn init_bitcoin_wallet(
|
async fn init_bitcoin_wallet(
|
||||||
electrum_rpc_url: Url,
|
electrum_rpc_url: Url,
|
||||||
seed: &Seed,
|
seed: &Seed,
|
||||||
@ -207,6 +212,10 @@ pub mod api_test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::tor::DEFAULT_SOCKS5_PORT;
|
use crate::tor::DEFAULT_SOCKS5_PORT;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use uuid::Uuid;
|
||||||
|
use crate::api::request::{Request, Params, Method, Shutdown};
|
||||||
|
use libp2p::Multiaddr;
|
||||||
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
pub const MULTI_ADDRESS: &str =
|
pub const MULTI_ADDRESS: &str =
|
||||||
"/ip4/127.0.0.1/tcp/9939/p2p/12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi";
|
"/ip4/127.0.0.1/tcp/9939/p2p/12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi";
|
||||||
@ -236,13 +245,13 @@ pub mod api_test {
|
|||||||
seed: Some(seed),
|
seed: Some(seed),
|
||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
is_testnet
|
is_testnet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
impl Request {
|
impl Request {
|
||||||
pub fn buy_xmr(is_testnet: bool) -> Request {
|
pub fn buy_xmr(is_testnet: bool, tx: broadcast::Sender<()>) -> Request {
|
||||||
let seller = Multiaddr::from_str(MULTI_ADDRESS).unwrap();
|
let seller = Multiaddr::from_str(MULTI_ADDRESS).unwrap();
|
||||||
let bitcoin_change_address = {
|
let bitcoin_change_address = {
|
||||||
if is_testnet {
|
if is_testnet {
|
||||||
@ -268,36 +277,40 @@ pub mod api_test {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::BuyXmr,
|
cmd: Method::BuyXmr,
|
||||||
|
shutdown: Shutdown::new(tx.subscribe()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resume() -> Request {
|
pub fn resume(tx: broadcast::Sender<()>) -> Request {
|
||||||
Request {
|
Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::Resume,
|
cmd: Method::Resume,
|
||||||
|
shutdown: Shutdown::new(tx.subscribe()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel() -> Request {
|
pub fn cancel(tx: broadcast::Sender<()>) -> Request {
|
||||||
Request {
|
Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::Cancel,
|
cmd: Method::Cancel,
|
||||||
|
shutdown: Shutdown::new(tx.subscribe()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refund() -> Request {
|
pub fn refund(tx: broadcast::Sender<()>) -> Request {
|
||||||
Request {
|
Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::Refund,
|
cmd: Method::Refund,
|
||||||
|
shutdown: Shutdown::new(tx.subscribe()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,56 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use crate::api::Context;
|
use crate::api::Context;
|
||||||
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub params: Params,
|
pub params: Params,
|
||||||
pub cmd: Method,
|
pub cmd: Method,
|
||||||
|
pub shutdown: Shutdown,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Shutdown {
|
||||||
|
pub fn new(notify: broadcast::Receiver<()>) -> Shutdown {
|
||||||
|
Shutdown {
|
||||||
|
shutdown: false,
|
||||||
|
notify,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the shutdown signal has been received.
|
||||||
|
pub fn is_shutdown(&self) -> bool {
|
||||||
|
self.shutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Receive the shutdown notice, waiting if necessary.
|
||||||
|
pub async fn recv(&mut self) {
|
||||||
|
// If the shutdown signal has already been received, then return
|
||||||
|
// immediately.
|
||||||
|
if self.shutdown {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cannot receive a "lag error" as only one value is ever sent.
|
||||||
|
let _ = self.notify.recv().await;
|
||||||
|
|
||||||
|
self.shutdown = true;
|
||||||
|
|
||||||
|
// Remember that the signal has been received.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Shutdown {
|
||||||
|
shutdown: bool,
|
||||||
|
notify: broadcast::Receiver<()>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Shutdown {
|
||||||
|
fn eq(&self, other: &Shutdown) -> bool {
|
||||||
|
self.shutdown == other.shutdown
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Debug)]
|
#[derive(Default, PartialEq, Debug)]
|
||||||
@ -37,6 +81,7 @@ pub struct Params {
|
|||||||
pub address: Option<bitcoin::Address>,
|
pub address: Option<bitcoin::Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Method {
|
pub enum Method {
|
||||||
BuyXmr,
|
BuyXmr,
|
||||||
@ -57,7 +102,7 @@ pub enum Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
pub async fn call(&self, context: Arc<Context>) -> Result<serde_json::Value> {
|
pub async fn call(&mut self, context: Arc<Context>) -> Result<serde_json::Value> {
|
||||||
let result = match self.cmd {
|
let result = match self.cmd {
|
||||||
Method::BuyXmr => {
|
Method::BuyXmr => {
|
||||||
let swap_id = Uuid::new_v4();
|
let swap_id = Uuid::new_v4();
|
||||||
@ -247,19 +292,18 @@ impl Request {
|
|||||||
Method::StartDaemon => {
|
Method::StartDaemon => {
|
||||||
let addr2 = "127.0.0.1:1234".parse()?;
|
let addr2 = "127.0.0.1:1234".parse()?;
|
||||||
|
|
||||||
let server_handle = {
|
let (_, server_handle) = rpc::run_server(addr2, Arc::clone(&context)).await?;
|
||||||
if let Some(addr) = context.config.server_address {
|
|
||||||
let (_addr, handle) = rpc::run_server(addr, context).await?;
|
loop {
|
||||||
Some(handle)
|
tokio::select! {
|
||||||
} else {
|
_ = self.shutdown.recv() => {
|
||||||
let (_addr, handle) = rpc::run_server(addr2, context).await?;
|
server_handle.stop();
|
||||||
Some(handle)
|
return Ok(json!({
|
||||||
|
"result": []
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
loop {}
|
|
||||||
json!({
|
|
||||||
"result": []
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
Method::Balance => {
|
Method::Balance => {
|
||||||
let bitcoin_wallet = context.bitcoin_wallet.as_ref().unwrap();
|
let bitcoin_wallet = context.bitcoin_wallet.as_ref().unwrap();
|
||||||
@ -458,6 +502,7 @@ impl Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn qr_code(value: &impl ToString) -> Result<String> {
|
fn qr_code(value: &impl ToString) -> Result<String> {
|
||||||
let code = QrCode::new(value.to_string())?;
|
let code = QrCode::new(value.to_string())?;
|
||||||
let qr_code = code
|
let qr_code = code
|
||||||
|
@ -17,10 +17,12 @@ use std::env;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use swap::cli::command::{parse_args_and_apply_defaults, ParseResult};
|
use swap::cli::command::{parse_args_and_apply_defaults, ParseResult};
|
||||||
use swap::common::check_latest_version;
|
use swap::common::check_latest_version;
|
||||||
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let (context, request) = match parse_args_and_apply_defaults(env::args_os()).await? {
|
let (tx, mut rx1) = broadcast::channel(1);
|
||||||
|
let (context, mut request) = match parse_args_and_apply_defaults(env::args_os(), tx).await? {
|
||||||
ParseResult::Context(context, request) => (context, request),
|
ParseResult::Context(context, request) => (context, request),
|
||||||
ParseResult::PrintAndExitZero { message } => {
|
ParseResult::PrintAndExitZero { message } => {
|
||||||
println!("{}", message);
|
println!("{}", message);
|
||||||
@ -42,7 +44,7 @@ mod tests {
|
|||||||
use ::bitcoin::Amount;
|
use ::bitcoin::Amount;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use swap::api::determine_btc_to_swap;
|
use swap::api::request::determine_btc_to_swap;
|
||||||
use swap::network::quote::BidQuote;
|
use swap::network::quote::BidQuote;
|
||||||
use swap::tracing_ext::capture_logs;
|
use swap::tracing_ext::capture_logs;
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::api::Context;
|
use crate::api::Context;
|
||||||
use crate::api::request::{Request, Params, Method};
|
use crate::api::request::{Request, Params, Method, Shutdown};
|
||||||
use crate::bitcoin::{Amount, bitcoin_address};
|
use crate::bitcoin::{Amount, bitcoin_address};
|
||||||
use crate::monero::monero_address;
|
use crate::monero::monero_address;
|
||||||
use crate::monero;
|
use crate::monero;
|
||||||
@ -13,6 +13,7 @@ use std::sync::Arc;
|
|||||||
use structopt::{clap, StructOpt};
|
use structopt::{clap, StructOpt};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
// See: https://moneroworld.com/
|
// See: https://moneroworld.com/
|
||||||
pub const DEFAULT_MONERO_DAEMON_ADDRESS: &str = "node.community.rino.io:18081";
|
pub const DEFAULT_MONERO_DAEMON_ADDRESS: &str = "node.community.rino.io:18081";
|
||||||
@ -41,7 +42,7 @@ pub enum ParseResult {
|
|||||||
PrintAndExitZero { message: String },
|
PrintAndExitZero { message: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn parse_args_and_apply_defaults<I, T>(raw_args: I) -> Result<ParseResult>
|
pub async fn parse_args_and_apply_defaults<I, T>(raw_args: I, rx: broadcast::Sender<()>) -> Result<ParseResult>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
T: Into<OsString> + Clone,
|
T: Into<OsString> + Clone,
|
||||||
@ -60,7 +61,6 @@ where
|
|||||||
let json = args.json;
|
let json = args.json;
|
||||||
let is_testnet = args.testnet;
|
let is_testnet = args.testnet;
|
||||||
let data = args.data;
|
let data = args.data;
|
||||||
|
|
||||||
let (context, request) = match args.cmd {
|
let (context, request) = match args.cmd {
|
||||||
CliCommand::BuyXmr {
|
CliCommand::BuyXmr {
|
||||||
seller: Seller { seller },
|
seller: Seller { seller },
|
||||||
@ -70,18 +70,6 @@ where
|
|||||||
monero_receive_address,
|
monero_receive_address,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
let context = Context::build(
|
|
||||||
Some(bitcoin),
|
|
||||||
Some(monero),
|
|
||||||
Some(tor),
|
|
||||||
data,
|
|
||||||
is_testnet,
|
|
||||||
debug,
|
|
||||||
json,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let monero_receive_address = monero_address::validate(monero_receive_address, is_testnet)?;
|
let monero_receive_address = monero_address::validate(monero_receive_address, is_testnet)?;
|
||||||
let bitcoin_change_address = bitcoin_address::validate(bitcoin_change_address, is_testnet)?;
|
let bitcoin_change_address = bitcoin_address::validate(bitcoin_change_address, is_testnet)?;
|
||||||
|
|
||||||
@ -93,30 +81,52 @@ where
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::BuyXmr,
|
cmd: Method::BuyXmr,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context = Context::build(
|
||||||
|
Some(bitcoin),
|
||||||
|
Some(monero),
|
||||||
|
Some(tor),
|
||||||
|
data,
|
||||||
|
is_testnet,
|
||||||
|
debug,
|
||||||
|
json,
|
||||||
|
None,
|
||||||
|
rx,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::History => {
|
CliCommand::History => {
|
||||||
let context =
|
|
||||||
Context::build(None, None, None, data, is_testnet, debug, json, None).await?;
|
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cmd: Method::History,
|
cmd: Method::History,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context =
|
||||||
|
Context::build(None, None, None, data, is_testnet, debug, json, None, rx).await?;
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::Config => {
|
CliCommand::Config => {
|
||||||
let context =
|
|
||||||
Context::build(None, None, None, data, is_testnet, debug, json, None).await?;
|
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cmd: Method::Config,
|
cmd: Method::Config,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context =
|
||||||
|
Context::build(None, None, None, data, is_testnet, debug, json, None, rx).await?;
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::Balance { bitcoin } => {
|
CliCommand::Balance { bitcoin } => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params::default(),
|
||||||
|
cmd: Method::Balance,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
None,
|
None,
|
||||||
@ -126,12 +136,9 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
None,
|
None,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params::default(),
|
|
||||||
cmd: Method::Balance,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::StartDaemon {
|
CliCommand::StartDaemon {
|
||||||
@ -140,6 +147,12 @@ where
|
|||||||
monero,
|
monero,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params::default(),
|
||||||
|
cmd: Method::StartDaemon,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
Some(monero),
|
Some(monero),
|
||||||
@ -149,12 +162,9 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
server_address,
|
server_address,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params::default(),
|
|
||||||
cmd: Method::StartDaemon,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::WithdrawBtc {
|
CliCommand::WithdrawBtc {
|
||||||
@ -162,18 +172,6 @@ where
|
|||||||
amount,
|
amount,
|
||||||
address,
|
address,
|
||||||
} => {
|
} => {
|
||||||
let context = Context::build(
|
|
||||||
Some(bitcoin),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
data,
|
|
||||||
is_testnet,
|
|
||||||
debug,
|
|
||||||
json,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let address = bitcoin_address::validate(address, is_testnet)?;
|
let address = bitcoin_address::validate(address, is_testnet)?;
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
@ -183,7 +181,21 @@ where
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::WithdrawBtc,
|
cmd: Method::WithdrawBtc,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context = Context::build(
|
||||||
|
Some(bitcoin),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
data,
|
||||||
|
is_testnet,
|
||||||
|
debug,
|
||||||
|
json,
|
||||||
|
None,
|
||||||
|
rx,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::Resume {
|
CliCommand::Resume {
|
||||||
@ -192,6 +204,15 @@ where
|
|||||||
monero,
|
monero,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params {
|
||||||
|
swap_id: Some(swap_id),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cmd: Method::Resume,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
Some(monero),
|
Some(monero),
|
||||||
@ -201,15 +222,9 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
None,
|
None,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params {
|
|
||||||
swap_id: Some(swap_id),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
cmd: Method::Resume,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::Cancel {
|
CliCommand::Cancel {
|
||||||
@ -217,6 +232,15 @@ where
|
|||||||
bitcoin,
|
bitcoin,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params {
|
||||||
|
swap_id: Some(swap_id),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cmd: Method::Cancel,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
None,
|
None,
|
||||||
@ -226,15 +250,9 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
None,
|
None,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params {
|
|
||||||
swap_id: Some(swap_id),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
cmd: Method::Cancel,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::Refund {
|
CliCommand::Refund {
|
||||||
@ -242,6 +260,15 @@ where
|
|||||||
bitcoin,
|
bitcoin,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params {
|
||||||
|
swap_id: Some(swap_id),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cmd: Method::Refund,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
None,
|
None,
|
||||||
@ -251,34 +278,36 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
None,
|
None,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params {
|
|
||||||
swap_id: Some(swap_id),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
cmd: Method::Refund,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::ListSellers {
|
CliCommand::ListSellers {
|
||||||
rendezvous_point,
|
rendezvous_point,
|
||||||
tor,
|
tor,
|
||||||
} => {
|
} => {
|
||||||
let context =
|
|
||||||
Context::build(None, None, Some(tor), data, is_testnet, debug, json, None).await?;
|
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
rendezvous_point: Some(rendezvous_point),
|
rendezvous_point: Some(rendezvous_point),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::ListSellers,
|
cmd: Method::ListSellers,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context =
|
||||||
|
Context::build(None, None, Some(tor), data, is_testnet, debug, json, None, rx).await?;
|
||||||
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::ExportBitcoinWallet { bitcoin } => {
|
CliCommand::ExportBitcoinWallet { bitcoin } => {
|
||||||
|
let request = Request {
|
||||||
|
params: Params::default(),
|
||||||
|
cmd: Method::ExportBitcoinWallet,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
|
};
|
||||||
|
|
||||||
let context = Context::build(
|
let context = Context::build(
|
||||||
Some(bitcoin),
|
Some(bitcoin),
|
||||||
None,
|
None,
|
||||||
@ -288,25 +317,24 @@ where
|
|||||||
debug,
|
debug,
|
||||||
json,
|
json,
|
||||||
None,
|
None,
|
||||||
|
rx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let request = Request {
|
|
||||||
params: Params::default(),
|
|
||||||
cmd: Method::ExportBitcoinWallet,
|
|
||||||
};
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
CliCommand::MoneroRecovery { swap_id } => {
|
CliCommand::MoneroRecovery { swap_id } => {
|
||||||
let context =
|
|
||||||
Context::build(None, None, None, data, is_testnet, debug, json, None).await?;
|
|
||||||
|
|
||||||
let request = Request {
|
let request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(swap_id.swap_id),
|
swap_id: Some(swap_id.swap_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::MoneroRecovery,
|
cmd: Method::MoneroRecovery,
|
||||||
|
shutdown: Shutdown::new(rx.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let context =
|
||||||
|
Context::build(None, None, None, data, is_testnet, debug, json, None, rx).await?;
|
||||||
|
|
||||||
(context, request)
|
(context, request)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -577,6 +605,8 @@ mod tests {
|
|||||||
use crate::api::api_test::*;
|
use crate::api::api_test::*;
|
||||||
use sequential_test::sequential;
|
use sequential_test::sequential;
|
||||||
use crate::monero::monero_address::MoneroAddressNetworkMismatch;
|
use crate::monero::monero_address::MoneroAddressNetworkMismatch;
|
||||||
|
use crate::api::Config;
|
||||||
|
use crate::fs::system_data_dir;
|
||||||
|
|
||||||
const BINARY_NAME: &str = "swap";
|
const BINARY_NAME: &str = "swap";
|
||||||
const ARGS_DATA_DIR: &str = "/tmp/dir/";
|
const ARGS_DATA_DIR: &str = "/tmp/dir/";
|
||||||
@ -595,12 +625,13 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -627,12 +658,13 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -658,7 +690,8 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let err = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let err = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.downcast_ref::<MoneroAddressNetworkMismatch>().unwrap(),
|
err.downcast_ref::<MoneroAddressNetworkMismatch>().unwrap(),
|
||||||
@ -684,7 +717,8 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let err = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let err = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.downcast_ref::<MoneroAddressNetworkMismatch>().unwrap(),
|
err.downcast_ref::<MoneroAddressNetworkMismatch>().unwrap(),
|
||||||
@ -700,12 +734,13 @@ mod tests {
|
|||||||
async fn given_resume_on_mainnet_then_defaults_to_mainnet() {
|
async fn given_resume_on_mainnet_then_defaults_to_mainnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "resume", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "resume", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -722,12 +757,13 @@ mod tests {
|
|||||||
async fn given_resume_on_testnet_then_defaults_to_testnet() {
|
async fn given_resume_on_testnet_then_defaults_to_testnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "--testnet", "resume", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "--testnet", "resume", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -744,13 +780,14 @@ mod tests {
|
|||||||
async fn given_cancel_on_mainnet_then_defaults_to_mainnet() {
|
async fn given_cancel_on_mainnet_then_defaults_to_mainnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "cancel", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "cancel", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
|
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::cancel(),
|
Request::cancel(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -767,12 +804,13 @@ mod tests {
|
|||||||
async fn given_cancel_on_testnet_then_defaults_to_testnet() {
|
async fn given_cancel_on_testnet_then_defaults_to_testnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "--testnet", "cancel", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "--testnet", "cancel", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::cancel(),
|
Request::cancel(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -789,12 +827,13 @@ mod tests {
|
|||||||
async fn given_refund_on_mainnet_then_defaults_to_mainnet() {
|
async fn given_refund_on_mainnet_then_defaults_to_mainnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "refund", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "refund", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::refund(),
|
Request::refund(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -811,12 +850,13 @@ mod tests {
|
|||||||
async fn given_refund_on_testnet_then_defaults_to_testnet() {
|
async fn given_refund_on_testnet_then_defaults_to_testnet() {
|
||||||
let raw_ars = vec![BINARY_NAME, "--testnet", "refund", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "--testnet", "refund", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::refund(),
|
Request::refund(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -844,13 +884,14 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -880,13 +921,14 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let (tx, _) = broadcast::channel(1);
|
||||||
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -911,13 +953,14 @@ mod tests {
|
|||||||
SWAP_ID,
|
SWAP_ID,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let (tx, _) = broadcast::channel(1);
|
||||||
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, false);
|
let (is_testnet, debug, json) = (false, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -943,13 +986,14 @@ mod tests {
|
|||||||
SWAP_ID,
|
SWAP_ID,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let (tx, _) = broadcast::channel(1);
|
||||||
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
let data_dir = PathBuf::from_str(ARGS_DATA_DIR).unwrap();
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, false);
|
let (is_testnet, debug, json) = (true, false, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
Config::default(is_testnet, Some(data_dir.clone()), debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -976,12 +1020,13 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, true, false);
|
let (is_testnet, debug, json) = (false, true, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1009,12 +1054,13 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, true, false);
|
let (is_testnet, debug, json) = (true, true, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1032,12 +1078,13 @@ mod tests {
|
|||||||
|
|
||||||
let raw_ars = vec![BINARY_NAME, "--debug", "resume", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "--debug", "resume", "--swap-id", SWAP_ID];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, true, false);
|
let (is_testnet, debug, json) = (false, true, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1062,12 +1109,13 @@ mod tests {
|
|||||||
SWAP_ID,
|
SWAP_ID,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, true, false);
|
let (is_testnet, debug, json) = (true, true, false);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1094,13 +1142,14 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, true);
|
let (is_testnet, debug, json) = (false, false, true);
|
||||||
let data_dir = data_dir_path_cli(is_testnet);
|
let data_dir = data_dir_path_cli(is_testnet);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1128,12 +1177,13 @@ mod tests {
|
|||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, true);
|
let (is_testnet, debug, json) = (true, false, true);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::buy_xmr(is_testnet),
|
Request::buy_xmr(is_testnet, tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1149,13 +1199,14 @@ mod tests {
|
|||||||
#[sequential]
|
#[sequential]
|
||||||
async fn given_resume_on_mainnet_with_json_then_json_set() {
|
async fn given_resume_on_mainnet_with_json_then_json_set() {
|
||||||
|
|
||||||
|
let (tx, _) = broadcast::channel(1);
|
||||||
let raw_ars = vec![BINARY_NAME, "--json", "resume", "--swap-id", SWAP_ID];
|
let raw_ars = vec![BINARY_NAME, "--json", "resume", "--swap-id", SWAP_ID];
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (false, false, true);
|
let (is_testnet, debug, json) = (false, false, true);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1180,12 +1231,13 @@ mod tests {
|
|||||||
SWAP_ID,
|
SWAP_ID,
|
||||||
];
|
];
|
||||||
|
|
||||||
let args = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let args = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
let (is_testnet, debug, json) = (true, false, true);
|
let (is_testnet, debug, json) = (true, false, true);
|
||||||
|
|
||||||
let (expected_config, expected_request) = (
|
let (expected_config, expected_request) = (
|
||||||
Config::default(is_testnet, None, debug, json),
|
Config::default(is_testnet, None, debug, json),
|
||||||
Request::resume(),
|
Request::resume(tx.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (actual_config, actual_request) = match args {
|
let (actual_config, actual_request) = match args {
|
||||||
@ -1210,7 +1262,8 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let (tx, _) = broadcast::channel(1);
|
||||||
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
let raw_ars = vec![
|
let raw_ars = vec![
|
||||||
BINARY_NAME,
|
BINARY_NAME,
|
||||||
@ -1222,7 +1275,7 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
let raw_ars = vec![
|
let raw_ars = vec![
|
||||||
BINARY_NAME,
|
BINARY_NAME,
|
||||||
@ -1234,13 +1287,14 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
assert!(matches!(result, ParseResult::Context(_, _)));
|
assert!(matches!(result, ParseResult::Context(_, _)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[sequential]
|
#[sequential]
|
||||||
async fn only_bech32_addresses_testnet_are_allowed() {
|
async fn only_bech32_addresses_testnet_are_allowed() {
|
||||||
|
let (tx, _) = broadcast::channel(1);
|
||||||
let raw_ars = vec![
|
let raw_ars = vec![
|
||||||
BINARY_NAME,
|
BINARY_NAME,
|
||||||
"--testnet",
|
"--testnet",
|
||||||
@ -1252,7 +1306,7 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
let raw_ars = vec![
|
let raw_ars = vec![
|
||||||
BINARY_NAME,
|
BINARY_NAME,
|
||||||
@ -1265,7 +1319,7 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap_err();
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap_err();
|
||||||
|
|
||||||
let raw_ars = vec![
|
let raw_ars = vec![
|
||||||
BINARY_NAME,
|
BINARY_NAME,
|
||||||
@ -1278,7 +1332,7 @@ mod tests {
|
|||||||
"--seller",
|
"--seller",
|
||||||
MULTI_ADDRESS,
|
MULTI_ADDRESS,
|
||||||
];
|
];
|
||||||
let result = parse_args_and_apply_defaults(raw_ars).await.unwrap();
|
let result = parse_args_and_apply_defaults(raw_ars, tx.clone()).await.unwrap();
|
||||||
assert!(matches!(result, ParseResult::Context(_, _)));
|
assert!(matches!(result, ParseResult::Context(_, _)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::api::Context;
|
use crate::api::Context;
|
||||||
use jsonrpsee::http_server::{HttpServerBuilder, HttpServerHandle, RpcModule};
|
use jsonrpsee::server::{ServerBuilder, ServerHandle, RpcModule};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@ -15,8 +15,8 @@ pub enum Error {
|
|||||||
pub async fn run_server(
|
pub async fn run_server(
|
||||||
server_address: SocketAddr,
|
server_address: SocketAddr,
|
||||||
context: Arc<Context>,
|
context: Arc<Context>,
|
||||||
) -> anyhow::Result<(SocketAddr, HttpServerHandle)> {
|
) -> anyhow::Result<(SocketAddr, ServerHandle)> {
|
||||||
let server = HttpServerBuilder::default().build(server_address).await?;
|
let server = ServerBuilder::default().build(server_address).await?;
|
||||||
let mut modules = RpcModule::new(());
|
let mut modules = RpcModule::new(());
|
||||||
{
|
{
|
||||||
modules
|
modules
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::api::{Context};
|
use crate::api::{Context};
|
||||||
use crate::api::request::{Params, Request, Method};
|
use crate::api::request::{Params, Request, Method, Shutdown};
|
||||||
//use crate::rpc::Error;
|
//use crate::rpc::Error;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crate::{bitcoin, monero};
|
use crate::{bitcoin, monero};
|
||||||
use crate::{bitcoin::bitcoin_address, monero::monero_address};
|
use crate::{bitcoin::bitcoin_address, monero::monero_address};
|
||||||
use jsonrpsee::http_server::RpcModule;
|
use jsonrpsee::server::RpcModule;
|
||||||
use libp2p::core::Multiaddr;
|
use libp2p::core::Multiaddr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -144,9 +144,10 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_bitcoin_balance(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
async fn get_bitcoin_balance(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cmd: Method::Balance,
|
cmd: Method::Balance,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let balance = request.call(Arc::clone(context))
|
let balance = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -156,9 +157,10 @@ async fn get_bitcoin_balance(context: &Arc<Context>) -> Result<serde_json::Value
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
async fn get_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cmd: Method::History,
|
cmd: Method::History,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let history = request.call(Arc::clone(context))
|
let history = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -167,9 +169,10 @@ async fn get_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrp
|
|||||||
Ok(history)
|
Ok(history)
|
||||||
}
|
}
|
||||||
async fn get_raw_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
async fn get_raw_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
cmd: Method::RawHistory,
|
cmd: Method::RawHistory,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let history = request.call(Arc::clone(context))
|
let history = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -182,12 +185,13 @@ async fn get_seller(
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
context: &Arc<Context>
|
context: &Arc<Context>
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(swap_id),
|
swap_id: Some(swap_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::GetSeller,
|
cmd: Method::GetSeller,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let result = request.call(Arc::clone(context))
|
let result = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -200,12 +204,13 @@ async fn get_swap_start_date(
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
context: &Arc<Context>
|
context: &Arc<Context>
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(swap_id),
|
swap_id: Some(swap_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::SwapStartDate,
|
cmd: Method::SwapStartDate,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let result = request.call(Arc::clone(context))
|
let result = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -218,12 +223,13 @@ async fn resume_swap(
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
context: &Arc<Context>,
|
context: &Arc<Context>,
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
swap_id: Some(swap_id),
|
swap_id: Some(swap_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::Resume,
|
cmd: Method::Resume,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = request.call(Arc::clone(context))
|
let result = request.call(Arc::clone(context))
|
||||||
@ -236,13 +242,14 @@ async fn withdraw_btc(
|
|||||||
amount: Option<bitcoin::Amount>,
|
amount: Option<bitcoin::Amount>,
|
||||||
context: &Arc<Context>,
|
context: &Arc<Context>,
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
amount,
|
amount,
|
||||||
address: Some(withdraw_address),
|
address: Some(withdraw_address),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::WithdrawBtc,
|
cmd: Method::WithdrawBtc,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let result = request.call(Arc::clone(context))
|
let result = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -256,7 +263,7 @@ async fn buy_xmr(
|
|||||||
seller: Multiaddr,
|
seller: Multiaddr,
|
||||||
context: &Arc<Context>,
|
context: &Arc<Context>,
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
bitcoin_change_address: Some(bitcoin_change_address),
|
bitcoin_change_address: Some(bitcoin_change_address),
|
||||||
monero_receive_address: Some(monero_receive_address),
|
monero_receive_address: Some(monero_receive_address),
|
||||||
@ -264,6 +271,7 @@ async fn buy_xmr(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::BuyXmr,
|
cmd: Method::BuyXmr,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let swap = request.call(Arc::clone(context))
|
let swap = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
@ -275,12 +283,13 @@ async fn list_sellers(
|
|||||||
rendezvous_point: Multiaddr,
|
rendezvous_point: Multiaddr,
|
||||||
context: &Arc<Context>,
|
context: &Arc<Context>,
|
||||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||||
let request = Request {
|
let mut request = Request {
|
||||||
params: Params {
|
params: Params {
|
||||||
rendezvous_point: Some(rendezvous_point),
|
rendezvous_point: Some(rendezvous_point),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cmd: Method::ListSellers,
|
cmd: Method::ListSellers,
|
||||||
|
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||||
};
|
};
|
||||||
let result = request.call(Arc::clone(context))
|
let result = request.call(Arc::clone(context))
|
||||||
.await
|
.await
|
||||||
|
Loading…
Reference in New Issue
Block a user