@@ -246,6 +246,14 @@ pub struct OfferInfo {
246
246
pub status : OfferStatus ,
247
247
}
248
248
249
+ /// Information about a failed swap
250
+ pub struct FailedSwapInfo {
251
+ pub address : String ,
252
+ /// The amount that is available to be refunded. The refund will involve paying some
253
+ /// onchain fees so it isn't possible to recover the entire amount.
254
+ pub amount : Amount ,
255
+ }
256
+
249
257
#[ derive( Clone , PartialEq , Debug ) ]
250
258
pub ( crate ) struct UserPreferences {
251
259
fiat_currency : String ,
@@ -1064,6 +1072,53 @@ impl LightningNode {
1064
1072
. to_hex ( ) )
1065
1073
}
1066
1074
1075
+ /// Lists all unresolved failed swaps. Each individual failed swap can be refunded
1076
+ /// using [`LightningNode::refund_failed_swap`].
1077
+ pub fn get_unresolved_failed_swaps ( & self ) -> Result < Vec < FailedSwapInfo > > {
1078
+ Ok ( self
1079
+ . rt
1080
+ . handle ( )
1081
+ . block_on ( self . sdk . list_refundables ( ) )
1082
+ . map_to_runtime_error (
1083
+ RuntimeErrorCode :: NodeUnavailable ,
1084
+ "Failed to list refundable failed swaps" ,
1085
+ ) ?
1086
+ . iter ( )
1087
+ . map ( |s| FailedSwapInfo {
1088
+ address : s. bitcoin_address . clone ( ) ,
1089
+ amount : ( s. confirmed_sats * 1000 ) . to_amount_down ( & self . get_exchange_rate ( ) ) ,
1090
+ } )
1091
+ . collect ( ) )
1092
+ }
1093
+
1094
+ /// Creates and broadcasts a refund transaction to recover funds from a failed swap. Existing
1095
+ /// failed swaps can be listed using [`LightningNode::get_unresolved_failed_swaps`].
1096
+ ///
1097
+ /// Parameters:
1098
+ /// * `failed_swap_address` - the address of the failed swap (can be obtained from [`FailedSwapInfo`])
1099
+ /// * `to_address` - the destination address to which funds will be sent
1100
+ /// * `onchain_fee_rate` - the fee rate that will be applied. The recommeded one can be fetched
1101
+ /// using [`LightningNode::query_onchain_fee`]
1102
+ ///
1103
+ /// Returns the txid of the refund transaction.
1104
+ pub fn refund_failed_swap (
1105
+ & self ,
1106
+ failed_swap_address : String ,
1107
+ to_address : String ,
1108
+ onchain_fee_rate : u32 ,
1109
+ ) -> Result < String > {
1110
+ self . rt
1111
+ . handle ( )
1112
+ . block_on (
1113
+ self . sdk
1114
+ . refund ( failed_swap_address, to_address, onchain_fee_rate) ,
1115
+ )
1116
+ . map_to_runtime_error (
1117
+ RuntimeErrorCode :: NodeUnavailable ,
1118
+ "Failed to create and broadcast failed swap refund transaction" ,
1119
+ )
1120
+ }
1121
+
1067
1122
/// Prints additional debug information to the logs.
1068
1123
///
1069
1124
/// Throws an error in case that the necessary information can't be retrieved.
0 commit comments