mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-24 06:59:36 -05:00
Do some more cleanups
This commit is contained in:
parent
2059158dad
commit
30298bdf1f
@ -88,7 +88,6 @@ pub async fn swap(
|
||||
|
||||
let (state2, channel) = match swarm.next().await {
|
||||
OutEvent::Message1 { msg, channel } => {
|
||||
debug!("Got message1 from Bob");
|
||||
let state2 = state1.receive(msg);
|
||||
(state2, channel)
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ async fn swap_as_alice(
|
||||
|
||||
async fn swap_as_bob<W>(
|
||||
sats: u64,
|
||||
addr: Multiaddr,
|
||||
alice: Multiaddr,
|
||||
refund: bitcoin::Address,
|
||||
wallet: W,
|
||||
) -> Result<()>
|
||||
@ -113,7 +113,8 @@ where
|
||||
{
|
||||
let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
|
||||
let (mut rsp_tx, rsp_rx) = mpsc::channel(1);
|
||||
tokio::spawn(bob::swap(sats, addr, cmd_tx, rsp_rx, refund, wallet));
|
||||
tokio::spawn(bob::swap(sats, alice, cmd_tx, rsp_rx, refund, wallet));
|
||||
|
||||
loop {
|
||||
let read = cmd_rx.next().await;
|
||||
match read {
|
||||
@ -139,16 +140,19 @@ fn verify(amounts: SwapAmounts) -> Rsp {
|
||||
println!("Got rate from Alice for XMR/BTC swap\n");
|
||||
println!("{}", amounts);
|
||||
print!("Would you like to continue with this swap [y/N]: ");
|
||||
|
||||
let _ = io::stdout().flush();
|
||||
io::stdin()
|
||||
.read_line(&mut s)
|
||||
.expect("Did not enter a correct string");
|
||||
|
||||
if let Some('\n') = s.chars().next_back() {
|
||||
s.pop();
|
||||
}
|
||||
if let Some('\r') = s.chars().next_back() {
|
||||
s.pop();
|
||||
}
|
||||
|
||||
if !is_yes(&s) {
|
||||
println!("No worries, try again later - Alice updates her rate regularly");
|
||||
return Rsp::Abort;
|
||||
|
@ -1,10 +1,10 @@
|
||||
use serde::{de::Error, Deserialize, Deserializer, Serializer};
|
||||
|
||||
use xmr_btc::monero::Amount;
|
||||
//! Monero stuff, for now just serde.
|
||||
|
||||
// This has to be in a sub-module to use with serde derive.
|
||||
pub mod amount_serde {
|
||||
use super::*;
|
||||
use serde::{de::Error, Deserialize, Deserializer, Serializer};
|
||||
use std::str::FromStr;
|
||||
use xmr_btc::monero::Amount;
|
||||
|
||||
pub fn serialize<S>(value: &Amount, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -13,6 +13,9 @@ use xmr_btc::{alice, bob, monero};
|
||||
/// Time to wait for a response back once we send a request.
|
||||
pub const TIMEOUT: u64 = 3600; // One hour.
|
||||
|
||||
// TODO: Think about whether there is a better way to do this, e.g., separate
|
||||
// Codec for each Message and a macro that implements them.
|
||||
|
||||
/// Messages Bob sends to Alice.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
|
@ -14,6 +14,8 @@ use libp2p::{
|
||||
yamux, PeerId,
|
||||
};
|
||||
|
||||
// TOOD: Add the tor transport builder.
|
||||
|
||||
/// Builds a libp2p transport with the following features:
|
||||
/// - TcpConnection
|
||||
/// - DNS name resolution
|
||||
|
Loading…
Reference in New Issue
Block a user