mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-18 13:34:22 +01:00
Always fill in the actual_payer_amount_sat
This commit is contained in:
@@ -731,7 +731,8 @@ pub(crate) struct ChainSwap {
|
||||
pub(crate) description: Option<String>,
|
||||
/// Payer amount defined at swap creation
|
||||
pub(crate) payer_amount_sat: u64,
|
||||
/// The actual payer amount in case it differs from `payer_amount_sat` (over/underpayment)
|
||||
/// The actual payer amount as seen on the user lockup tx. Might differ from `payer_amount_sat`
|
||||
/// in the case of an over/underpayment
|
||||
pub(crate) actual_payer_amount_sat: Option<u64>,
|
||||
/// Receiver amount defined at swap creation
|
||||
pub(crate) receiver_amount_sat: u64,
|
||||
@@ -861,6 +862,17 @@ impl ChainSwap {
|
||||
|
||||
Ok(create_response_json)
|
||||
}
|
||||
|
||||
pub(crate) fn is_amount_mismatch(&self) -> bool {
|
||||
match self.actual_payer_amount_sat {
|
||||
Some(actual_amount) => actual_amount != self.payer_amount_sat,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_waiting_fee_acceptance(&self) -> bool {
|
||||
self.is_amount_mismatch() && self.accepted_receiver_amount_sat.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
||||
@@ -580,9 +580,12 @@ impl Persister {
|
||||
let receiver_amount_sat =
|
||||
match maybe_chain_swap_accepted_receiver_amount_sat {
|
||||
Some(accepted_receiver_amount_sat) => accepted_receiver_amount_sat,
|
||||
None => match maybe_chain_swap_actual_payer_amount_sat {
|
||||
Some(_) => payer_amount_sat, // For over/underpaid chain swaps WaitingFeeAcceptance, show zero fees
|
||||
None => maybe_chain_swap_receiver_amount_sat.unwrap_or(0),
|
||||
None => match (
|
||||
maybe_chain_swap_actual_payer_amount_sat,
|
||||
maybe_chain_swap_payer_amount_sat,
|
||||
) {
|
||||
(Some(actual), Some(expected)) if actual != expected => actual, // For over/underpaid chain swaps WaitingFeeAcceptance, show zero fees
|
||||
_ => maybe_chain_swap_receiver_amount_sat.unwrap_or(0),
|
||||
},
|
||||
};
|
||||
let swapper_fees_sat = maybe_chain_swap_pair_fees
|
||||
|
||||
@@ -212,20 +212,14 @@ impl Recoverer {
|
||||
log::warn!("Could not apply recovered data for incoming Chain swap {swap_id}: recovery data not found");
|
||||
continue;
|
||||
};
|
||||
if chain_swap.payer_amount_sat != recovered_data.btc_user_lockup_amount_sat
|
||||
{
|
||||
chain_swap.actual_payer_amount_sat =
|
||||
Some(recovered_data.btc_user_lockup_amount_sat)
|
||||
}
|
||||
chain_swap.actual_payer_amount_sat =
|
||||
Some(recovered_data.btc_user_lockup_amount_sat);
|
||||
let is_expired = bitcoin_height >= chain_swap.timeout_block_height;
|
||||
let min_lockup_amount_sat = chain_swap.payer_amount_sat;
|
||||
let is_waiting_fee_acceptance =
|
||||
chain_swap.actual_payer_amount_sat.is_some()
|
||||
&& chain_swap.accepted_receiver_amount_sat.is_none();
|
||||
if let Some(new_state) = recovered_data.derive_partial_state(
|
||||
min_lockup_amount_sat,
|
||||
is_expired,
|
||||
is_waiting_fee_acceptance,
|
||||
chain_swap.is_waiting_fee_acceptance(),
|
||||
) {
|
||||
chain_swap.state = new_state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user