xmr-btc-swap/swap/src/lib.rs

78 lines
1.7 KiB
Rust
Raw Normal View History

#![warn(
unused_extern_crates,
rust_2018_idioms,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::fallible_impl_from,
clippy::cast_precision_loss,
clippy::cast_possible_wrap,
clippy::dbg_macro
)]
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
#![forbid(unsafe_code)]
#![allow(
non_snake_case,
missing_debug_implementations,
missing_copy_implementations
)]
2020-11-24 05:49:47 +00:00
2021-01-07 23:44:31 +00:00
use serde::{Deserialize, Serialize};
2020-10-15 23:43:32 +00:00
use std::fmt::{self, Display};
2020-10-21 02:01:10 +00:00
pub mod bitcoin;
pub mod cli;
pub mod config;
pub mod database;
pub mod fs;
pub mod monero;
pub mod network;
pub mod protocol;
pub mod seed;
2020-12-04 05:27:17 +00:00
pub mod trace;
pub type Never = std::convert::Infallible;
/// Commands sent from Bob to the main task.
2020-10-15 23:43:32 +00:00
#[derive(Clone, Copy, Debug)]
pub enum Cmd {
2020-10-22 02:30:07 +00:00
VerifyAmounts(SwapAmounts),
}
2020-10-22 02:55:50 +00:00
/// Responses sent from the main task back to Bob.
2020-10-15 23:43:32 +00:00
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Rsp {
2020-10-22 02:55:50 +00:00
VerifiedAmounts,
Abort,
}
2020-10-22 02:30:07 +00:00
/// XMR/BTC swap amounts.
2020-12-08 03:54:08 +00:00
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
// TODO(Franck): review necessity of this struct
2020-10-22 02:30:07 +00:00
pub struct SwapAmounts {
/// Amount of BTC to swap.
2020-10-21 02:01:10 +00:00
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
pub btc: bitcoin::Amount,
/// Amount of XMR to swap.
2021-01-07 23:44:31 +00:00
#[serde(with = "monero::monero_amount")]
pub xmr: monero::Amount,
}
2020-10-22 02:55:50 +00:00
// TODO: Display in XMR and BTC (not picos and sats).
2020-10-22 02:30:07 +00:00
impl Display for SwapAmounts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2020-10-21 03:41:50 +00:00
write!(
f,
"{} sats for {} piconeros",
self.btc.as_sat(),
self.xmr.as_piconero()
)
2020-10-15 23:43:32 +00:00
}
}
#[derive(Debug, Clone, Copy)]
pub enum ExpiredTimelocks {
None,
Cancel,
Punish,
}