Skip to content

Commit

Permalink
Improve names and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Nov 13, 2023
1 parent fe6ca62 commit b7788fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
30 changes: 16 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ pub struct SwapAddressInfo {
/// Information about a failed swap
pub struct FailedSwapInfo {
pub address: String,
/// The amount that is available to be refunded. The refund will involve paying some
/// The amount that is available to be recovered. The recovery will involve paying some
/// on-chain fees so it isn't possible to recover the entire amount.
pub amount: Amount,
pub created_at: SystemTime,
}

/// Information about a failed swap refund
pub struct FailedSwapRefundInfo {
/// Information the resolution of a failed swap.
pub struct ResolveFailedSwapInfo {
/// The amount that will be sent (swap amount - onchain fee)
pub refund_amount: Amount,
pub recovered_amount: Amount,
/// The amount that will be paid in onchain fees
pub onchain_fee: Amount,
}
Expand Down Expand Up @@ -1389,7 +1389,7 @@ impl LightningNode {
})
}

/// Lists all unresolved failed swaps. Each individual failed swap can be refunded
/// Lists all unresolved failed swaps. Each individual failed swap can be recovered
/// using [`LightningNode::resolve_failed_swap`].
pub fn get_unresolved_failed_swaps(&self) -> Result<Vec<FailedSwapInfo>> {
Ok(self
Expand All @@ -1412,20 +1412,20 @@ impl LightningNode {
.collect())
}

/// Prepares a failed swap refund in order to know how much will be recovered and how much
/// will be paid in onchain fees
/// Prepares the resolution of a failed swap in order to know how much will be recovered and how much
/// will be paid in onchain fees.
///
/// Parameters:
/// * `failed_swap_info` - the failed swap that will be prepared
/// * `to_address` - the destination address to which funds will be sent
/// * `onchain_fee_rate` - the fee rate that will be applied. The recommended one can be fetched
/// using [`LightningNode::query_onchain_fee_rate`]
pub fn prepare_refund_failed_swap(
pub fn prepare_resolve_failed_swap(
&self,
failed_swap_info: FailedSwapInfo,
to_address: String,
onchain_fee_rate: u32,
) -> Result<FailedSwapRefundInfo> {
) -> Result<ResolveFailedSwapInfo> {
let response = self
.rt
.handle()
Expand All @@ -1441,17 +1441,17 @@ impl LightningNode {

let rate = self.get_exchange_rate();
let onchain_fee = response.refund_tx_fee_sat.as_sats().to_amount_up(&rate);
let refund_amount = (failed_swap_info.amount.sats - onchain_fee.sats)
let recovered_amount = (failed_swap_info.amount.sats - onchain_fee.sats)
.as_sats()
.to_amount_down(&rate);

Ok(FailedSwapRefundInfo {
refund_amount,
Ok(ResolveFailedSwapInfo {
recovered_amount,
onchain_fee,
})
}

/// Creates and broadcasts a refund transaction to recover funds from a failed swap. Existing
/// Creates and broadcasts a resolving transaction to recover funds from a failed swap. Existing
/// failed swaps can be listed using [`LightningNode::get_unresolved_failed_swaps`].
///
/// Parameters:
Expand All @@ -1460,7 +1460,9 @@ impl LightningNode {
/// * `onchain_fee_rate` - the fee rate that will be applied. The recommeded one can be fetched
/// using [`LightningNode::query_onchain_fee_rate`]
///
/// Returns the txid of the refund transaction.
/// Returns the txid of the resolving transaction.
///
/// Paid on-chain fees can be known in advance using [`LightningNode::prepare_resolve_failed_swap`].
pub fn resolve_failed_swap(
&self,
failed_swap_address: String,
Expand Down
6 changes: 3 additions & 3 deletions src/lipalightninglib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface LightningNode {
sequence<FailedSwapInfo> get_unresolved_failed_swaps();

[Throws=LnError]
FailedSwapRefundInfo prepare_refund_failed_swap(FailedSwapInfo failed_swap_info, string to_address, u32 onchain_fee_rate);
ResolveFailedSwapInfo prepare_resolve_failed_swap(FailedSwapInfo failed_swap_info, string to_address, u32 onchain_fee_rate);

[Throws=LnError]
string resolve_failed_swap(string failed_swap_address, string to_address, u32 onchain_fee_rate);
Expand Down Expand Up @@ -357,8 +357,8 @@ dictionary SwapAddressInfo {
Amount max_deposit;
};

dictionary FailedSwapRefundInfo {
Amount refund_amount;
dictionary ResolveFailedSwapInfo {
Amount recovered_amount;
Amount onchain_fee;
};

Expand Down

0 comments on commit b7788fc

Please sign in to comment.