2020-11-24 05:49:47 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2020-12-08 03:54:08 +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
|
|
|
|
2020-11-26 02:55:56 +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-11-12 00:06:34 +00:00
|
|
|
pub mod cli;
|
2020-10-27 01:11:03 +00:00
|
|
|
pub mod monero;
|
2020-10-15 22:14:39 +00:00
|
|
|
pub mod network;
|
2020-11-03 05:53:28 +00:00
|
|
|
pub mod state;
|
2020-10-23 02:13:17 +00:00
|
|
|
pub mod storage;
|
2020-12-04 05:27:17 +00:00
|
|
|
pub mod trace;
|
2020-10-15 22:14:39 +00:00
|
|
|
|
|
|
|
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 {
|
2020-10-22 02:30:07 +00:00
|
|
|
VerifyAmounts(SwapAmounts),
|
2020-10-15 22:14:39 +00:00
|
|
|
}
|
|
|
|
|
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)]
|
2020-10-15 22:14:39 +00:00
|
|
|
pub enum Rsp {
|
2020-10-22 02:55:50 +00:00
|
|
|
VerifiedAmounts,
|
2020-10-15 22:14:39 +00:00
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
2020-10-22 02:30:07 +00:00
|
|
|
/// XMR/BTC swap amounts.
|
2020-12-08 03:54:08 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
2020-11-18 05:27:50 +00:00
|
|
|
// TODO(Franck): review necessity of this struct
|
2020-10-22 02:30:07 +00:00
|
|
|
pub struct SwapAmounts {
|
2020-10-15 22:14:39 +00:00
|
|
|
/// Amount of BTC to swap.
|
2020-10-21 02:01:10 +00:00
|
|
|
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
2020-11-06 19:57:35 +00:00
|
|
|
pub btc: bitcoin::Amount,
|
2020-10-15 22:14:39 +00:00
|
|
|
/// Amount of XMR to swap.
|
2020-10-22 02:54:13 +00:00
|
|
|
#[serde(with = "xmr_btc::serde::monero_amount")]
|
2020-11-06 19:57:35 +00:00
|
|
|
pub xmr: monero::Amount,
|
2020-10-15 22:14:39 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|