Skip to content

Commit

Permalink
cli: show payment duration
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Oct 24, 2024
1 parent 114eba1 commit 2445570
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/sdk-cli/src/command_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fs;
use std::sync::Arc;
use std::time::SystemTime;

use anyhow::{anyhow, Context, Error, Result};
use breez_sdk_core::InputType::{LnUrlAuth, LnUrlPay, LnUrlWithdraw};
Expand Down Expand Up @@ -247,6 +248,7 @@ pub(crate) async fn handle_command(
label,
use_trampoline,
} => {
let start = SystemTime::now();
let payment = sdk()?
.send_payment(SendPaymentRequest {
bolt11,
Expand All @@ -255,13 +257,17 @@ pub(crate) async fn handle_command(
use_trampoline,
})
.await?;
let end = SystemTime::now();
let diff = end.duration_since(start)?;
println!("payment took {}s", diff.as_secs_f32());
serde_json::to_string_pretty(&payment).map_err(|e| e.into())
}
Commands::SendSpontaneousPayment {
node_id,
amount_msat,
label,
} => {
let start = SystemTime::now();
let response = sdk()?
.send_spontaneous_payment(SendSpontaneousPaymentRequest {
node_id,
Expand All @@ -270,6 +276,9 @@ pub(crate) async fn handle_command(
label,
})
.await?;
let end = SystemTime::now();
let diff = end.duration_since(start)?;
println!("payment took {}s", diff.as_secs_f32());
serde_json::to_string_pretty(&response.payment).map_err(|e| e.into())
}
Commands::ListPayments {
Expand Down Expand Up @@ -481,6 +490,7 @@ pub(crate) async fn handle_command(
);

let amount_msat = rl.readline(&prompt)?;
let start = SystemTime::now();
let pay_res = sdk()?
.lnurl_pay(LnUrlPayRequest {
data: pd,
Expand All @@ -491,6 +501,9 @@ pub(crate) async fn handle_command(
validate_success_action_url: validate_success_url,
})
.await?;
let end = SystemTime::now();
let diff = end.duration_since(start)?;
println!("payment took {}s", diff.as_secs_f32());
//show_results(pay_res);
serde_json::to_string_pretty(&pay_res).map_err(|e| e.into())
}
Expand Down

0 comments on commit 2445570

Please sign in to comment.