mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-07-01 00:51:23 +00:00
CLI log statements to be more JSON friendly
Values to be logged as fields. Upon starting a swap we print the swap-id as well.
This commit is contained in:
parent
0187d9ef4f
commit
fb9fb21c2b
|
@ -100,6 +100,8 @@ async fn main() -> Result<()> {
|
||||||
.behaviour_mut()
|
.behaviour_mut()
|
||||||
.add_address(seller_peer_id, seller_addr);
|
.add_address(seller_peer_id, seller_addr);
|
||||||
|
|
||||||
|
let our_peer_id = swarm.local_peer_id();
|
||||||
|
tracing::debug!(peer_id = %our_peer_id, "Initializing network module");
|
||||||
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
let (event_loop, mut event_loop_handle) = EventLoop::new(
|
||||||
swap_id,
|
swap_id,
|
||||||
swarm,
|
swarm,
|
||||||
|
@ -110,7 +112,7 @@ async fn main() -> Result<()> {
|
||||||
let event_loop = tokio::spawn(event_loop.run());
|
let event_loop = tokio::spawn(event_loop.run());
|
||||||
|
|
||||||
let max_givable = || bitcoin_wallet.max_giveable(TxLock::script_size());
|
let max_givable = || bitcoin_wallet.max_giveable(TxLock::script_size());
|
||||||
let (send_bitcoin, fees) = determine_btc_to_swap(
|
let (amount, fees) = determine_btc_to_swap(
|
||||||
event_loop_handle.request_quote(),
|
event_loop_handle.request_quote(),
|
||||||
bitcoin_wallet.new_address(),
|
bitcoin_wallet.new_address(),
|
||||||
|| bitcoin_wallet.balance(),
|
|| bitcoin_wallet.balance(),
|
||||||
|
@ -119,7 +121,7 @@ async fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
info!("Swapping {} with {} fees", send_bitcoin, fees);
|
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?;
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ async fn main() -> Result<()> {
|
||||||
env_config,
|
env_config,
|
||||||
event_loop_handle,
|
event_loop_handle,
|
||||||
monero_receive_address,
|
monero_receive_address,
|
||||||
send_bitcoin,
|
amount,
|
||||||
);
|
);
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
|
@ -193,8 +195,8 @@ async fn main() -> Result<()> {
|
||||||
let seller_peer_id = db.get_peer_id(swap_id)?;
|
let seller_peer_id = db.get_peer_id(swap_id)?;
|
||||||
|
|
||||||
let mut swarm = swarm::bob(&seed, seller_peer_id, tor_socks5_port).await?;
|
let mut swarm = swarm::bob(&seed, seller_peer_id, tor_socks5_port).await?;
|
||||||
let bob_peer_id = swarm.local_peer_id();
|
let our_peer_id = swarm.local_peer_id();
|
||||||
tracing::debug!("Our peer-id: {}", bob_peer_id);
|
tracing::debug!(peer_id = %our_peer_id, "Initializing network module");
|
||||||
swarm
|
swarm
|
||||||
.behaviour_mut()
|
.behaviour_mut()
|
||||||
.add_address(seller_peer_id, seller_addr);
|
.add_address(seller_peer_id, seller_addr);
|
||||||
|
@ -353,10 +355,10 @@ where
|
||||||
debug!("Requesting quote");
|
debug!("Requesting quote");
|
||||||
let bid_quote = bid_quote.await?;
|
let bid_quote = bid_quote.await?;
|
||||||
info!(
|
info!(
|
||||||
|
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,
|
||||||
"Received quote: 1 XMR ~ {}",
|
"Received quote: 1 XMR ~ ",
|
||||||
bid_quote.price
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut current_maximum_giveable = max_giveable().await?;
|
let mut current_maximum_giveable = max_giveable().await?;
|
||||||
|
|
|
@ -61,7 +61,7 @@ async fn next_state(
|
||||||
env_config: &Config,
|
env_config: &Config,
|
||||||
receive_monero_address: monero::Address,
|
receive_monero_address: monero::Address,
|
||||||
) -> Result<BobState> {
|
) -> Result<BobState> {
|
||||||
tracing::trace!("Current state: {}", state);
|
tracing::trace!(%state, "Advancing state");
|
||||||
|
|
||||||
Ok(match state {
|
Ok(match state {
|
||||||
BobState::Started { btc_amount } => {
|
BobState::Started { btc_amount } => {
|
||||||
|
@ -152,7 +152,7 @@ async fn next_state(
|
||||||
match received_xmr {
|
match received_xmr {
|
||||||
Ok(()) => BobState::XmrLocked(state.xmr_locked(monero_wallet_restore_blockheight)),
|
Ok(()) => BobState::XmrLocked(state.xmr_locked(monero_wallet_restore_blockheight)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::warn!("Waiting for refund because insufficient Monero have been locked! {}", e);
|
tracing::warn!("Waiting for refund because insufficient Monero have been locked! {:#}", e);
|
||||||
tx_lock_status.wait_until_confirmed_with(state.cancel_timelock).await?;
|
tx_lock_status.wait_until_confirmed_with(state.cancel_timelock).await?;
|
||||||
|
|
||||||
BobState::CancelTimelockExpired(state.cancel())
|
BobState::CancelTimelockExpired(state.cancel())
|
||||||
|
@ -205,10 +205,10 @@ async fn next_state(
|
||||||
BobState::BtcRedeemed(state) => {
|
BobState::BtcRedeemed(state) => {
|
||||||
let (spend_key, view_key) = state.xmr_keys();
|
let (spend_key, view_key) = state.xmr_keys();
|
||||||
|
|
||||||
let generated_wallet_file_name = swap_id.to_string();
|
let wallet_file_name = swap_id.to_string();
|
||||||
if let Err(e) = monero_wallet
|
if let Err(e) = monero_wallet
|
||||||
.create_from_and_load(
|
.create_from_and_load(
|
||||||
generated_wallet_file_name.clone(),
|
wallet_file_name.clone(),
|
||||||
spend_key,
|
spend_key,
|
||||||
view_key,
|
view_key,
|
||||||
state.monero_wallet_restore_blockheight,
|
state.monero_wallet_restore_blockheight,
|
||||||
|
@ -219,11 +219,10 @@ async fn next_state(
|
||||||
// exist! This is a very unlikely scenario, but if we don't take care of it we
|
// exist! This is a very unlikely scenario, but if we don't take care of it we
|
||||||
// might not be able to ever transfer the Monero.
|
// might not be able to ever transfer the Monero.
|
||||||
tracing::warn!("Failed to generate monero wallet from keys: {:#}", e);
|
tracing::warn!("Failed to generate monero wallet from keys: {:#}", e);
|
||||||
tracing::info!(
|
tracing::info!(%wallet_file_name,
|
||||||
"Falling back to trying to open the the wallet if it already exists: {}",
|
"Falling back to trying to open the the wallet if it already exists",
|
||||||
swap_id
|
|
||||||
);
|
);
|
||||||
monero_wallet.open(generated_wallet_file_name).await?;
|
monero_wallet.open(wallet_file_name).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the generated wallet is synced so we have a proper balance
|
// Ensure that the generated wallet is synced so we have a proper balance
|
||||||
|
@ -232,7 +231,7 @@ async fn next_state(
|
||||||
let tx_hashes = monero_wallet.sweep_all(receive_monero_address).await?;
|
let tx_hashes = monero_wallet.sweep_all(receive_monero_address).await?;
|
||||||
|
|
||||||
for tx_hash in tx_hashes {
|
for tx_hash in tx_hashes {
|
||||||
tracing::info!("Sent XMR to {} in tx {}", receive_monero_address, tx_hash.0);
|
tracing::info!(%receive_monero_address, txid=%tx_hash.0, "Sent XMR to");
|
||||||
}
|
}
|
||||||
|
|
||||||
BobState::XmrRedeemed {
|
BobState::XmrRedeemed {
|
||||||
|
@ -281,7 +280,7 @@ pub async fn request_price_and_setup(
|
||||||
) -> Result<bob::state::State2> {
|
) -> Result<bob::state::State2> {
|
||||||
let xmr = event_loop_handle.request_spot_price(btc).await?;
|
let xmr = event_loop_handle.request_spot_price(btc).await?;
|
||||||
|
|
||||||
tracing::info!("Spot price for {} is {}", btc, xmr);
|
tracing::info!(%btc, %xmr, "Spot price");
|
||||||
|
|
||||||
let state0 = State0::new(
|
let state0 = State0::new(
|
||||||
swap_id,
|
swap_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user