add logs command to asb

This commit is contained in:
Einliterflasche 2024-08-04 18:31:14 +02:00
parent ab782cf817
commit 6923ac141f
3 changed files with 57 additions and 4 deletions

View File

@ -41,6 +41,17 @@ where
env_config: env_config(testnet),
cmd: Command::History,
},
RawCommand::Logs { dir_path, redact } => Arguments {
testnet,
json,
disable_timestamp,
config_path: config_path(config, testnet)?,
env_config: env_config(testnet),
cmd: Command::Logs {
path: dir_path,
redact,
},
},
RawCommand::WithdrawBtc { amount, address } => Arguments {
testnet,
json,
@ -197,6 +208,10 @@ pub enum Command {
},
History,
Config,
Logs {
path: Option<PathBuf>,
redact: bool,
},
WithdrawBtc {
amount: Option<Amount>,
address: Address,
@ -270,6 +285,16 @@ pub enum RawCommand {
},
#[structopt(about = "Prints swap-id and the state of each swap ever made.")]
History,
#[structopt(about = "Prints all logging messages issued in the past.")]
Logs {
#[structopt(help = "Print the logs from this directory instead of the default one.")]
dir_path: Option<PathBuf>,
#[structopt(
help = "Redact swap-ids, Bitcoin and Monero addresses.",
long = "redact"
)]
redact: bool,
},
#[structopt(about = "Prints the current config")]
Config,
#[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")]

View File

@ -20,6 +20,7 @@ use libp2p::swarm::AddressScore;
use libp2p::Swarm;
use std::convert::TryInto;
use std::env;
use std::fs::read_dir;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use structopt::clap;
@ -29,7 +30,7 @@ use swap::asb::config::{
initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized,
};
use swap::asb::{cancel, punish, redeem, refund, safely_abort, EventLoop, Finality, KrakenRate};
use swap::common::check_latest_version;
use swap::common::{self, check_latest_version};
use swap::database::{open_db, AccessMode};
use swap::fs::system_data_dir;
use swap::network::rendezvous::XmrBtcNamespace;
@ -38,6 +39,8 @@ use swap::protocol::alice::{run, AliceState};
use swap::seed::Seed;
use swap::tor::AuthenticatedClient;
use swap::{asb, bitcoin, kraken, monero, tor};
use tokio::fs::File;
use tokio::io::{AsyncBufReadExt, BufReader};
use tracing_subscriber::filter::LevelFilter;
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
@ -245,6 +248,31 @@ async fn main() -> Result<()> {
let config_json = serde_json::to_string_pretty(&config)?;
println!("{}", config_json);
}
Command::Logs { path, redact } => {
// use provided directory of default one
let default_dir = system_data_dir()?.join("logs");
let logs_dir = path.unwrap_or(default_dir);
// go through each file and print it
let log_files = read_dir(&logs_dir)?;
for entry in log_files {
let file_name = entry?.path();
let file = File::open(&file_name).await?;
let buf_reader = BufReader::new(file);
let mut lines = buf_reader.lines();
println!("====reading log from file `{}`", &file_name.display());
// print each line, redacted if the flag is set
while let Some(line) = lines.next_line().await? {
let line = if redact { common::redact(&line) } else { line };
println!("{}", line);
}
println!("====no more log files found");
}
}
Command::WithdrawBtc { amount, address } => {
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

View File

@ -2,7 +2,7 @@ use proptest::prelude::*;
pub mod ecdsa_fun {
use super::*;
use ecdsa_fun::fun::{Point, Scalar, G};
use ::ecdsa_fun::fun::{Point, Scalar, G};
pub fn point() -> impl Strategy<Value = Point> {
scalar().prop_map(|mut scalar| Point::even_y_from_scalar_mul(G, &mut scalar).normalize())
@ -17,8 +17,8 @@ pub mod ecdsa_fun {
pub mod bitcoin {
use super::*;
use bitcoin::util::bip32::ExtendedPrivKey;
use bitcoin::Network;
use ::bitcoin::util::bip32::ExtendedPrivKey;
use ::bitcoin::Network;
pub fn extended_priv_key() -> impl Strategy<Value = ExtendedPrivKey> {
prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| {