Skip to content

Commit

Permalink
Add missing reserve
Browse files Browse the repository at this point in the history
Fix payjoin#76. Lnd's RequiredReserve returns the amount the wallet needs
to have when it opens a channel. Only add reserve amount if it is
missing from the wallet's total balance
  • Loading branch information
DanGould committed Nov 20, 2022
1 parent fad32ce commit 3a98144
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ impl Scheduler {
let bitcoin_addr = self.lnd.get_new_bech32_address().await?;

let required_reserve = self.lnd.required_reserve(batch.channels().len() as u32).await?;
let pj = &ScheduledPayJoin::new(required_reserve, batch);
let wallet_balance = self.lnd.wallet_balance().await?;
// Only add reserve if the wallet needs it
let missing_reserve = required_reserve.checked_sub(wallet_balance).unwrap_or_default();
let pj = &ScheduledPayJoin::new(missing_reserve, batch);

if self.insert_payjoin(&bitcoin_addr, pj) {
Ok((
Expand Down

0 comments on commit 3a98144

Please sign in to comment.