mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-29 12:16:19 -04:00
wip: add tracing instrument macro to some request functions
This commit is contained in:
parent
472e3a57b3
commit
42bbf09a2b
@ -22,6 +22,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{debug_span, field, Instrument, Span};
|
use tracing::{debug_span, field, Instrument, Span};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use tracing:
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
@ -113,6 +114,7 @@ pub enum Method {
|
|||||||
GetRawStates,
|
GetRawStates,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Simplify this using
|
||||||
impl Method {
|
impl Method {
|
||||||
fn get_tracing_span(&self, log_reference_id: Option<String>) -> Span {
|
fn get_tracing_span(&self, log_reference_id: Option<String>) -> Span {
|
||||||
let span = match self {
|
let span = match self {
|
||||||
@ -215,6 +217,7 @@ impl Method {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(fields(method="suspend_current_swap"), skip(context))]
|
||||||
async fn suspend_current_swap(context: Arc<Context>) -> Result<serde_json::Value> {
|
async fn suspend_current_swap(context: Arc<Context>) -> Result<serde_json::Value> {
|
||||||
let swap_id = context.swap_lock.get_current_swap_id().await;
|
let swap_id = context.swap_lock.get_current_swap_id().await;
|
||||||
|
|
||||||
@ -227,17 +230,17 @@ async fn suspend_current_swap(context: Arc<Context>) -> Result<serde_json::Value
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(fields(method="get_swap_info", swap_id = args.swap_id), skip(context))]
|
||||||
async fn get_swap_info(
|
async fn get_swap_info(
|
||||||
get_swap_info: GetSwapInfoArgs,
|
args: GetSwapInfoArgs,
|
||||||
context: Arc<Context>,
|
context: Arc<Context>,
|
||||||
) -> Result<serde_json::Value> {
|
) -> Result<serde_json::Value> {
|
||||||
let GetSwapInfoArgs { swap_id } = get_swap_info;
|
|
||||||
let bitcoin_wallet = context
|
let bitcoin_wallet = context
|
||||||
.bitcoin_wallet
|
.bitcoin_wallet
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.context("Could not get Bitcoin wallet")?;
|
.context("Could not get Bitcoin wallet")?;
|
||||||
|
|
||||||
let state = context.db.get_state(swap_id).await?;
|
let state = context.db.get_state(args.swap_id).await?;
|
||||||
let is_completed = state.swap_finished();
|
let is_completed = state.swap_finished();
|
||||||
|
|
||||||
let peerId = context
|
let peerId = context
|
||||||
@ -252,7 +255,7 @@ async fn get_swap_info(
|
|||||||
.await
|
.await
|
||||||
.with_context(|| "Could not get addressess")?;
|
.with_context(|| "Could not get addressess")?;
|
||||||
|
|
||||||
let start_date = context.db.get_swap_start_date(swap_id).await?;
|
let start_date = context.db.get_swap_start_date(args.swap_id).await?;
|
||||||
|
|
||||||
let swap_state: BobState = state.try_into()?;
|
let swap_state: BobState = state.try_into()?;
|
||||||
let state_name = format!("{}", swap_state);
|
let state_name = format!("{}", swap_state);
|
||||||
@ -269,7 +272,7 @@ async fn get_swap_info(
|
|||||||
punish_timelock,
|
punish_timelock,
|
||||||
) = context
|
) = context
|
||||||
.db
|
.db
|
||||||
.get_states(swap_id)
|
.get_states(args.swap_id)
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|state| {
|
.find_map(|state| {
|
||||||
@ -323,7 +326,7 @@ async fn get_swap_info(
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"swapId": swap_id,
|
"swapId": args.swap_id,
|
||||||
"seller": {
|
"seller": {
|
||||||
"peerId": peerId.to_string(),
|
"peerId": peerId.to_string(),
|
||||||
"addresses": addresses
|
"addresses": addresses
|
||||||
@ -740,6 +743,7 @@ async fn start_daemon(
|
|||||||
Ok(json!({}))
|
Ok(json!({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(method="get_balance")
|
||||||
pub async fn get_balance(balance: BalanceArgs, context: Arc<Context>) -> Result<BalanceResponse> {
|
pub async fn get_balance(balance: BalanceArgs, context: Arc<Context>) -> Result<BalanceResponse> {
|
||||||
let BalanceArgs { force_refresh } = balance;
|
let BalanceArgs { force_refresh } = balance;
|
||||||
let bitcoin_wallet = context
|
let bitcoin_wallet = context
|
||||||
|
Loading…
x
Reference in New Issue
Block a user