mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-24 14:15:55 -04:00
fix: asb tracing, remove disable-timespamps option
This commit is contained in:
parent
fdd7d305b9
commit
defc94d0b7
4 changed files with 50 additions and 92 deletions
|
@ -19,7 +19,6 @@ where
|
||||||
let args = RawArguments::from_clap(&matches);
|
let args = RawArguments::from_clap(&matches);
|
||||||
|
|
||||||
let json = args.json;
|
let json = args.json;
|
||||||
let disable_timestamp = args.disable_timestamp;
|
|
||||||
let testnet = args.testnet;
|
let testnet = args.testnet;
|
||||||
let config = args.config;
|
let config = args.config;
|
||||||
let command: RawCommand = args.cmd;
|
let command: RawCommand = args.cmd;
|
||||||
|
@ -28,7 +27,6 @@ where
|
||||||
RawCommand::Start { resume_only } => Arguments {
|
RawCommand::Start { resume_only } => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Start { resume_only },
|
cmd: Command::Start { resume_only },
|
||||||
|
@ -36,7 +34,6 @@ where
|
||||||
RawCommand::History => Arguments {
|
RawCommand::History => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::History,
|
cmd: Command::History,
|
||||||
|
@ -49,7 +46,6 @@ where
|
||||||
} => Arguments {
|
} => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Logs {
|
cmd: Command::Logs {
|
||||||
|
@ -62,7 +58,6 @@ where
|
||||||
RawCommand::WithdrawBtc { amount, address } => Arguments {
|
RawCommand::WithdrawBtc { amount, address } => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::WithdrawBtc {
|
cmd: Command::WithdrawBtc {
|
||||||
|
@ -73,7 +68,6 @@ where
|
||||||
RawCommand::Balance => Arguments {
|
RawCommand::Balance => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Balance,
|
cmd: Command::Balance,
|
||||||
|
@ -81,7 +75,6 @@ where
|
||||||
RawCommand::Config => Arguments {
|
RawCommand::Config => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Config,
|
cmd: Command::Config,
|
||||||
|
@ -89,7 +82,6 @@ where
|
||||||
RawCommand::ExportBitcoinWallet => Arguments {
|
RawCommand::ExportBitcoinWallet => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::ExportBitcoinWallet,
|
cmd: Command::ExportBitcoinWallet,
|
||||||
|
@ -100,7 +92,6 @@ where
|
||||||
}) => Arguments {
|
}) => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Redeem {
|
cmd: Command::Redeem {
|
||||||
|
@ -114,7 +105,6 @@ where
|
||||||
}) => Arguments {
|
}) => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Cancel { swap_id },
|
cmd: Command::Cancel { swap_id },
|
||||||
|
@ -124,7 +114,6 @@ where
|
||||||
}) => Arguments {
|
}) => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Refund { swap_id },
|
cmd: Command::Refund { swap_id },
|
||||||
|
@ -134,7 +123,6 @@ where
|
||||||
}) => Arguments {
|
}) => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Punish { swap_id },
|
cmd: Command::Punish { swap_id },
|
||||||
|
@ -142,7 +130,6 @@ where
|
||||||
RawCommand::ManualRecovery(ManualRecovery::SafelyAbort { swap_id }) => Arguments {
|
RawCommand::ManualRecovery(ManualRecovery::SafelyAbort { swap_id }) => Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path: config_path(config, testnet)?,
|
config_path: config_path(config, testnet)?,
|
||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::SafelyAbort { swap_id },
|
cmd: Command::SafelyAbort { swap_id },
|
||||||
|
@ -202,7 +189,6 @@ pub struct BitcoinAddressNetworkMismatch {
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
pub testnet: bool,
|
pub testnet: bool,
|
||||||
pub json: bool,
|
pub json: bool,
|
||||||
pub disable_timestamp: bool,
|
|
||||||
pub config_path: PathBuf,
|
pub config_path: PathBuf,
|
||||||
pub env_config: env::Config,
|
pub env_config: env::Config,
|
||||||
pub cmd: Command,
|
pub cmd: Command,
|
||||||
|
@ -414,7 +400,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Start { resume_only: false },
|
cmd: Command::Start { resume_only: false },
|
||||||
|
@ -432,7 +417,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::History,
|
cmd: Command::History,
|
||||||
|
@ -450,7 +434,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Balance,
|
cmd: Command::Balance,
|
||||||
|
@ -472,7 +455,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::WithdrawBtc {
|
cmd: Command::WithdrawBtc {
|
||||||
|
@ -499,7 +481,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Cancel {
|
cmd: Command::Cancel {
|
||||||
|
@ -525,7 +506,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Refund {
|
cmd: Command::Refund {
|
||||||
|
@ -551,7 +531,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Punish {
|
cmd: Command::Punish {
|
||||||
|
@ -577,7 +556,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::SafelyAbort {
|
cmd: Command::SafelyAbort {
|
||||||
|
@ -597,7 +575,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::Start { resume_only: false },
|
cmd: Command::Start { resume_only: false },
|
||||||
|
@ -615,7 +592,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::History,
|
cmd: Command::History,
|
||||||
|
@ -633,7 +609,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::Balance,
|
cmd: Command::Balance,
|
||||||
|
@ -657,7 +632,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::WithdrawBtc {
|
cmd: Command::WithdrawBtc {
|
||||||
|
@ -684,7 +658,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::Cancel {
|
cmd: Command::Cancel {
|
||||||
|
@ -711,7 +684,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::Refund {
|
cmd: Command::Refund {
|
||||||
|
@ -738,7 +710,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::Punish {
|
cmd: Command::Punish {
|
||||||
|
@ -765,7 +736,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: true,
|
testnet: true,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: false,
|
|
||||||
config_path: default_testnet_conf_path,
|
config_path: default_testnet_conf_path,
|
||||||
env_config: testnet_env_config,
|
env_config: testnet_env_config,
|
||||||
cmd: Command::SafelyAbort {
|
cmd: Command::SafelyAbort {
|
||||||
|
@ -785,7 +755,6 @@ mod tests {
|
||||||
let expected_args = Arguments {
|
let expected_args = Arguments {
|
||||||
testnet: false,
|
testnet: false,
|
||||||
json: false,
|
json: false,
|
||||||
disable_timestamp: true,
|
|
||||||
config_path: default_mainnet_conf_path,
|
config_path: default_mainnet_conf_path,
|
||||||
env_config: mainnet_env_config,
|
env_config: mainnet_env_config,
|
||||||
cmd: Command::Start { resume_only: false },
|
cmd: Command::Start { resume_only: false },
|
||||||
|
|
|
@ -5,75 +5,57 @@ use tracing_subscriber::filter::LevelFilter;
|
||||||
use tracing_subscriber::fmt::time::UtcTime;
|
use tracing_subscriber::fmt::time::UtcTime;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::fmt;
|
use tracing_subscriber::fmt;
|
||||||
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
|
/// Output formats for logging messages.
|
||||||
|
pub enum Format {
|
||||||
|
/// Standard, human readable format.
|
||||||
|
Raw,
|
||||||
|
/// Machine readable format.
|
||||||
|
Json,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
level: LevelFilter,
|
level: LevelFilter,
|
||||||
json_format: bool,
|
format: Format,
|
||||||
timestamp: bool,
|
|
||||||
dir: impl AsRef<Path>,
|
dir: impl AsRef<Path>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if level == LevelFilter::OFF {
|
if level == LevelFilter::OFF {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_terminal = atty::is(atty::Stream::Stderr);
|
// file logger will always write in JSON format and with timestamps
|
||||||
|
|
||||||
// File logger will always write in JSON format and with timestamps
|
|
||||||
let file_appender = tracing_appender::rolling::never(dir.as_ref(), "swap-all.log");
|
let file_appender = tracing_appender::rolling::never(dir.as_ref(), "swap-all.log");
|
||||||
|
|
||||||
let file_layer = fmt::layer()
|
let file_layer = fmt::layer()
|
||||||
.with_writer(std::io::stdout)
|
.with_writer(file_appender)
|
||||||
.with_ansi(false)
|
.with_ansi(false)
|
||||||
.with_timer(UtcTime::rfc_3339())
|
.with_timer(UtcTime::rfc_3339())
|
||||||
.with_target(false)
|
.with_target(false)
|
||||||
.json();
|
.json();
|
||||||
|
|
||||||
// Terminal logger
|
// terminal logger
|
||||||
let terminal_layer_base = fmt::layer()
|
let is_terminal = atty::is(atty::Stream::Stderr);
|
||||||
|
let terminal_layer = fmt::layer()
|
||||||
.with_writer(std::io::stdout)
|
.with_writer(std::io::stdout)
|
||||||
.with_ansi(is_terminal)
|
.with_ansi(is_terminal)
|
||||||
.with_timer(UtcTime::rfc_3339())
|
.with_timer(UtcTime::rfc_3339())
|
||||||
.with_target(false);
|
.with_target(false);
|
||||||
|
|
||||||
// Since tracing is stupid, and makes each option return a different type
|
// combine the layers and start logging, format with json if specified
|
||||||
// but also doesn't allow dynamic dispatch we have to use this beauty
|
if let Format::Json = format {
|
||||||
let (
|
tracing_subscriber::registry()
|
||||||
a,
|
.with(file_layer)
|
||||||
b,
|
.with(terminal_layer.json())
|
||||||
c,
|
.init();
|
||||||
d
|
} else {
|
||||||
) = match (json_format, timestamp) {
|
tracing_subscriber::registry()
|
||||||
(true, true) => (Some(terminal_layer_base.json()), None, None, None),
|
.with(file_layer)
|
||||||
(true, false) => (None, Some(terminal_layer_base.json().without_time()), None, None),
|
.with(terminal_layer)
|
||||||
(false, true) => (None, None, Some(terminal_layer_base), None),
|
.init();
|
||||||
(false, false) => (None, None, None, Some(terminal_layer_base.without_time())),
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let combined_subscriber = tracing_subscriber::registry()
|
|
||||||
.with(file_layer)
|
|
||||||
.with(a);
|
|
||||||
|
|
||||||
combined_subscriber.init();
|
|
||||||
|
|
||||||
// let builder = FmtSubscriber::builder()
|
// now we can use the tracing macros to log messages
|
||||||
// .with_env_filter(format!("asb={},swap={}", level, level))
|
|
||||||
// .with_writer(async_file_appender.and(std::io::stderr))
|
|
||||||
// .with_ansi(is_terminal)
|
|
||||||
// .with_timer(UtcTime::rfc_3339())
|
|
||||||
// .with_target(false);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// match (json_format, timestamp) {
|
|
||||||
// (true, true) => builder.json().init(),
|
|
||||||
// (true, false) => builder.json().without_time().init(),
|
|
||||||
// (false, true) => builder.init(),
|
|
||||||
// (false, false) => builder.without_time().init(),
|
|
||||||
// }
|
|
||||||
|
|
||||||
tracing::info!(%level, "Initialized tracing");
|
tracing::info!(%level, "Initialized tracing");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -18,6 +18,7 @@ use libp2p::core::multiaddr::Protocol;
|
||||||
use libp2p::core::Multiaddr;
|
use libp2p::core::Multiaddr;
|
||||||
use libp2p::swarm::AddressScore;
|
use libp2p::swarm::AddressScore;
|
||||||
use libp2p::Swarm;
|
use libp2p::Swarm;
|
||||||
|
use swap::asb::tracing::Format;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fs::read_dir;
|
use std::fs::read_dir;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
@ -47,39 +48,39 @@ const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
// parse cli arguments
|
||||||
let Arguments {
|
let Arguments {
|
||||||
testnet,
|
testnet,
|
||||||
json,
|
json,
|
||||||
disable_timestamp,
|
|
||||||
config_path,
|
config_path,
|
||||||
env_config,
|
env_config,
|
||||||
cmd,
|
cmd,
|
||||||
} = match parse_args(env::args_os()) {
|
} = match parse_args(env::args_os()) {
|
||||||
Ok(args) => args,
|
Ok(args) => args,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
// make sure to display the clap error message it exists
|
||||||
if let Some(clap_err) = e.downcast_ref::<clap::Error>() {
|
if let Some(clap_err) = e.downcast_ref::<clap::Error>() {
|
||||||
match clap_err.kind {
|
if let ErrorKind::HelpDisplayed | ErrorKind::VersionDisplayed = clap_err.kind {
|
||||||
ErrorKind::HelpDisplayed | ErrorKind::VersionDisplayed => {
|
println!("{}", clap_err.message);
|
||||||
println!("{}", clap_err.message);
|
std::process::exit(0);
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
bail!(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bail!(e);
|
bail!(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// warn if we're not on the latest version
|
||||||
if let Err(e) = check_latest_version(env!("CARGO_PKG_VERSION")).await {
|
if let Err(e) = check_latest_version(env!("CARGO_PKG_VERSION")).await {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize tracing
|
||||||
|
let format = if json { Format::Json } else { Format::Raw };
|
||||||
let log_dir = system_data_dir()?.join("logs");
|
let log_dir = system_data_dir()?.join("logs");
|
||||||
asb::tracing::init(LevelFilter::DEBUG, json, !disable_timestamp, log_dir)
|
asb::tracing::init(LevelFilter::DEBUG, format, log_dir)
|
||||||
.expect("initialize tracing");
|
.expect("initialize tracing");
|
||||||
|
|
||||||
|
// read config from the specified path
|
||||||
let config = match read_config(config_path.clone())? {
|
let config = match read_config(config_path.clone())? {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(ConfigNotInitialized {}) => {
|
Err(ConfigNotInitialized {}) => {
|
||||||
|
@ -88,6 +89,7 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// check for conflicting env / config values
|
||||||
if config.monero.network != env_config.monero_network {
|
if config.monero.network != env_config.monero_network {
|
||||||
bail!(format!(
|
bail!(format!(
|
||||||
"Expected monero network in config file to be {:?} but was {:?}",
|
"Expected monero network in config file to be {:?} but was {:?}",
|
||||||
|
@ -114,6 +116,7 @@ async fn main() -> Result<()> {
|
||||||
rendezvous_addrs.sort();
|
rendezvous_addrs.sort();
|
||||||
rendezvous_addrs.dedup();
|
rendezvous_addrs.dedup();
|
||||||
let new_len = rendezvous_addrs.len();
|
let new_len = rendezvous_addrs.len();
|
||||||
|
|
||||||
if new_len < prev_len {
|
if new_len < prev_len {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"`rendezvous_point` config has {} duplicate entries, they are being ignored.",
|
"`rendezvous_point` config has {} duplicate entries, they are being ignored.",
|
||||||
|
@ -121,9 +124,12 @@ async fn main() -> Result<()> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize monero wallet
|
||||||
let monero_wallet = init_monero_wallet(&config, env_config).await?;
|
let monero_wallet = init_monero_wallet(&config, env_config).await?;
|
||||||
let monero_address = monero_wallet.get_main_address();
|
let monero_address = monero_wallet.get_main_address();
|
||||||
tracing::info!(%monero_address, "Monero wallet address");
|
tracing::info!(%monero_address, "Monero wallet address");
|
||||||
|
|
||||||
|
// check monero balance
|
||||||
let monero = monero_wallet.get_balance().await?;
|
let monero = monero_wallet.get_balance().await?;
|
||||||
match (monero.balance, monero.unlocked_balance) {
|
match (monero.balance, monero.unlocked_balance) {
|
||||||
(0, _) => {
|
(0, _) => {
|
||||||
|
@ -146,6 +152,7 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init bitcoin wallet
|
||||||
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
||||||
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
||||||
tracing::info!(%bitcoin_balance, "Bitcoin wallet balance");
|
tracing::info!(%bitcoin_balance, "Bitcoin wallet balance");
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn is_latest_version(current: &str, latest: &str) -> bool {
|
||||||
macro_rules! regex_find_placeholders {
|
macro_rules! regex_find_placeholders {
|
||||||
($pattern:expr, $create_placeholder:expr, $replacements:expr, $input:expr) => {{
|
($pattern:expr, $create_placeholder:expr, $replacements:expr, $input:expr) => {{
|
||||||
// compile the regex pattern
|
// compile the regex pattern
|
||||||
let regex = once_cell::sync::Lazy::new(|| {
|
static REGEX: once_cell::sync::Lazy<regex::Regex> = once_cell::sync::Lazy::new(|| {
|
||||||
regex::Regex::new($pattern).expect("invalid regex pattern")
|
regex::Regex::new($pattern).expect("invalid regex pattern")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ macro_rules! regex_find_placeholders {
|
||||||
|
|
||||||
// for every matched address check whether we already found it
|
// for every matched address check whether we already found it
|
||||||
// and if we didn't, generate a placeholder for it
|
// and if we didn't, generate a placeholder for it
|
||||||
for address in regex.find_iter($input) {
|
for address in REGEX.find_iter($input) {
|
||||||
if !$replacements.contains_key(address.as_str()) {
|
if !$replacements.contains_key(address.as_str()) {
|
||||||
$replacements.insert(address.as_str().to_owned(), $create_placeholder(counter));
|
$replacements.insert(address.as_str().to_owned(), $create_placeholder(counter));
|
||||||
counter += 1;
|
counter += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue