2020-10-15 18:14:39 -04: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
|
|
|
|
|
|
|
pub mod alice;
|
2020-10-20 22:01:10 -04:00
|
|
|
pub mod bitcoin;
|
2020-10-15 18:14:39 -04:00
|
|
|
pub mod bob;
|
|
|
|
pub mod network;
|
|
|
|
|
|
|
|
pub const ONE_BTC: u64 = 100_000_000;
|
|
|
|
|
2020-10-21 22:30:07 -04:00
|
|
|
const REFUND_TIMELOCK: u32 = 10; // Relative timelock, this is number of blocks. TODO: What should it be?
|
2020-10-20 23:41:50 -04:00
|
|
|
const PUNISH_TIMELOCK: u32 = 20; // FIXME: What should this be?
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/// Responses send 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 {
|
|
|
|
Verified,
|
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
2020-10-21 22:30:07 -04:00
|
|
|
/// XMR/BTC swap amounts.
|
2020-10-15 18:14:39 -04:00
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
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-10-20 23:41:50 -04:00
|
|
|
pub btc: ::bitcoin::Amount,
|
2020-10-15 18:14:39 -04:00
|
|
|
/// Amount of XMR to swap.
|
2020-10-21 22:54:13 -04:00
|
|
|
#[serde(with = "xmr_btc::serde::monero_amount")]
|
2020-10-20 23:41:50 -04:00
|
|
|
pub xmr: xmr_btc::monero::Amount,
|
2020-10-15 18:14:39 -04:00
|
|
|
}
|
|
|
|
|
2020-10-21 22:30:07 -04:00
|
|
|
impl Display for SwapAmounts {
|
2020-10-15 19:43:32 -04: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
|
|
|
}
|
|
|
|
}
|