refactor(tauri, swap): move rpc api to cli/api

This commit is contained in:
binarybaron 2024-08-26 15:40:50 +02:00
parent 5425a83871
commit 349035d321
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
15 changed files with 1231 additions and 46 deletions

View file

@ -5,6 +5,7 @@ mod event_loop;
mod list_sellers;
pub mod tracing;
pub mod transport;
pub mod api;
pub use behaviour::{Behaviour, OutEvent};
pub use cancel_and_refund::{cancel, cancel_and_refund, refund};

1188
swap/src/cli/api/request.rs Normal file

File diff suppressed because it is too large Load diff

View file

@ -27,11 +27,7 @@ impl TauriHandle {
}
pub trait TauriEmitter {
fn emit_tauri_event<S: Serialize + Clone>(
&self,
event: &str,
payload: S,
) -> Result<()>;
fn emit_tauri_event<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()>;
fn emit_swap_progress_event(&self, swap_id: Uuid, event: TauriSwapProgressEvent) {
let _ = self.emit_tauri_event(
@ -42,21 +38,13 @@ pub trait TauriEmitter {
}
impl TauriEmitter for TauriHandle {
fn emit_tauri_event<S: Serialize + Clone>(
&self,
event: &str,
payload: S,
) -> Result<()> {
fn emit_tauri_event<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()> {
self.emit_tauri_event(event, payload)
}
}
impl TauriEmitter for Option<TauriHandle> {
fn emit_tauri_event<S: Serialize + Clone>(
&self,
event: &str,
payload: S,
) -> Result<()> {
fn emit_tauri_event<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()> {
match self {
Some(tauri) => tauri.emit_tauri_event(event, payload),
None => Ok(()),

View file

@ -1,10 +1,9 @@
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, ExportBitcoinWalletArgs, GetConfigArgs, GetHistoryArgs,
ListSellersArgs, MoneroRecoveryArgs, Request, ResumeSwapArgs, StartDaemonArgs, WithdrawBtcArgs,
use crate::cli::api::request::{
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, ExportBitcoinWalletArgs, GetConfigArgs,
GetHistoryArgs, ListSellersArgs, MoneroRecoveryArgs, Request, ResumeSwapArgs, StartDaemonArgs,
WithdrawBtcArgs,
};
use crate::api::Context;
use crate::cli::api::Context;
use crate::bitcoin::{bitcoin_address, Amount};
use crate::monero;
use crate::monero::monero_address;
@ -544,15 +543,14 @@ struct Seller {
mod tests {
use super::*;
use crate::api::api_test::*;
use crate::api::Config;
use crate::cli::api::api_test::*;
use crate::cli::api::Config;
use crate::monero::monero_address::MoneroAddressNetworkMismatch;
const BINARY_NAME: &str = "swap";
const ARGS_DATA_DIR: &str = "/tmp/dir/";
#[tokio::test]
// this test is very long, however it just checks that various CLI arguments sets the
// internal Context and Request properly. It is unlikely to fail and splitting it in various
// tests would require to run the tests sequantially which is very slow (due to the context

View file

@ -73,6 +73,7 @@ pub enum Status {
Unreachable,
}
#[allow(unused)]
#[derive(Debug)]
enum OutEvent {
Rendezvous(rendezvous::client::Event),

View file

@ -264,6 +264,7 @@ mod wire {
#[serde(transparent)]
pub struct TickerUpdate(Vec<TickerField>);
#[allow(unused)]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum TickerField {
@ -277,6 +278,7 @@ mod wire {
ask: Vec<RateElement>,
}
#[allow(unused)]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum RateElement {

View file

@ -16,7 +16,6 @@
missing_copy_implementations
)]
pub mod api;
pub mod asb;
pub mod bitcoin;
pub mod cli;

View file

@ -13,5 +13,5 @@ pub mod tor_transport;
pub mod transfer_proof;
pub mod transport;
#[cfg(any(test, feature = "test"))]
#[cfg(test)]
pub mod test;

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::Result;
use uuid::Uuid;
use crate::api::tauri_bindings::TauriHandle;
use crate::cli::api::tauri_bindings::TauriHandle;
use crate::protocol::Database;
use crate::{bitcoin, cli, env, monero};

View file

@ -1,4 +1,4 @@
use crate::api::tauri_bindings::{TauriEmitter, TauriHandle, TauriSwapProgressEvent};
use crate::cli::api::tauri_bindings::{TauriEmitter, TauriHandle, TauriSwapProgressEvent};
use crate::bitcoin::{ExpiredTimelocks, TxCancel, TxRefund};
use crate::cli::EventLoopHandle;
use crate::network::cooperative_xmr_redeem_after_punish::Response::{Fullfilled, Rejected};

View file

@ -1,4 +1,4 @@
use crate::api::Context;
use crate::cli::api::Context;
use std::net::SocketAddr;
use thiserror::Error;
use tower_http::cors::CorsLayer;

View file

@ -1,10 +1,9 @@
use crate::api::request::{
get_current_swap, get_history, get_raw_states,
suspend_current_swap,
BalanceArgs, BuyXmrArgs, CancelAndRefundArgs, GetSwapInfoArgs, ListSellersArgs,
MoneroRecoveryArgs, Request, ResumeSwapArgs, WithdrawBtcArgs,
use crate::cli::api::request::{
get_current_swap, get_history, get_raw_states, suspend_current_swap, BalanceArgs, BuyXmrArgs,
CancelAndRefundArgs, GetSwapInfoArgs, ListSellersArgs, MoneroRecoveryArgs, Request,
ResumeSwapArgs, WithdrawBtcArgs,
};
use crate::api::Context;
use crate::cli::api::Context;
use crate::bitcoin::bitcoin_address;
use crate::monero::monero_address;
use crate::{bitcoin, monero};