Re-introduce history command

This commit is contained in:
Lucas Soriano del Pino 2020-11-05 16:55:30 +11:00 committed by rishflab
parent 0f1a77fa21
commit 09773dd15b
3 changed files with 22 additions and 4 deletions

4
.gitignore vendored
View File

@ -1,4 +1,3 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust,clion+all,emacs
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,clion+all,emacs
@ -154,4 +153,7 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# sled DB directory generated during local development
.swap-db/
# End of https://www.toptal.com/developers/gitignore/api/rust,clion+all,emacs

View File

@ -33,4 +33,5 @@ pub enum Options {
#[structopt(long = "tor")]
tor: bool,
},
History,
}

View File

@ -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::{
@ -27,9 +28,11 @@ use swap::{
network::transport::{build, build_tor, SwapTransport},
Cmd, Rsp, SwapAmounts,
};
use tempfile::tempdir;
use tracing::info;
#[macro_use]
extern crate prettytable;
mod cli;
mod trace;
@ -44,8 +47,8 @@ async fn main() -> Result<()> {
trace::init_tracing(LevelFilter::Debug)?;
let db_dir = tempdir()?;
let db = Database::open(db_dir.path()).unwrap();
// This currently creates the directory if it's not there in the first place
let db = Database::open(std::path::Path::new("./.swap-db/")).unwrap();
match opt {
Options::Alice {
@ -130,6 +133,18 @@ async fn main() -> Result<()> {
)
.await?;
}
Options::History => {
let mut table = Table::new();
table.add_row(row!["SWAP ID", "STATE"]);
for (swap_id, state) in db.all()? {
table.add_row(row![swap_id, state]);
}
// Print the table to stdout
table.printstd();
}
}
Ok(())