mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-29 09:26:30 -05:00
Move log messages to the appropriate abstraction layer
Log messages are ideally as close to the functionality they are talking about, otherwise we might end up repeating ourselves on several callsites or the log messages gets outdated if the behaviour changes.
This commit is contained in:
parent
b8df4a3145
commit
7387884e6d
@ -179,10 +179,15 @@ impl SignTxLock for Wallet {
|
||||
#[async_trait]
|
||||
impl BroadcastSignedTransaction for Wallet {
|
||||
async fn broadcast_signed_transaction(&self, transaction: Transaction) -> Result<Txid> {
|
||||
tracing::debug!("attempting to broadcast tx: {}", transaction.txid());
|
||||
self.inner.lock().await.broadcast(transaction.clone())?;
|
||||
tracing::info!("Bitcoin tx broadcasted! TXID = {}", transaction.txid());
|
||||
Ok(transaction.txid())
|
||||
let txid = transaction.txid();
|
||||
|
||||
self.inner
|
||||
.lock()
|
||||
.await
|
||||
.broadcast(transaction)
|
||||
.with_context(|| format!("failed to broadcast transaction {}", txid))?;
|
||||
|
||||
Ok(txid)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
};
|
||||
use anyhow::{Error, Result};
|
||||
use libp2p::{request_response::ResponseChannel, NetworkBehaviour, PeerId};
|
||||
use tracing::{debug, info};
|
||||
use tracing::debug;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum OutEvent {
|
||||
@ -121,7 +121,6 @@ impl Behaviour {
|
||||
quote_response: QuoteResponse,
|
||||
) -> Result<()> {
|
||||
self.quote_response.send(channel, quote_response)?;
|
||||
info!("Sent quote response");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,10 @@ impl From<RequestResponseEvent<QuoteRequest, QuoteResponse>> for OutEvent {
|
||||
RequestResponseEvent::OutboundFailure { error, .. } => {
|
||||
OutEvent::Failure(anyhow!("Outbound failure: {:?}", error))
|
||||
}
|
||||
RequestResponseEvent::ResponseSent { .. } => OutEvent::ResponseSent,
|
||||
RequestResponseEvent::ResponseSent { peer, .. } => {
|
||||
tracing::debug!("successfully sent quote response to {}", peer);
|
||||
OutEvent::ResponseSent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use crate::{
|
||||
use anyhow::{bail, Error, Result};
|
||||
use libp2p::{core::Multiaddr, identity::Keypair, NetworkBehaviour, PeerId};
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, info};
|
||||
use tracing::debug;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use self::{
|
||||
@ -259,8 +259,7 @@ pub struct Behaviour {
|
||||
impl Behaviour {
|
||||
/// Sends a quote request to Alice to retrieve the rate.
|
||||
pub fn send_quote_request(&mut self, alice: PeerId, quote_request: QuoteRequest) {
|
||||
let _id = self.quote_request.send(alice, quote_request);
|
||||
info!("Requesting quote from: {}", alice);
|
||||
let _ = self.quote_request.send(alice, quote_request);
|
||||
}
|
||||
|
||||
pub fn start_execution_setup(
|
||||
@ -271,10 +270,8 @@ impl Behaviour {
|
||||
) {
|
||||
self.execution_setup
|
||||
.run(alice_peer_id, state0, bitcoin_wallet);
|
||||
info!("Start execution setup with {}", alice_peer_id);
|
||||
}
|
||||
|
||||
/// Sends Bob's fourth message to Alice.
|
||||
pub fn send_encrypted_signature(
|
||||
&mut self,
|
||||
alice: PeerId,
|
||||
|
@ -72,7 +72,6 @@ impl EventLoopHandle {
|
||||
/// Dials other party and wait for the connection to be established.
|
||||
/// Do nothing if we are already connected
|
||||
pub async fn dial(&mut self) -> Result<()> {
|
||||
debug!("Attempt to dial Alice");
|
||||
let _ = self.dial_alice.send(()).await?;
|
||||
|
||||
self.conn_established
|
||||
|
@ -72,6 +72,8 @@ impl Behaviour {
|
||||
) {
|
||||
self.inner
|
||||
.do_protocol_dialer(alice, move |mut substream| async move {
|
||||
tracing::debug!("Starting execution setup with {}", alice);
|
||||
|
||||
substream
|
||||
.write_message(
|
||||
&serde_cbor::to_vec(&state0.next_message())
|
||||
|
@ -36,6 +36,11 @@ pub struct Behaviour {
|
||||
|
||||
impl Behaviour {
|
||||
pub fn send(&mut self, alice: PeerId, quote_request: QuoteRequest) -> Result<RequestId> {
|
||||
debug!(
|
||||
"Requesting quote for {} from {}",
|
||||
quote_request.btc_amount, alice
|
||||
);
|
||||
|
||||
let id = self.rr.send_request(&alice, quote_request);
|
||||
|
||||
Ok(id)
|
||||
@ -67,13 +72,9 @@ impl From<RequestResponseEvent<QuoteRequest, QuoteResponse>> for OutEvent {
|
||||
..
|
||||
} => OutEvent::Failure(anyhow!("Bob should never get a request from Alice")),
|
||||
RequestResponseEvent::Message {
|
||||
peer,
|
||||
message: RequestResponseMessage::Response { response, .. },
|
||||
..
|
||||
} => {
|
||||
debug!("Received quote response from {}", peer);
|
||||
OutEvent::MsgReceived(response)
|
||||
}
|
||||
} => OutEvent::MsgReceived(response),
|
||||
RequestResponseEvent::InboundFailure { error, .. } => {
|
||||
OutEvent::Failure(anyhow!("Inbound failure: {:?}", error))
|
||||
}
|
||||
|
@ -389,12 +389,14 @@ pub async fn request_quote_and_setup(
|
||||
.send_quote_request(QuoteRequest { btc_amount })
|
||||
.await?;
|
||||
|
||||
let quote_response = event_loop_handle.recv_quote_response().await?;
|
||||
let xmr_amount = event_loop_handle.recv_quote_response().await?.xmr_amount;
|
||||
|
||||
tracing::info!("Quote for {} is {}", btc_amount, xmr_amount);
|
||||
|
||||
let state0 = State0::new(
|
||||
&mut OsRng,
|
||||
btc_amount,
|
||||
quote_response.xmr_amount,
|
||||
xmr_amount,
|
||||
execution_params.bitcoin_cancel_timelock,
|
||||
execution_params.bitcoin_punish_timelock,
|
||||
bitcoin_refund_address,
|
||||
|
Loading…
Reference in New Issue
Block a user