Don't import tracing's macros

Log statements end up getting changed constantly and having to clean
up imports after that is annoying, for example, if the last `info!`
in a file disappears, you end up with an unused import warning.

Fully qualifying tracing's macros prevents that and also communicates
clearly that we are using tracing and not log.
pull/607/head
Thomas Eizinger 3 years ago committed by Daniel Karzel
parent fa1a5e6efb
commit 78480547d5
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E

@ -14,7 +14,6 @@ use std::ffi::OsStr;
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
use tracing::info;
use url::Url; use url::Url;
pub trait GetDefaults { pub trait GetDefaults {
@ -178,7 +177,7 @@ pub struct ConfigNotInitialized {}
pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotInitialized>> { pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotInitialized>> {
if config_path.exists() { if config_path.exists() {
info!( tracing::info!(
path = %config_path.display(), path = %config_path.display(),
"Using config file at", "Using config file at",
); );
@ -198,7 +197,7 @@ pub fn initial_setup(config_path: PathBuf, config: Config) -> Result<()> {
ensure_directory_exists(config_path.as_path())?; ensure_directory_exists(config_path.as_path())?;
fs::write(&config_path, toml)?; fs::write(&config_path, toml)?;
info!( tracing::info!(
path = %config_path.as_path().display(), path = %config_path.as_path().display(),
"Initial setup complete, config file created", "Initial setup complete, config file created",
); );

@ -36,7 +36,6 @@ use swap::protocol::alice::run;
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 tracing::{debug, info, warn};
use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::filter::LevelFilter;
const DEFAULT_WALLET_NAME: &str = "asb-wallet"; const DEFAULT_WALLET_NAME: &str = "asb-wallet";
@ -90,7 +89,7 @@ async fn main() -> Result<()> {
)); ));
} }
info!( tracing::info!(
db_folder = %config.data.dir.display(), db_folder = %config.data.dir.display(),
"Database and Seed will be stored in", "Database and Seed will be stored in",
); );
@ -110,17 +109,17 @@ async fn main() -> Result<()> {
let monero_wallet = init_monero_wallet(&config, env_config).await?; let monero_wallet = init_monero_wallet(&config, env_config).await?;
let bitcoin_balance = bitcoin_wallet.balance().await?; let bitcoin_balance = bitcoin_wallet.balance().await?;
info!(%bitcoin_balance, "Initialized Bitcoin wallet"); tracing::info!(%bitcoin_balance, "Initialized Bitcoin wallet");
let monero_balance = monero_wallet.get_balance().await?; let monero_balance = monero_wallet.get_balance().await?;
if monero_balance == Amount::ZERO { if monero_balance == Amount::ZERO {
let monero_address = monero_wallet.get_main_address(); let monero_address = monero_wallet.get_main_address();
warn!( tracing::warn!(
%monero_address, %monero_address,
"The Monero balance is 0, make sure to deposit funds at", "The Monero balance is 0, make sure to deposit funds at",
) )
} else { } else {
info!(%monero_balance, "Initialized Monero wallet"); tracing::info!(%monero_balance, "Initialized Monero wallet");
} }
let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?; let kraken_price_updates = kraken::connect(config.maker.price_ticker_ws_url.clone())?;
@ -314,7 +313,7 @@ async fn init_bitcoin_wallet(
seed: &Seed, seed: &Seed,
env_config: swap::env::Config, env_config: swap::env::Config,
) -> Result<bitcoin::Wallet> { ) -> Result<bitcoin::Wallet> {
debug!("Opening Bitcoin wallet"); tracing::debug!("Opening Bitcoin wallet");
let wallet_dir = config.data.dir.join("wallet"); let wallet_dir = config.data.dir.join("wallet");
let wallet = bitcoin::Wallet::new( let wallet = bitcoin::Wallet::new(
@ -336,7 +335,7 @@ async fn init_monero_wallet(
config: &Config, config: &Config,
env_config: swap::env::Config, env_config: swap::env::Config,
) -> Result<monero::Wallet> { ) -> Result<monero::Wallet> {
debug!("Opening Monero wallet"); tracing::debug!("Opening Monero wallet");
let wallet = monero::Wallet::open_or_create( let wallet = monero::Wallet::open_or_create(
config.monero.wallet_rpc_url.clone(), config.monero.wallet_rpc_url.clone(),
DEFAULT_WALLET_NAME.to_string(), DEFAULT_WALLET_NAME.to_string(),

@ -34,7 +34,6 @@ use swap::protocol::bob;
use swap::protocol::bob::Swap; use swap::protocol::bob::Swap;
use swap::seed::Seed; use swap::seed::Seed;
use swap::{bitcoin, cli, monero}; use swap::{bitcoin, cli, monero};
use tracing::{debug, error, info, warn};
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
@ -111,7 +110,7 @@ async fn main() -> Result<()> {
) )
.await?; .await?;
info!(%amount, %fees, %swap_id, "Swapping"); tracing::info!(%amount, %fees, %swap_id, "Swapping");
db.insert_peer_id(swap_id, seller_peer_id).await?; db.insert_peer_id(swap_id, seller_peer_id).await?;
db.insert_monero_address(swap_id, monero_receive_address) db.insert_monero_address(swap_id, monero_receive_address)
@ -242,9 +241,9 @@ async fn main() -> Result<()> {
match cancel { match cancel {
Ok((txid, _)) => { Ok((txid, _)) => {
debug!("Cancel transaction successfully published with id {}", txid) tracing::debug!("Cancel transaction successfully published with id {}", txid)
} }
Err(cli::cancel::Error::CancelTimelockNotExpiredYet) => error!( Err(cli::cancel::Error::CancelTimelockNotExpiredYet) => tracing::error!(
"The Cancel Transaction cannot be published yet, because the timelock has not expired. Please try again later" "The Cancel Transaction cannot be published yet, because the timelock has not expired. Please try again later"
), ),
} }
@ -395,9 +394,9 @@ where
TS: Future<Output = Result<()>>, TS: Future<Output = Result<()>>,
FS: Fn() -> TS, FS: Fn() -> TS,
{ {
debug!("Requesting quote"); tracing::debug!("Requesting quote");
let bid_quote = bid_quote.await?; let bid_quote = bid_quote.await?;
info!( tracing::info!(
price = %bid_quote.price, price = %bid_quote.price,
minimum_amount = %bid_quote.min_quantity, minimum_amount = %bid_quote.min_quantity,
maximum_amount = %bid_quote.max_quantity, maximum_amount = %bid_quote.max_quantity,
@ -415,7 +414,7 @@ where
eprintln!("{}", qr_code(&deposit_address)?); eprintln!("{}", qr_code(&deposit_address)?);
} }
info!( tracing::info!(
%deposit_address, %deposit_address,
%max_giveable, %max_giveable,
%minimum_amount, %minimum_amount,

@ -8,7 +8,6 @@ use crate::{bitcoin, database, monero};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use tokio::select; use tokio::select;
use tokio::time::timeout; use tokio::time::timeout;
use tracing::{error, info, warn};
use uuid::Uuid; use uuid::Uuid;
pub async fn run<LR>(swap: Swap, rate_service: LR) -> Result<AliceState> pub async fn run<LR>(swap: Swap, rate_service: LR) -> Result<AliceState>
@ -66,7 +65,7 @@ where
.latest_rate() .latest_rate()
.map_or("NaN".to_string(), |rate| format!("{}", rate)); .map_or("NaN".to_string(), |rate| format!("{}", rate));
info!(%state, %rate, "Advancing state"); tracing::info!(%state, %rate, "Advancing state");
Ok(match state { Ok(match state {
AliceState::Started { state3 } => { AliceState::Started { state3 } => {
@ -78,7 +77,7 @@ where
.await .await
{ {
Err(_) => { Err(_) => {
info!( tracing::info!(
minutes = %env_config.bitcoin_lock_mempool_timeout.as_secs_f64() / 60.0, minutes = %env_config.bitcoin_lock_mempool_timeout.as_secs_f64() / 60.0,
"TxLock lock was not seen in mempool in time", "TxLock lock was not seen in mempool in time",
); );
@ -99,7 +98,7 @@ where
.await .await
{ {
Err(_) => { Err(_) => {
info!( tracing::info!(
confirmations_needed = %env_config.bitcoin_finality_confirmations, confirmations_needed = %env_config.bitcoin_finality_confirmations,
minutes = %env_config.bitcoin_lock_confirmed_timeout.as_secs_f64() / 60.0, minutes = %env_config.bitcoin_lock_confirmed_timeout.as_secs_f64() / 60.0,
"TxLock lock did not get enough confirmations in time", "TxLock lock did not get enough confirmations in time",
@ -204,7 +203,7 @@ where
} }
} }
enc_sig = event_loop_handle.recv_encrypted_signature() => { enc_sig = event_loop_handle.recv_encrypted_signature() => {
info!("Received encrypted signature"); tracing::info!("Received encrypted signature");
AliceState::EncSigLearned { AliceState::EncSigLearned {
monero_wallet_restore_blockheight, monero_wallet_restore_blockheight,
@ -232,7 +231,7 @@ where
} }
}, },
Err(error) => { Err(error) => {
error!( tracing::error!(
"Publishing the redeem transaction failed. Error {:#}", "Publishing the redeem transaction failed. Error {:#}",
error error
); );
@ -248,7 +247,7 @@ where
} }
}, },
Err(error) => { Err(error) => {
error!( tracing::error!(
"Constructing the redeem transaction failed. Attempting to wait for cancellation now. Error {:#}", error); "Constructing the redeem transaction failed. Attempting to wait for cancellation now. Error {:#}", error);
tx_lock_status tx_lock_status
.wait_until_confirmed_with(state3.cancel_timelock) .wait_until_confirmed_with(state3.cancel_timelock)
@ -361,7 +360,7 @@ where
match punish { match punish {
Ok(_) => AliceState::BtcPunished, Ok(_) => AliceState::BtcPunished,
Err(error) => { Err(error) => {
warn!( tracing::warn!(
"Falling back to refund because punish transaction failed. Error {:#}", "Falling back to refund because punish transaction failed. Error {:#}",
error error
); );

Loading…
Cancel
Save