Expose fees for review + auto accept

This commit is contained in:
Daniel Granhão
2024-12-20 13:36:30 +00:00
parent 08f0fd26cc
commit 351473a41e
30 changed files with 1195 additions and 367 deletions

View File

@@ -4,7 +4,7 @@ use std::sync::Arc;
use std::thread;
use std::time::Duration;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, bail, Result};
use breez_sdk_liquid::prelude::*;
use clap::{arg, Parser};
use qrcode_rs::render::unicode;
@@ -131,6 +131,14 @@ pub(crate) enum Command {
/// Lightning payment hash
payment_hash: String,
},
/// Get proposed fees for WaitingFeeAcceptance Payment
FetchPaymentProposedFees { swap_id: String },
/// Accept proposed fees for WaitingFeeAcceptance Payment
AcceptPaymentProposedFees {
swap_id: String,
// Fee amount obtained using FetchPaymentProposedFees
fees_sat: u64,
},
/// List refundable chain swaps
ListRefundables,
/// Prepare a refund transaction for an incomplete swap
@@ -519,6 +527,23 @@ pub(crate) async fn handle_command(
}
}
}
Command::FetchPaymentProposedFees { swap_id } => {
let res = sdk
.fetch_payment_proposed_fees(&FetchPaymentProposedFeesRequest { swap_id })
.await?;
command_result!(res)
}
Command::AcceptPaymentProposedFees { swap_id, fees_sat } => {
let res = sdk
.fetch_payment_proposed_fees(&FetchPaymentProposedFeesRequest { swap_id })
.await?;
if fees_sat != res.fees_sat {
bail!("Fees changed since they were fetched")
}
sdk.accept_payment_proposed_fees(&AcceptPaymentProposedFeesRequest { response: res })
.await?;
command_result!("Proposed fees accepted successfully")
}
Command::ListRefundables => {
let refundables = sdk.list_refundables().await?;
command_result!(refundables)