Print swap history on --history flag

pull/36/head
Lucas Soriano del Pino 4 years ago committed by rishflab
parent ecbfed9c11
commit ac2cfd7f65

@ -21,6 +21,7 @@ libp2p-tokio-socks5 = "0.4"
log = { version = "0.4", features = ["serde"] }
monero = { version = "0.9", features = ["serde_support"] }
monero-harness = { path = "../monero-harness" }
prettytable-rs = "0.8"
rand = "0.7"
reqwest = { version = "0.10", default-features = false, features = ["socks"] }
serde = { version = "1", features = ["derive"] }

@ -16,6 +16,7 @@ use anyhow::Result;
use futures::{channel::mpsc, StreamExt};
use libp2p::Multiaddr;
use log::LevelFilter;
use prettytable::{row, Table};
use std::{io, io::Write, process, sync::Arc};
use structopt::StructOpt;
use swap::{
@ -30,6 +31,9 @@ use swap::{
use tempfile::tempdir;
use tracing::info;
#[macro_use]
extern crate prettytable;
mod cli;
mod trace;
@ -81,13 +85,7 @@ async fn main() -> Result<()> {
let monero_wallet = Arc::new(monero::Wallet::new(monerod_url));
let db = Database::open(db_dir.path()).unwrap();
swap_as_alice(
bitcoin_wallet,
monero_wallet,
db
listen_addr,
swap_as_alice(bitcoin_wallet, monero_wallet, dblisten_addr,
transport,
behaviour,
)

@ -1,6 +1,6 @@
use anyhow::{anyhow, bail, Context, Result};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::path::Path;
use std::{fmt::Display, path::Path};
use uuid::Uuid;
use xmr_btc::{alice, bob, monero, serde::monero_private_key};
@ -53,6 +53,42 @@ impl From<Bob> for Swap {
}
}
impl Display for Swap {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Swap::Alice(alice) => Display::fmt(alice, f),
Swap::Bob(bob) => Display::fmt(bob, f),
}
}
}
impl Display for Alice {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Alice::Handshaken(_) => f.write_str("Handshake complete"),
Alice::BtcLocked(_) => f.write_str("Bitcoin locked"),
Alice::XmrLocked(_) => f.write_str("Monero locked"),
Alice::BtcRedeemable { .. } => f.write_str("Bitcoin redeemable"),
Alice::BtcPunishable(_) => f.write_str("Bitcoin punishable"),
Alice::BtcRefunded { .. } => f.write_str("Monero refundable"),
Alice::SwapComplete => f.write_str("Swap complete"),
}
}
}
impl Display for Bob {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Bob::Handshaken(_) => f.write_str("Handshake complete"),
Bob::BtcLocked(_) | Bob::XmrLocked(_) | Bob::BtcRefundable(_) => {
f.write_str("Bitcoin refundable")
}
Bob::BtcRedeemed(_) => f.write_str("Monero redeemable"),
Bob::SwapComplete => f.write_str("Swap complete"),
}
}
}
pub struct Database(sled::Db);
impl Database {

@ -8,6 +8,11 @@ mod e2e_test {
use swap::{alice, bob, network::transport::build};
use testcontainers::clients::Cli;
// NOTE: For some reason running these tests overflows the stack. In order to
// mitigate this run them with:
//
// RUST_MIN_STACK=100000000 cargo test
#[tokio::test]
async fn swap() {
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9876"

Loading…
Cancel
Save