Properly format output of commands history, config, balance and list-sellers using tracing

This commit is contained in:
binarybaron 2021-12-07 15:51:29 +01:00
parent 490c1d2ec1
commit e03865e172
2 changed files with 53 additions and 32 deletions

View File

@ -138,40 +138,38 @@ async fn main() -> Result<()> {
} }
} }
Command::History => { Command::History => {
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
let db = open_db(data_dir.join("sqlite")).await?; let db = open_db(data_dir.join("sqlite")).await?;
let mut table = Table::new(); let swaps = db.all().await?;
table.set_header(vec!["SWAP ID", "STATE"]); if json {
for (swap_id, state) in swaps {
let state: BobState = state.try_into()?;
tracing::info!(swap_id=%swap_id.to_string(), state=%state.to_string(), "Read swap state from database");
}
} else {
let mut table = Table::new();
for (swap_id, state) in db.all().await? { table.set_header(vec!["SWAP ID", "STATE"]);
let state: BobState = state.try_into()?;
table.add_row(vec![swap_id.to_string(), state.to_string()]); for (swap_id, state) in swaps {
let state: BobState = state.try_into()?;
table.add_row(vec![swap_id.to_string(), state.to_string()]);
}
println!("{}", table);
} }
println!("{}", table);
} }
Command::Config => { Command::Config => {
println!("Data directory: {}", data_dir.display()); cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
println!(
"Log files locations: {}", tracing::info!(path=%data_dir.display(), "Data directory");
format!("{}/wallet", data_dir.display()) tracing::info!(path=%format!("{}/logs", data_dir.display()), "Log files directory");
); tracing::info!(path=%format!("{}/sqlite", data_dir.display()), "Sqlite file location");
println!( tracing::info!(path=%format!("{}/seed.pem", data_dir.display()), "Seed file location");
"Sqlite file location: {}", tracing::info!(path=%format!("{}/monero", data_dir.display()), "Monero-wallet-rpc directory");
format!("{}/sqlite", data_dir.display()) tracing::info!(path=%format!("{}/wallet", data_dir.display()), "Internal bitcoin wallet directory");
);
println!(
"Seed file location: {}",
format!("{}/seed.pem", data_dir.display())
);
println!(
"Monero-wallet-rpc location: {}",
format!("{}/monero", data_dir.display())
);
println!(
"Internal bitcoin wallet location: {}",
format!("{}/wallet", data_dir.display())
);
} }
Command::WithdrawBtc { Command::WithdrawBtc {
bitcoin_electrum_rpc_url, bitcoin_electrum_rpc_url,
@ -225,7 +223,10 @@ async fn main() -> Result<()> {
.await?; .await?;
let bitcoin_balance = bitcoin_wallet.balance().await?; let bitcoin_balance = bitcoin_wallet.balance().await?;
println!("Bitcoin balance is {}", bitcoin_balance); tracing::info!(
balance = %bitcoin_balance,
"Checked Bitcoin balance",
);
} }
Command::Resume { Command::Resume {
swap_id, swap_id,
@ -359,7 +360,25 @@ async fn main() -> Result<()> {
if json { if json {
for seller in sellers { for seller in sellers {
println!("{}", serde_json::to_string(&seller)?); match seller.status {
SellerStatus::Online(quote) => {
tracing::info!(
price = %quote.price.to_string(),
min_quantity = %quote.min_quantity.to_string(),
max_quantity = %quote.max_quantity.to_string(),
status = "Online",
address = %seller.multiaddr.to_string(),
"Fetched peer status"
);
}
SellerStatus::Unreachable => {
tracing::info!(
status = "Unreachable",
address = %seller.multiaddr.to_string(),
"Fetched peer status"
);
}
}
} }
} else { } else {
let mut table = Table::new(); let mut table = Table::new();
@ -404,6 +423,8 @@ async fn main() -> Result<()> {
bitcoin_electrum_rpc_url, bitcoin_electrum_rpc_url,
bitcoin_target_block, bitcoin_target_block,
} => { } => {
cli::tracing::init(debug, json, data_dir.join("logs"), None)?;
let seed = Seed::from_file_or_generate(data_dir.as_path()) let seed = Seed::from_file_or_generate(data_dir.as_path())
.context("Failed to read in seed file")?; .context("Failed to read in seed file")?;
let bitcoin_wallet = init_bitcoin_wallet( let bitcoin_wallet = init_bitcoin_wallet(
@ -415,7 +436,7 @@ async fn main() -> Result<()> {
) )
.await?; .await?;
let wallet_export = bitcoin_wallet.wallet_export("cli").await?; let wallet_export = bitcoin_wallet.wallet_export("cli").await?;
println!("{}", wallet_export.to_string()) tracing::info!(descriptor=%wallet_export.to_string(), "Exported bitcoin wallet");
} }
}; };
Ok(()) Ok(())

View File

@ -200,7 +200,7 @@ impl EventLoop {
for registration in registrations { for registration in registrations {
let peer = registration.record.peer_id(); let peer = registration.record.peer_id();
for address in registration.record.addresses() { for address in registration.record.addresses() {
tracing::info!("Discovered peer {} at {}", peer, address); tracing::info!(peer_id=%peer, address=%address, "Discovered peer");
let p2p_suffix = Protocol::P2p(*peer.as_ref()); let p2p_suffix = Protocol::P2p(*peer.as_ref());
let _address_with_p2p = if !address let _address_with_p2p = if !address