2020-10-15 22:14:39 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-10-15 23:43:32 +00:00
|
|
|
use std::fmt::{self, Display};
|
2020-10-15 22:14:39 +00:00
|
|
|
|
|
|
|
pub mod alice;
|
2020-10-21 02:01:10 +00:00
|
|
|
pub mod bitcoin;
|
2020-10-15 22:14:39 +00:00
|
|
|
pub mod bob;
|
2020-10-21 02:01:10 +00:00
|
|
|
pub mod monero;
|
2020-10-15 22:14:39 +00:00
|
|
|
pub mod network;
|
|
|
|
|
|
|
|
pub const ONE_BTC: u64 = 100_000_000;
|
|
|
|
|
|
|
|
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)]
|
2020-10-15 22:14:39 +00:00
|
|
|
pub enum Cmd {
|
|
|
|
VerifyAmounts(SwapParams),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Responses send from the main task back to Bob.
|
2020-10-15 23:43:32 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
2020-10-15 22:14:39 +00:00
|
|
|
pub enum Rsp {
|
|
|
|
Verified,
|
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// XMR/BTC swap parameters.
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct SwapParams {
|
|
|
|
/// Amount of BTC to swap.
|
2020-10-21 02:01:10 +00:00
|
|
|
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
2020-10-15 22:14:39 +00:00
|
|
|
pub btc: bitcoin::Amount,
|
|
|
|
/// Amount of XMR to swap.
|
|
|
|
pub xmr: monero::Amount,
|
|
|
|
}
|
|
|
|
|
2020-10-15 23:43:32 +00:00
|
|
|
impl Display for SwapParams {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{} for {}", self.btc, self.xmr)
|
|
|
|
}
|
|
|
|
}
|