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

56 lines
1.2 KiB
Rust
Raw Normal View History

2020-11-24 00:49:47 -05:00
#![allow(non_snake_case)]
use serde::{Deserialize, Serialize};
2020-10-15 19:43:32 -04:00
use std::fmt::{self, Display};
2020-11-25 21:55:56 -05:00
pub mod alice;
2020-10-20 22:01:10 -04:00
pub mod bitcoin;
pub mod bob;
pub mod cli;
pub mod monero;
pub mod network;
pub mod recover;
2020-11-03 00:53:28 -05:00
pub mod state;
2020-10-22 22:13:17 -04:00
pub mod storage;
2020-10-22 19:32:48 -04:00
pub mod tor;
2020-12-04 00:27:17 -05:00
pub mod trace;
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)]
pub enum Cmd {
2020-10-21 22:30:07 -04:00
VerifyAmounts(SwapAmounts),
}
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)]
pub enum Rsp {
2020-10-21 22:55:50 -04:00
VerifiedAmounts,
Abort,
}
2020-10-21 22:30:07 -04:00
/// XMR/BTC swap amounts.
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
// TODO(Franck): review necessity of this struct
2020-10-21 22:30:07 -04:00
pub struct SwapAmounts {
/// Amount of BTC to swap.
2020-10-20 22:01:10 -04:00
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
pub btc: bitcoin::Amount,
/// Amount of XMR to swap.
2020-10-21 22:54:13 -04:00
#[serde(with = "xmr_btc::serde::monero_amount")]
pub xmr: monero::Amount,
}
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-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
}
}