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