mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-01 04:56:41 -05:00
fixing formatting and cargo clippy warnings
This commit is contained in:
parent
925c7bc179
commit
9d1a39b2ff
13 changed files with 374 additions and 209 deletions
|
|
@ -1,8 +1,9 @@
|
|||
use crate::api::{Context};
|
||||
use crate::api::request::{Params, Request, Method, Shutdown};
|
||||
use anyhow::Result;
|
||||
use crate::api::request::{Method, Params, Request, Shutdown};
|
||||
use crate::api::Context;
|
||||
use crate::bitcoin::bitcoin_address;
|
||||
use crate::monero::monero_address;
|
||||
use crate::{bitcoin, monero};
|
||||
use crate::{bitcoin::bitcoin_address, monero::monero_address};
|
||||
use anyhow::Result;
|
||||
use jsonrpsee::server::RpcModule;
|
||||
use libp2p::core::Multiaddr;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -16,17 +17,17 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
.register_async_method("get_bitcoin_balance", |_, context| async move {
|
||||
get_bitcoin_balance(&context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method get_bitcoin_balance");
|
||||
module
|
||||
.register_async_method("get_history", |_, context| async move {
|
||||
get_history(&context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method get_history");
|
||||
module
|
||||
.register_async_method("get_raw_history", |_, context| async move {
|
||||
get_raw_history(&context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method get_history");
|
||||
module
|
||||
.register_async_method("get_seller", |params, context| async move {
|
||||
let params: HashMap<String, Uuid> = params.parse()?;
|
||||
|
|
@ -37,7 +38,7 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
|
||||
get_seller(*swap_id, &context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method get_seller");
|
||||
module
|
||||
.register_async_method("get_swap_start_date", |params, context| async move {
|
||||
let params: HashMap<String, Uuid> = params.parse()?;
|
||||
|
|
@ -48,7 +49,7 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
|
||||
get_swap_start_date(*swap_id, &context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method get_swap_start_date");
|
||||
module
|
||||
.register_async_method("resume_swap", |params, context| async move {
|
||||
let params: HashMap<String, Uuid> = params.parse()?;
|
||||
|
|
@ -59,7 +60,7 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
|
||||
resume_swap(*swap_id, &context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method resume_swap");
|
||||
module
|
||||
.register_async_method("withdraw_btc", |params, context| async move {
|
||||
let params: HashMap<String, String> = params.parse()?;
|
||||
|
|
@ -80,11 +81,12 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
jsonrpsee_core::Error::Custom("Does not contain address".to_string())
|
||||
})?)
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
let withdraw_address = bitcoin_address::validate(withdraw_address, context.config.is_testnet)?;
|
||||
let withdraw_address =
|
||||
bitcoin_address::validate(withdraw_address, context.config.is_testnet)?;
|
||||
|
||||
withdraw_btc(withdraw_address, amount, &context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method withdraw_btc");
|
||||
module
|
||||
.register_async_method("buy_xmr", |params, context| async move {
|
||||
let params: HashMap<String, String> = params.parse()?;
|
||||
|
|
@ -98,7 +100,8 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
)
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
let bitcoin_change_address = bitcoin_address::validate(bitcoin_change_address, context.config.is_testnet)?;
|
||||
let bitcoin_change_address =
|
||||
bitcoin_address::validate(bitcoin_change_address, context.config.is_testnet)?;
|
||||
|
||||
let monero_receive_address = monero::Address::from_str(
|
||||
params.get("monero_receive_address").ok_or_else(|| {
|
||||
|
|
@ -109,7 +112,8 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
)
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
let monero_receive_address = monero_address::validate(monero_receive_address, context.config.is_testnet)?;
|
||||
let monero_receive_address =
|
||||
monero_address::validate(monero_receive_address, context.config.is_testnet)?;
|
||||
|
||||
let seller = Multiaddr::from_str(params.get("seller").ok_or_else(|| {
|
||||
jsonrpsee_core::Error::Custom("Does not contain seller".to_string())
|
||||
|
|
@ -121,29 +125,33 @@ pub fn register_modules(context: Arc<Context>) -> RpcModule<Arc<Context>> {
|
|||
monero_receive_address,
|
||||
seller,
|
||||
&context,
|
||||
).await
|
||||
)
|
||||
.await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method buy_xmr");
|
||||
module
|
||||
.register_async_method("list_sellers", |params, context| async move {
|
||||
let params: HashMap<String, Multiaddr> = params.parse()?;
|
||||
let rendezvous_point = params.get("rendezvous_point").ok_or_else(|| {
|
||||
jsonrpsee_core::Error::Custom("Does not contain rendezvous_point".to_string())
|
||||
})?;
|
||||
jsonrpsee_core::Error::Custom("Does not contain rendezvous_point".to_string())
|
||||
})?;
|
||||
|
||||
list_sellers(rendezvous_point.clone(), &context).await
|
||||
})
|
||||
.unwrap();
|
||||
.expect("Could not register RPC method list_sellers");
|
||||
module
|
||||
}
|
||||
|
||||
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 mut request = Request {
|
||||
params: Params::default(),
|
||||
cmd: Method::Balance,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let balance = request.call(Arc::clone(context))
|
||||
let balance = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
|
|
@ -156,19 +164,23 @@ async fn get_history(context: &Arc<Context>) -> Result<serde_json::Value, jsonrp
|
|||
cmd: Method::History,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let history = request.call(Arc::clone(context))
|
||||
let history = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
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 mut request = Request {
|
||||
params: Params::default(),
|
||||
cmd: Method::RawHistory,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let history = request.call(Arc::clone(context))
|
||||
let history = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
|
|
@ -177,7 +189,7 @@ async fn get_raw_history(context: &Arc<Context>) -> Result<serde_json::Value, js
|
|||
|
||||
async fn get_seller(
|
||||
swap_id: Uuid,
|
||||
context: &Arc<Context>
|
||||
context: &Arc<Context>,
|
||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||
let mut request = Request {
|
||||
params: Params {
|
||||
|
|
@ -187,7 +199,8 @@ async fn get_seller(
|
|||
cmd: Method::GetSeller,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let result = request.call(Arc::clone(context))
|
||||
let result = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
|
|
@ -196,7 +209,7 @@ async fn get_seller(
|
|||
|
||||
async fn get_swap_start_date(
|
||||
swap_id: Uuid,
|
||||
context: &Arc<Context>
|
||||
context: &Arc<Context>,
|
||||
) -> Result<serde_json::Value, jsonrpsee_core::Error> {
|
||||
let mut request = Request {
|
||||
params: Params {
|
||||
|
|
@ -206,7 +219,8 @@ async fn get_swap_start_date(
|
|||
cmd: Method::SwapStartDate,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let result = request.call(Arc::clone(context))
|
||||
let result = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
|
||||
|
|
@ -226,7 +240,8 @@ async fn resume_swap(
|
|||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
|
||||
let result = request.call(Arc::clone(context))
|
||||
let result = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
Ok(result)
|
||||
|
|
@ -245,7 +260,8 @@ async fn withdraw_btc(
|
|||
cmd: Method::WithdrawBtc,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let result = request.call(Arc::clone(context))
|
||||
let result = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
Ok(result)
|
||||
|
|
@ -267,7 +283,8 @@ async fn buy_xmr(
|
|||
cmd: Method::BuyXmr,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let swap = request.call(Arc::clone(context))
|
||||
let swap = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
Ok(swap)
|
||||
|
|
@ -285,7 +302,8 @@ async fn list_sellers(
|
|||
cmd: Method::ListSellers,
|
||||
shutdown: Shutdown::new(context.shutdown.subscribe()),
|
||||
};
|
||||
let result = request.call(Arc::clone(context))
|
||||
let result = request
|
||||
.call(Arc::clone(context))
|
||||
.await
|
||||
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))?;
|
||||
Ok(result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue