Skip to content

Commit

Permalink
Expose fees for review + auto accept
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Dec 21, 2024
1 parent 0b6d3b6 commit 8a32e74
Show file tree
Hide file tree
Showing 30 changed files with 1,192 additions and 75 deletions.
29 changes: 27 additions & 2 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) enum Command {
#[clap(name = "filter", short = 'r', long = "filter")]
filters: Option<Vec<PaymentType>>,

/// The optional payment state. Either "pending", "complete", "failed", "pendingrefund" or "refundable"
/// The optional payment state. Either "Pending", "Complete", "Failed", "RefundPending", "Refundable" or "WaitingFeeAcceptance"
#[clap(name = "state", short = 's', long = "state")]
states: Option<Vec<PaymentState>>,

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef struct _Dart_Handle* Dart_Handle;

#define ESTIMATED_BTC_CLAIM_TX_VSIZE 111

#define ESTIMATED_BTC_LOCKUP_TX_VSIZE 154

#define STANDARD_FEE_RATE_SAT_PER_VBYTE 0.1

#define LOWBALL_FEE_RATE_SAT_PER_VBYTE 0.01
Expand Down Expand Up @@ -481,13 +483,18 @@ typedef struct wire_cst_SdkEvent_PaymentWaitingConfirmation {
struct wire_cst_payment *details;
} wire_cst_SdkEvent_PaymentWaitingConfirmation;

typedef struct wire_cst_SdkEvent_PaymentWaitingFeeAcceptance {
struct wire_cst_payment *details;
} wire_cst_SdkEvent_PaymentWaitingFeeAcceptance;

typedef union SdkEventKind {
struct wire_cst_SdkEvent_PaymentFailed PaymentFailed;
struct wire_cst_SdkEvent_PaymentPending PaymentPending;
struct wire_cst_SdkEvent_PaymentRefunded PaymentRefunded;
struct wire_cst_SdkEvent_PaymentRefundPending PaymentRefundPending;
struct wire_cst_SdkEvent_PaymentSucceeded PaymentSucceeded;
struct wire_cst_SdkEvent_PaymentWaitingConfirmation PaymentWaitingConfirmation;
struct wire_cst_SdkEvent_PaymentWaitingFeeAcceptance PaymentWaitingFeeAcceptance;
} SdkEventKind;

typedef struct wire_cst_sdk_event {
Expand Down Expand Up @@ -519,6 +526,7 @@ typedef struct wire_cst_config {
struct wire_cst_list_prim_u_8_strict *breez_api_key;
struct wire_cst_list_external_input_parser *external_input_parsers;
bool use_default_external_input_parsers;
uint32_t *onchain_fee_rate_leeway_sat_per_vbyte;
} wire_cst_config;

typedef struct wire_cst_connect_request {
Expand Down
6 changes: 3 additions & 3 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ dictionary Config {
u64? zero_conf_max_amount_sat;
boolean use_default_external_input_parsers = true;
sequence<ExternalInputParser>? external_input_parsers = null;
u32? onchain_fee_rate_leeway_sat_per_vbyte;
u32? onchain_fee_rate_leeway_sat_per_vbyte = null;
};

enum LiquidNetwork {
Expand Down Expand Up @@ -585,7 +585,7 @@ enum PaymentState {
"TimedOut",
"Refundable",
"RefundPending",
"WaitingUserAction",
"WaitingFeeAcceptance",
};

dictionary RefundableSwap {
Expand Down Expand Up @@ -755,7 +755,7 @@ interface BindingLiquidSdk {
[Throws=SdkError]
FetchPaymentProposedFeesResponse fetch_payment_proposed_fees(FetchPaymentProposedFeesRequest req);

[Throws=SdkError]
[Throws=PaymentError]
void accept_payment_proposed_fees(AcceptPaymentProposedFeesRequest req);

[Throws=SdkError]
Expand Down
14 changes: 14 additions & 0 deletions lib/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ impl BindingLiquidSdk {
rt().block_on(self.sdk.get_payment(&req))
}

pub fn fetch_payment_proposed_fees(
&self,
req: FetchPaymentProposedFeesRequest,
) -> SdkResult<FetchPaymentProposedFeesResponse> {
rt().block_on(self.sdk.fetch_payment_proposed_fees(&req))
}

pub fn accept_payment_proposed_fees(
&self,
req: AcceptPaymentProposedFeesRequest,
) -> Result<(), PaymentError> {
rt().block_on(self.sdk.accept_payment_proposed_fees(&req))
}

pub fn prepare_lnurl_pay(
&self,
req: PrepareLnUrlPayRequest,
Expand Down
Loading

0 comments on commit 8a32e74

Please sign in to comment.