Print swap history on --history flag

This commit is contained in:
Lucas Soriano del Pino 2020-11-03 16:44:04 +11:00 committed by rishflab
parent ecbfed9c11
commit ac2cfd7f65
4 changed files with 48 additions and 8 deletions

View File

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

View File

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

View File

@ -1,6 +1,6 @@
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::path::Path; use std::{fmt::Display, path::Path};
use uuid::Uuid; use uuid::Uuid;
use xmr_btc::{alice, bob, monero, serde::monero_private_key}; 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); pub struct Database(sled::Db);
impl Database { impl Database {

View File

@ -8,6 +8,11 @@ mod e2e_test {
use swap::{alice, bob, network::transport::build}; use swap::{alice, bob, network::transport::build};
use testcontainers::clients::Cli; 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] #[tokio::test]
async fn swap() { async fn swap() {
let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9876" let alice_multiaddr: Multiaddr = "/ip4/127.0.0.1/tcp/9876"