@@ -109,7 +109,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
109109
110110pub use balance:: { BalanceDetails , LightningBalance , PendingSweepBalance } ;
111111use bitcoin:: secp256k1:: PublicKey ;
112- use bitcoin:: Amount ;
112+ use bitcoin:: { Address , Amount } ;
113113#[ cfg( feature = "uniffi" ) ]
114114pub use builder:: ArcedNodeBuilder as Builder ;
115115pub use builder:: BuildError ;
@@ -1328,6 +1328,71 @@ impl Node {
13281328 }
13291329 }
13301330
1331+ /// Remove funds from an existing channel, sending them to an on-chain address.
1332+ ///
1333+ /// This provides for decreasing a channel's outbound liquidity without re-balancing or closing
1334+ /// it. Once negotiation with the counterparty is complete, the channel remains operational
1335+ /// while waiting for a new funding transaction to confirm.
1336+ ///
1337+ /// # Experimental API
1338+ ///
1339+ /// This API is experimental. Currently, a splice-out will be marked as an inbound payment if
1340+ /// paid to an address associated with the on-chain wallet, but this classification may change
1341+ /// in the future.
1342+ pub fn splice_out (
1343+ & self , user_channel_id : & UserChannelId , counterparty_node_id : PublicKey , address : & Address ,
1344+ splice_amount_sats : u64 ,
1345+ ) -> Result < ( ) , Error > {
1346+ let open_channels =
1347+ self . channel_manager . list_channels_with_counterparty ( & counterparty_node_id) ;
1348+ if let Some ( channel_details) =
1349+ open_channels. iter ( ) . find ( |c| c. user_channel_id == user_channel_id. 0 )
1350+ {
1351+ if splice_amount_sats > channel_details. outbound_capacity_msat {
1352+ return Err ( Error :: ChannelSplicingFailed ) ;
1353+ }
1354+
1355+ self . wallet . parse_and_validate_address ( address) ?;
1356+
1357+ let contribution = SpliceContribution :: SpliceOut {
1358+ outputs : vec ! [ bitcoin:: TxOut {
1359+ value: Amount :: from_sat( splice_amount_sats) ,
1360+ script_pubkey: address. script_pubkey( ) ,
1361+ } ] ,
1362+ } ;
1363+
1364+ let fee_rate = self . fee_estimator . estimate_fee_rate ( ConfirmationTarget :: ChannelFunding ) ;
1365+ let funding_feerate_per_kw: u32 = match fee_rate. to_sat_per_kwu ( ) . try_into ( ) {
1366+ Ok ( fee_rate) => fee_rate,
1367+ Err ( _) => {
1368+ debug_assert ! ( false ) ;
1369+ fee_estimator:: get_fallback_rate_for_target ( ConfirmationTarget :: ChannelFunding )
1370+ } ,
1371+ } ;
1372+
1373+ self . channel_manager
1374+ . splice_channel (
1375+ & channel_details. channel_id ,
1376+ & counterparty_node_id,
1377+ contribution,
1378+ funding_feerate_per_kw,
1379+ None ,
1380+ )
1381+ . map_err ( |e| {
1382+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1383+ Error :: ChannelSplicingFailed
1384+ } )
1385+ } else {
1386+ log_error ! (
1387+ self . logger,
1388+ "Channel not found for user_channel_id: {:?} and counterparty: {}" ,
1389+ user_channel_id,
1390+ counterparty_node_id
1391+ ) ;
1392+ Err ( Error :: ChannelSplicingFailed )
1393+ }
1394+ }
1395+
13311396 /// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
13321397 /// cache.
13331398 ///
0 commit comments