@@ -106,7 +106,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
106106
107107pub use balance:: { BalanceDetails , LightningBalance , PendingSweepBalance } ;
108108use bitcoin:: secp256k1:: PublicKey ;
109- use bitcoin:: Amount ;
109+ use bitcoin:: { Address , Amount } ;
110110#[ cfg( feature = "uniffi" ) ]
111111pub use builder:: ArcedNodeBuilder as Builder ;
112112pub use builder:: BuildError ;
@@ -1300,6 +1300,59 @@ impl Node {
13001300 }
13011301 }
13021302
1303+ /// Remove funds from an existing channel, sending them to an on-chain address.
1304+ ///
1305+ /// This provides for decreasing a channel's outbound liquidity without re-balancing or closing
1306+ /// it. Once negotiation with the counterparty is complete, the channel remains operational
1307+ /// while waiting for a new funding transaction to confirm.
1308+ pub fn splice_out (
1309+ & self , user_channel_id : & UserChannelId , counterparty_node_id : PublicKey , address : Address ,
1310+ splice_amount_sats : u64 ,
1311+ ) -> Result < ( ) , Error > {
1312+ let open_channels =
1313+ self . channel_manager . list_channels_with_counterparty ( & counterparty_node_id) ;
1314+ if let Some ( channel_details) =
1315+ open_channels. iter ( ) . find ( |c| c. user_channel_id == user_channel_id. 0 )
1316+ {
1317+ if splice_amount_sats > channel_details. outbound_capacity_msat {
1318+ return Err ( Error :: ChannelSplicingFailed ) ;
1319+ }
1320+
1321+ self . wallet . parse_and_validate_address ( & address) ?;
1322+
1323+ let contribution = SpliceContribution :: SpliceOut {
1324+ outputs : vec ! [ bitcoin:: TxOut {
1325+ value: Amount :: from_sat( splice_amount_sats) ,
1326+ script_pubkey: address. script_pubkey( ) ,
1327+ } ] ,
1328+ } ;
1329+
1330+ let fee_rate = self . wallet . estimate_channel_funding_fee_rate ( ) ;
1331+ let funding_feerate_per_kw = fee_rate. to_sat_per_kwu ( ) . try_into ( ) . unwrap_or ( u32:: MAX ) ;
1332+
1333+ self . channel_manager
1334+ . splice_channel (
1335+ & channel_details. channel_id ,
1336+ & counterparty_node_id,
1337+ contribution,
1338+ funding_feerate_per_kw,
1339+ None ,
1340+ )
1341+ . map_err ( |e| {
1342+ log_error ! ( self . logger, "Failed to splice channel: {:?}" , e) ;
1343+ Error :: ChannelSplicingFailed
1344+ } )
1345+ } else {
1346+ log_error ! (
1347+ self . logger,
1348+ "Channel not found for user_channel_id: {:?} and counterparty: {}" ,
1349+ user_channel_id,
1350+ counterparty_node_id
1351+ ) ;
1352+ Err ( Error :: ChannelSplicingFailed )
1353+ }
1354+ }
1355+
13031356 /// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
13041357 /// cache.
13051358 ///
0 commit comments