mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-09-16 19:04:51 -04:00
wip: WithdrawDialog migrated to Tauri IPC
This commit is contained in:
parent
92034a5be8
commit
47821cbe79
14 changed files with 185 additions and 166 deletions
|
@ -21,7 +21,7 @@ use std::future::Future;
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tracing::{debug_span, field, Instrument, Span};
|
||||
use tracing::Instrument;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
|
@ -53,9 +53,9 @@ pub struct MoneroRecoveryArgs {
|
|||
pub swap_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WithdrawBtcArgs {
|
||||
pub amount: Option<Amount>,
|
||||
pub amount: Option<u64>,
|
||||
pub address: bitcoin::Address,
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,12 @@ pub struct GetSwapInfoResponse {
|
|||
pub timelock: Option<ExpiredTimelocks>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct WithdrawBtcResponse {
|
||||
amount: u64,
|
||||
txid: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Seller {
|
||||
pub peer_id: String,
|
||||
|
@ -645,7 +651,7 @@ pub async fn get_config(context: Arc<Context>) -> Result<serde_json::Value> {
|
|||
pub async fn withdraw_btc(
|
||||
withdraw_btc: WithdrawBtcArgs,
|
||||
context: Arc<Context>,
|
||||
) -> Result<serde_json::Value> {
|
||||
) -> Result<WithdrawBtcResponse> {
|
||||
let WithdrawBtcArgs { address, amount } = withdraw_btc;
|
||||
let bitcoin_wallet = context
|
||||
.bitcoin_wallet
|
||||
|
@ -653,7 +659,7 @@ pub async fn withdraw_btc(
|
|||
.context("Could not get Bitcoin wallet")?;
|
||||
|
||||
let amount = match amount {
|
||||
Some(amount) => amount,
|
||||
Some(amount) => Amount::from_sat(amount),
|
||||
None => {
|
||||
bitcoin_wallet
|
||||
.max_giveable(address.script_pubkey().len())
|
||||
|
@ -669,11 +675,10 @@ pub async fn withdraw_btc(
|
|||
.broadcast(signed_tx.clone(), "withdraw")
|
||||
.await?;
|
||||
|
||||
Ok(json!({
|
||||
"signed_tx": signed_tx,
|
||||
"amount": amount.to_sat(),
|
||||
"txid": signed_tx.txid(),
|
||||
}))
|
||||
Ok(WithdrawBtcResponse {
|
||||
txid: signed_tx.txid().to_string(),
|
||||
amount: amount.to_sat(),
|
||||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(fields(method = "start_daemon"), skip(context))]
|
||||
|
@ -848,17 +853,7 @@ impl Request {
|
|||
}
|
||||
}
|
||||
|
||||
async fn handle_cmd(self, context: Arc<Context>) -> Result<Box<dyn erased_serde::Serialize>> {
|
||||
match self.cmd {
|
||||
Method::Balance(args) => {
|
||||
let response = get_balance(args, context).await?;
|
||||
Ok(Box::new(response) as Box<dyn erased_serde::Serialize>)
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn call(self, context: Arc<Context>) -> Result<JsonValue> {
|
||||
pub async fn call(self, _: Arc<Context>) -> Result<JsonValue> {
|
||||
unreachable!("This function should never be called")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#![warn(
|
||||
unused_extern_crates,
|
||||
missing_copy_implementations,
|
||||
rust_2018_idioms,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss,
|
||||
clippy::fallible_impl_from,
|
||||
|
@ -12,8 +11,10 @@
|
|||
#![forbid(unsafe_code)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::cli::command::{parse_args_and_apply_defaults, ParseResult};
|
||||
use crate::common::check_latest_version;
|
||||
use crate::{
|
||||
cli::command::{parse_args_and_apply_defaults, ParseResult},
|
||||
common::check_latest_version,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use std::env;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::api::request::{
|
||||
buy_xmr, cancel_and_refund, export_bitcoin_wallet, get_balance, get_config, get_history,
|
||||
list_sellers, monero_recovery, resume_swap, start_daemon, withdraw_btc, BalanceArgs,
|
||||
BuyXmrArgs, CancelAndRefundArgs, ListSellersArgs, Method, MoneroRecoveryArgs, Request,
|
||||
ResumeArgs, StartDaemonArgs, WithdrawBtcArgs,
|
||||
BuyXmrArgs, CancelAndRefundArgs, ListSellersArgs, MoneroRecoveryArgs, ResumeArgs,
|
||||
StartDaemonArgs, WithdrawBtcArgs,
|
||||
};
|
||||
use crate::api::Context;
|
||||
use crate::bitcoin::{bitcoin_address, Amount};
|
||||
|
@ -10,7 +10,6 @@ use crate::monero;
|
|||
use crate::monero::monero_address;
|
||||
use anyhow::Result;
|
||||
use libp2p::core::Multiaddr;
|
||||
use serde_json::Value;
|
||||
use std::ffi::OsString;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
@ -193,7 +192,14 @@ where
|
|||
.await?,
|
||||
);
|
||||
|
||||
withdraw_btc(WithdrawBtcArgs { amount, address }, context).await?;
|
||||
withdraw_btc(
|
||||
WithdrawBtcArgs {
|
||||
amount: amount.map(Amount::to_sat),
|
||||
address,
|
||||
},
|
||||
context,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::api::Context;
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
use std::net::SocketAddr;
|
||||
use thiserror::Error;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
use jsonrpsee::{
|
||||
core::server::host_filtering::AllowHosts,
|
||||
server::{RpcModule, ServerBuilder, ServerHandle},
|
||||
server::{ServerBuilder, ServerHandle},
|
||||
};
|
||||
|
||||
pub mod methods;
|
||||
|
|
|
@ -13,7 +13,6 @@ use jsonrpsee::server::RpcModule;
|
|||
use libp2p::core::Multiaddr;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
trait ConvertToJsonRpseeError<T> {
|
||||
|
@ -29,7 +28,7 @@ impl<T> ConvertToJsonRpseeError<T> for Result<T, anyhow::Error> {
|
|||
pub fn register_modules(outer_context: Context) -> Result<RpcModule<Context>> {
|
||||
let mut module = RpcModule::new(outer_context);
|
||||
|
||||
module.register_async_method("suspend_current_swap", |params, context| async move {
|
||||
module.register_async_method("suspend_current_swap", |_, context| async move {
|
||||
suspend_current_swap(context).await.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
|
@ -66,11 +65,11 @@ pub fn register_modules(outer_context: Context) -> Result<RpcModule<Context>> {
|
|||
.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
module.register_async_method("get_history", |params, context| async move {
|
||||
module.register_async_method("get_history", |_, context| async move {
|
||||
get_history(context).await.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
module.register_async_method("get_raw_states", |params, context| async move {
|
||||
module.register_async_method("get_raw_states", |_, context| async move {
|
||||
get_raw_states(context).await.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
|
@ -131,7 +130,8 @@ pub fn register_modules(outer_context: Context) -> Result<RpcModule<Context>> {
|
|||
::bitcoin::Amount::from_str_in(amount_str, ::bitcoin::Denomination::Bitcoin)
|
||||
.map_err(|_| {
|
||||
jsonrpsee_core::Error::Custom("Unable to parse amount".to_string())
|
||||
})?,
|
||||
})?
|
||||
.to_sat(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
@ -224,7 +224,7 @@ pub fn register_modules(outer_context: Context) -> Result<RpcModule<Context>> {
|
|||
.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
module.register_async_method("get_current_swap", |params, context| async move {
|
||||
module.register_async_method("get_current_swap", |_, context| async move {
|
||||
get_current_swap(context).await.to_jsonrpsee_result()
|
||||
})?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue