Skip to content

Commit a4e5344

Browse files
committed
boltz/bindings: use address types for restorable flows
1 parent f72c948 commit a4e5344

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

lwk_bindings/src/lightning.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,13 @@ impl BoltzSession {
494494
pub fn restorable_btc_to_lbtc_swaps(
495495
&self,
496496
swap_list: &SwapList,
497-
claim_address: String,
498-
refund_address: String,
497+
claim_address: &Address,
498+
refund_address: &BitcoinAddress,
499499
) -> Result<Vec<String>, LwkError> {
500500
let response = self.inner.restorable_btc_to_lbtc_swaps(
501501
&swap_list.inner,
502-
&claim_address,
503-
&refund_address,
502+
claim_address.as_ref(),
503+
refund_address.as_ref(),
504504
)?;
505505
let data = response
506506
.into_iter()
@@ -510,17 +510,17 @@ impl BoltzSession {
510510
Ok(data)
511511
}
512512

513-
/// Filter the swap list to only include restorable BTC to LBTC swaps
513+
/// Filter the swap list to only include restorable LBTC to BTC swaps
514514
pub fn restorable_lbtc_to_btc_swaps(
515515
&self,
516516
swap_list: &SwapList,
517-
claim_address: String,
518-
refund_address: String,
517+
claim_address: &BitcoinAddress,
518+
refund_address: &Address,
519519
) -> Result<Vec<String>, LwkError> {
520520
let response = self.inner.restorable_lbtc_to_btc_swaps(
521521
&swap_list.inner,
522-
&claim_address,
523-
&refund_address,
522+
claim_address.as_ref(),
523+
refund_address.as_ref(),
524524
)?;
525525
let data = response
526526
.into_iter()

lwk_boltz/src/blocking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl BoltzSession {
177177
pub fn restorable_btc_to_lbtc_swaps(
178178
&self,
179179
swaps: &[SwapRestoreResponse],
180-
claim_address: &str,
181-
refund_address: &str,
180+
claim_address: &elements::Address,
181+
refund_address: &bitcoin::Address,
182182
) -> Result<Vec<ChainSwapData>, Error> {
183183
let inner = self
184184
.runtime
@@ -193,8 +193,8 @@ impl BoltzSession {
193193
pub fn restorable_lbtc_to_btc_swaps(
194194
&self,
195195
swaps: &[SwapRestoreResponse],
196-
claim_address: &str,
197-
refund_address: &str,
196+
claim_address: &bitcoin::Address,
197+
refund_address: &elements::Address,
198198
) -> Result<Vec<ChainSwapData>, Error> {
199199
let inner = self
200200
.runtime

lwk_boltz/src/chain_swaps.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ impl BoltzSession {
223223
pub async fn restorable_btc_to_lbtc_swaps(
224224
&self,
225225
swaps: &[SwapRestoreResponse],
226-
claim_address: &str,
227-
refund_address: &str,
226+
claim_address: &elements::Address,
227+
refund_address: &bitcoin::Address,
228228
) -> Result<Vec<ChainSwapData>, Error> {
229+
let claim_address = claim_address.to_string();
230+
let refund_address = refund_address.to_string();
229231
swaps
230232
.iter()
231233
.filter(|e| matches!(e.swap_type, SwapRestoreType::Chain))
@@ -239,8 +241,8 @@ impl BoltzSession {
239241
convert_swap_restore_response_to_chain_swap_data(
240242
e,
241243
&self.mnemonic,
242-
claim_address,
243-
refund_address,
244+
&claim_address,
245+
&refund_address,
244246
)
245247
})
246248
.collect()
@@ -255,9 +257,11 @@ impl BoltzSession {
255257
pub async fn restorable_lbtc_to_btc_swaps(
256258
&self,
257259
swaps: &[SwapRestoreResponse],
258-
claim_address: &str,
259-
refund_address: &str,
260+
claim_address: &bitcoin::Address,
261+
refund_address: &elements::Address,
260262
) -> Result<Vec<ChainSwapData>, Error> {
263+
let claim_address = claim_address.to_string();
264+
let refund_address = refund_address.to_string();
261265
swaps
262266
.iter()
263267
.filter(|e| matches!(e.swap_type, SwapRestoreType::Chain))
@@ -271,14 +275,20 @@ impl BoltzSession {
271275
convert_swap_restore_response_to_chain_swap_data(
272276
e,
273277
&self.mnemonic,
274-
claim_address,
275-
refund_address,
278+
&claim_address,
279+
&refund_address,
276280
)
277281
})
278282
.collect()
279283
}
280284
}
281285

286+
/// Convert a swap restore response from Boltz API to a ChainSwapData.
287+
///
288+
/// Note: This function uses `&str` for addresses instead of typed `bitcoin::Address` or
289+
/// `elements::Address` because it handles both swap directions (BTC→LBTC and LBTC→BTC).
290+
/// The address types are swapped depending on the direction, so type safety is enforced
291+
/// at the public API level via `restorable_btc_to_lbtc_swaps` and `restorable_lbtc_to_btc_swaps`.
282292
pub(crate) fn convert_swap_restore_response_to_chain_swap_data(
283293
e: &SwapRestoreResponse,
284294
mnemonic: &Mnemonic,

0 commit comments

Comments
 (0)