mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-25 02:09:26 -04:00
add logs command to asb
This commit is contained in:
parent
ab782cf817
commit
6923ac141f
@ -41,6 +41,17 @@ where
|
|||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::History,
|
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 {
|
RawCommand::WithdrawBtc { amount, address } => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
@ -197,6 +208,10 @@ pub enum Command {
|
|||||||
},
|
},
|
||||||
History,
|
History,
|
||||||
Config,
|
Config,
|
||||||
|
Logs {
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
redact: bool,
|
||||||
|
},
|
||||||
WithdrawBtc {
|
WithdrawBtc {
|
||||||
amount: Option<Amount>,
|
amount: Option<Amount>,
|
||||||
address: Address,
|
address: Address,
|
||||||
@ -270,6 +285,16 @@ pub enum RawCommand {
|
|||||||
},
|
},
|
||||||
#[structopt(about = "Prints swap-id and the state of each swap ever made.")]
|
#[structopt(about = "Prints swap-id and the state of each swap ever made.")]
|
||||||
History,
|
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")]
|
#[structopt(about = "Prints the current config")]
|
||||||
Config,
|
Config,
|
||||||
#[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")]
|
#[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")]
|
||||||
|
@ -20,6 +20,7 @@ use libp2p::swarm::AddressScore;
|
|||||||
use libp2p::Swarm;
|
use libp2p::Swarm;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fs::read_dir;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use structopt::clap;
|
use structopt::clap;
|
||||||
@ -29,7 +30,7 @@ use swap::asb::config::{
|
|||||||
initial_setup, query_user_for_initial_config, read_config, Config, ConfigNotInitialized,
|
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::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::database::{open_db, AccessMode};
|
||||||
use swap::fs::system_data_dir;
|
use swap::fs::system_data_dir;
|
||||||
use swap::network::rendezvous::XmrBtcNamespace;
|
use swap::network::rendezvous::XmrBtcNamespace;
|
||||||
@ -38,6 +39,8 @@ use swap::protocol::alice::{run, AliceState};
|
|||||||
use swap::seed::Seed;
|
use swap::seed::Seed;
|
||||||
use swap::tor::AuthenticatedClient;
|
use swap::tor::AuthenticatedClient;
|
||||||
use swap::{asb, bitcoin, kraken, monero, tor};
|
use swap::{asb, bitcoin, kraken, monero, tor};
|
||||||
|
use tokio::fs::File;
|
||||||
|
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||||
use tracing_subscriber::filter::LevelFilter;
|
use tracing_subscriber::filter::LevelFilter;
|
||||||
|
|
||||||
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||||
@ -245,6 +248,31 @@ async fn main() -> Result<()> {
|
|||||||
let config_json = serde_json::to_string_pretty(&config)?;
|
let config_json = serde_json::to_string_pretty(&config)?;
|
||||||
println!("{}", config_json);
|
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 } => {
|
Command::WithdrawBtc { amount, address } => {
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use proptest::prelude::*;
|
|||||||
|
|
||||||
pub mod ecdsa_fun {
|
pub mod ecdsa_fun {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ecdsa_fun::fun::{Point, Scalar, G};
|
use ::ecdsa_fun::fun::{Point, Scalar, G};
|
||||||
|
|
||||||
pub fn point() -> impl Strategy<Value = Point> {
|
pub fn point() -> impl Strategy<Value = Point> {
|
||||||
scalar().prop_map(|mut scalar| Point::even_y_from_scalar_mul(G, &mut scalar).normalize())
|
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 {
|
pub mod bitcoin {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bitcoin::util::bip32::ExtendedPrivKey;
|
use ::bitcoin::util::bip32::ExtendedPrivKey;
|
||||||
use bitcoin::Network;
|
use ::bitcoin::Network;
|
||||||
|
|
||||||
pub fn extended_priv_key() -> impl Strategy<Value = ExtendedPrivKey> {
|
pub fn extended_priv_key() -> impl Strategy<Value = ExtendedPrivKey> {
|
||||||
prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| {
|
prop::array::uniform8(0..255u8).prop_filter_map("invalid secret key generated", |bytes| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user