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

55 lines
1.3 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
2020-10-15 23:43:32 +00:00
use std::fmt::{self, Display};
pub mod alice;
2020-10-21 02:01:10 +00:00
pub mod bitcoin;
pub mod bob;
pub mod monero;
pub mod network;
2020-10-23 02:13:17 +00:00
pub mod storage;
2020-10-22 23:32:48 +00:00
#[cfg(feature = "tor")]
pub mod tor;
pub const ONE_BTC: u64 = 100_000_000;
2020-10-22 02:30:07 +00:00
const REFUND_TIMELOCK: u32 = 10; // Relative timelock, this is number of blocks. TODO: What should it be?
2020-10-21 03:41:50 +00:00
const PUNISH_TIMELOCK: u32 = 20; // FIXME: What should this be?
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.
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
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")]
2020-10-21 03:41:50 +00:00
pub btc: ::bitcoin::Amount,
/// Amount of XMR to swap.
2020-10-22 02:54:13 +00:00
#[serde(with = "xmr_btc::serde::monero_amount")]
2020-10-21 03:41:50 +00:00
pub xmr: xmr_btc::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 {
2020-10-15 23:43:32 +00:00
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
}
}