dprint fmt

This commit is contained in:
binarybaron 2023-08-10 00:15:16 +02:00
parent 13945cbd8f
commit 7193866c30
5 changed files with 110 additions and 59 deletions

View File

@ -205,7 +205,7 @@ fn env_config_from(testnet: bool) -> EnvConfig {
pub mod api_test { pub mod api_test {
use super::*; use super::*;
use crate::api::request::{Method, Params, Request}; use crate::api::request::{Method, Params, Request};
use libp2p::Multiaddr; use libp2p::Multiaddr;
use std::str::FromStr; use std::str::FromStr;
use tokio::sync::broadcast; use tokio::sync::broadcast;
@ -264,34 +264,50 @@ pub mod api_test {
} }
}; };
Request::new(tx.subscribe(), Method::BuyXmr, Params { Request::new(
seller: Some(seller), tx.subscribe(),
bitcoin_change_address: Some(bitcoin_change_address), Method::BuyXmr,
monero_receive_address: Some(monero_receive_address), Params {
swap_id: Some(Uuid::new_v4()), seller: Some(seller),
..Default::default() bitcoin_change_address: Some(bitcoin_change_address),
}) monero_receive_address: Some(monero_receive_address),
swap_id: Some(Uuid::new_v4()),
..Default::default()
},
)
} }
pub fn resume(tx: broadcast::Sender<()>) -> Request { pub fn resume(tx: broadcast::Sender<()>) -> Request {
Request::new(tx.subscribe(), Method::Resume, Params { Request::new(
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()), tx.subscribe(),
..Default::default() Method::Resume,
}) Params {
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
..Default::default()
},
)
} }
pub fn cancel(tx: broadcast::Sender<()>) -> Request { pub fn cancel(tx: broadcast::Sender<()>) -> Request {
Request::new(tx.subscribe(), Method::CancelAndRefund, Params { Request::new(
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()), tx.subscribe(),
..Default::default() Method::CancelAndRefund,
}) Params {
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
..Default::default()
},
)
} }
pub fn refund(tx: broadcast::Sender<()>) -> Request { pub fn refund(tx: broadcast::Sender<()>) -> Request {
Request::new(tx.subscribe(), Method::CancelAndRefund, Params { Request::new(
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()), tx.subscribe(),
..Default::default() Method::CancelAndRefund,
}) Params {
swap_id: Some(Uuid::from_str(SWAP_ID).unwrap()),
..Default::default()
},
)
} }
} }
} }

View File

@ -18,8 +18,8 @@ use std::future::Future;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tokio::sync::broadcast;
use tokio::sync::broadcast::Receiver; use tokio::sync::broadcast::Receiver;
use tokio::sync::Mutex;
use tracing::{debug_span, Instrument}; use tracing::{debug_span, Instrument};
use uuid::Uuid; use uuid::Uuid;
@ -63,7 +63,7 @@ impl Shutdown {
#[derive(Debug)] #[derive(Debug)]
pub struct Shutdown { pub struct Shutdown {
shutdown: bool, shutdown: bool,
notify: broadcast::Receiver<()>, notify: Receiver<()>,
} }
impl PartialEq for Shutdown { impl PartialEq for Shutdown {
@ -332,7 +332,10 @@ impl Request {
} }
Method::StartDaemon => { Method::StartDaemon => {
// Default to 127.0.0.1:1234 // Default to 127.0.0.1:1234
let server_address = self.params.server_address.unwrap_or("127.0.0.1:1234".parse().unwrap()); let server_address = self
.params
.server_address
.unwrap_or("127.0.0.1:1234".parse().unwrap());
let (_, server_handle) = let (_, server_handle) =
rpc::run_server(server_address, Arc::clone(&context)).await?; rpc::run_server(server_address, Arc::clone(&context)).await?;

View File

@ -78,12 +78,16 @@ where
let bitcoin_change_address = let bitcoin_change_address =
bitcoin_address::validate(bitcoin_change_address, is_testnet)?; bitcoin_address::validate(bitcoin_change_address, is_testnet)?;
let request = Request::new(rx.subscribe(), Method::BuyXmr, Params { let request = Request::new(
bitcoin_change_address: Some(bitcoin_change_address), rx.subscribe(),
monero_receive_address: Some(monero_receive_address), Method::BuyXmr,
seller: Some(seller), Params {
..Default::default() bitcoin_change_address: Some(bitcoin_change_address),
}); monero_receive_address: Some(monero_receive_address),
seller: Some(seller),
..Default::default()
},
);
let context = Context::build( let context = Context::build(
Some(bitcoin), Some(bitcoin),
@ -136,10 +140,14 @@ where
monero, monero,
tor, tor,
} => { } => {
let request = Request::new(rx.subscribe(), Method::StartDaemon, Params { let request = Request::new(
server_address, rx.subscribe(),
..Default::default() Method::StartDaemon,
}); Params {
server_address,
..Default::default()
},
);
let context = Context::build( let context = Context::build(
Some(bitcoin), Some(bitcoin),
@ -162,11 +170,15 @@ where
} => { } => {
let address = bitcoin_address::validate(address, is_testnet)?; let address = bitcoin_address::validate(address, is_testnet)?;
let request = Request::new(rx.subscribe(), Method::WithdrawBtc, Params { let request = Request::new(
amount, rx.subscribe(),
address: Some(address), Method::WithdrawBtc,
..Default::default() Params {
}); amount,
address: Some(address),
..Default::default()
},
);
let context = Context::build( let context = Context::build(
Some(bitcoin), Some(bitcoin),
@ -188,10 +200,14 @@ where
monero, monero,
tor, tor,
} => { } => {
let request = Request::new(rx.subscribe(), Method::Resume, Params { let request = Request::new(
swap_id: Some(swap_id), rx.subscribe(),
..Default::default() Method::Resume,
}); Params {
swap_id: Some(swap_id),
..Default::default()
},
);
let context = Context::build( let context = Context::build(
Some(bitcoin), Some(bitcoin),
@ -212,10 +228,14 @@ where
bitcoin, bitcoin,
tor, tor,
} => { } => {
let request = Request::new(rx.subscribe(), Method::CancelAndRefund, Params { let request = Request::new(
swap_id: Some(swap_id), rx.subscribe(),
..Default::default() Method::CancelAndRefund,
}); Params {
swap_id: Some(swap_id),
..Default::default()
},
);
let context = Context::build( let context = Context::build(
Some(bitcoin), Some(bitcoin),
@ -235,10 +255,14 @@ where
rendezvous_point, rendezvous_point,
tor, tor,
} => { } => {
let request = Request::new(rx.subscribe(), Method::ListSellers, Params { let request = Request::new(
rendezvous_point: Some(rendezvous_point), rx.subscribe(),
..Default::default() Method::ListSellers,
}); Params {
rendezvous_point: Some(rendezvous_point),
..Default::default()
},
);
let context = Context::build( let context = Context::build(
None, None,
@ -279,10 +303,14 @@ where
CliCommand::MoneroRecovery { CliCommand::MoneroRecovery {
swap_id: SwapId { swap_id }, swap_id: SwapId { swap_id },
} => { } => {
let request = Request::new(rx.subscribe(), Method::MoneroRecovery, Params { let request = Request::new(
swap_id: Some(swap_id), rx.subscribe(),
..Default::default() Method::MoneroRecovery,
}); Params {
swap_id: Some(swap_id),
..Default::default()
},
);
let context = let context =
Context::build(None, None, None, data, is_testnet, debug, json, None, rx).await?; Context::build(None, None, None, data, is_testnet, debug, json, None, rx).await?;
@ -540,7 +568,6 @@ struct Seller {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::api::api_test::*; use crate::api::api_test::*;
use crate::api::Config; use crate::api::Config;

View File

@ -13,21 +13,25 @@ use uuid::Uuid;
pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> { pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
let mut module = RpcModule::new(context); let mut module = RpcModule::new(context);
module module
.register_async_method("get_bitcoin_balance", |_, context| async move { .register_async_method("get_bitcoin_balance", |_, context| async move {
get_bitcoin_balance(&context).await get_bitcoin_balance(&context).await
}) })
.expect("Could not register RPC method get_bitcoin_balance"); .expect("Could not register RPC method get_bitcoin_balance");
module module
.register_async_method("get_history", |_, context| async move { .register_async_method("get_history", |_, context| async move {
get_history(&context).await get_history(&context).await
}) })
.expect("Could not register RPC method get_history"); .expect("Could not register RPC method get_history");
module module
.register_async_method("get_raw_history", |_, context| async move { .register_async_method("get_raw_history", |_, context| async move {
get_raw_history(&context).await get_raw_history(&context).await
}) })
.expect("Could not register RPC method get_history"); .expect("Could not register RPC method get_history");
module module
.register_async_method("get_seller", |params, context| async move { .register_async_method("get_seller", |params, context| async move {
let params: HashMap<String, Uuid> = params.parse()?; let params: HashMap<String, Uuid> = params.parse()?;
@ -39,6 +43,7 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
get_seller(*swap_id, &context).await get_seller(*swap_id, &context).await
}) })
.expect("Could not register RPC method get_seller"); .expect("Could not register RPC method get_seller");
module module
.register_async_method("get_swap_start_date", |params, context| async move { .register_async_method("get_swap_start_date", |params, context| async move {
let params: HashMap<String, Uuid> = params.parse()?; let params: HashMap<String, Uuid> = params.parse()?;
@ -50,6 +55,7 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
get_swap_start_date(*swap_id, &context).await get_swap_start_date(*swap_id, &context).await
}) })
.expect("Could not register RPC method get_swap_start_date"); .expect("Could not register RPC method get_swap_start_date");
module module
.register_async_method("resume_swap", |params, context| async move { .register_async_method("resume_swap", |params, context| async move {
let params: HashMap<String, Uuid> = params.parse()?; let params: HashMap<String, Uuid> = params.parse()?;

View File

@ -1,7 +1,7 @@
use anyhow::{Result}; use anyhow::Result;
use jsonrpsee::rpc_params;
use jsonrpsee::ws_client::WsClientBuilder; use jsonrpsee::ws_client::WsClientBuilder;
use jsonrpsee::{rpc_params};
use jsonrpsee_core::client::ClientT; use jsonrpsee_core::client::ClientT;
use jsonrpsee_core::params::ObjectParams; use jsonrpsee_core::params::ObjectParams;
@ -11,10 +11,9 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use swap::api::request::{Method, Params, Request, Shutdown}; use swap::api::request::{Method, Params, Request, Shutdown};
use swap::api::{Context}; use swap::api::Context;
use swap::cli::command::{Bitcoin, Monero}; use swap::cli::command::{Bitcoin, Monero};
use tokio::sync::broadcast; use tokio::sync::broadcast;
use uuid::Uuid; use uuid::Uuid;