Skip to content

Commit

Permalink
feat: add delay to sendpayment command
Browse files Browse the repository at this point in the history
  • Loading branch information
yse committed Apr 9, 2024
1 parent cde06cb commit 43c42e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::borrow::Cow::{self, Owned};
use std::sync::Arc;
use std::thread;
use std::time::Duration;

use anyhow::Result;
use clap::{arg, Parser};
Expand All @@ -15,7 +17,13 @@ use serde_json::to_string_pretty;
#[derive(Parser, Debug, Clone, PartialEq)]
pub(crate) enum Command {
/// Send lbtc and receive btc through a swap
SendPayment { bolt11: String },
SendPayment {
bolt11: String,

/// Delay for the send, in seconds
#[arg(short, long)]
delay: Option<u64>,
},
/// Receive lbtc and send btc through a swap
ReceivePayment {
#[arg(short, long)]
Expand Down Expand Up @@ -76,10 +84,22 @@ pub(crate) fn handle_command(
qr2term::print_qr(response.invoice.clone())?;
command_result!(response)
}
Command::SendPayment { bolt11 } => {
Command::SendPayment { bolt11, delay } => {
let prepare_response = wallet.prepare_payment(&bolt11)?;
let response = wallet.send_payment(&prepare_response)?;
command_result!(response)

if let Some(delay) = delay {
let wallet_cloned = wallet.clone();
let prepare_cloned = prepare_response.clone();

thread::spawn(move || {
thread::sleep(Duration::from_secs(delay));
wallet_cloned.send_payment(&prepare_cloned).unwrap();
});
command_result!(prepare_response)
} else {
let response = wallet.send_payment(&prepare_response)?;
command_result!(response)
}
}
Command::GetInfo => {
command_result!(wallet.get_info(true)?)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct ReceivePaymentResponse {
pub invoice: String,
}

#[derive(Debug)]
#[derive(Debug, Clone, Serialize)]
pub struct PreparePaymentResponse {
pub id: String,
pub funding_amount: u64,
Expand Down

0 comments on commit 43c42e7

Please sign in to comment.