@@ -400,20 +400,16 @@ impl LightningWallet {
400400 }
401401 }
402402
403- pub ( crate ) async fn splice_balance_into_channel (
404- & self , amount : Amount ,
405- ) -> Result < UserChannelId , NodeError > {
403+ pub ( crate ) async fn splice_all_into_channel ( & self ) -> Result < UserChannelId , NodeError > {
406404 // find existing channel to splice into
407405 let channels = self . inner . ldk_node . list_channels ( ) ;
408406 let channel = channels. iter ( ) . find ( |c| c. counterparty_node_id == self . inner . lsp_node_id ) ;
409407
410408 match channel {
411409 Some ( chan) => {
412- self . inner . ldk_node . splice_in (
413- & chan. user_channel_id ,
414- chan. counterparty_node_id ,
415- amount. sats_rounding_up ( ) ,
416- ) ?;
410+ self . inner
411+ . ldk_node
412+ . splice_in_with_all ( & chan. user_channel_id , chan. counterparty_node_id ) ?;
417413 Ok ( chan. user_channel_id )
418414 } ,
419415 None => {
@@ -424,23 +420,9 @@ impl LightningWallet {
424420 }
425421
426422 pub ( crate ) async fn open_channel_with_lsp ( & self ) -> Result < UserChannelId , NodeError > {
427- let bal = self . inner . ldk_node . list_balances ( ) . spendable_onchain_balance_sats ;
428-
429- // need a dummy p2wsh address to estimate the fee, p2wsh is used for LN channels
430- // let fake_addr = Address::p2wsh(Script::new(), self.inner.ldk_node.config().network);
431- //
432- // let fee = self
433- // .inner
434- // .ldk_node
435- // .onchain_payment()
436- // .estimate_send_all_to_address(&fake_addr, true, None)?;
437- // todo get real fee
438- let fee = 1000 ;
439-
440- let id = self . inner . ldk_node . open_channel (
423+ let id = self . inner . ldk_node . open_channel_with_all (
441424 self . inner . lsp_node_id ,
442425 self . inner . lsp_socket_addr . clone ( ) ,
443- bal - fee,
444426 None ,
445427 None ,
446428 ) ?;
@@ -541,12 +523,9 @@ impl graduated_rebalancer::LightningWallet for LightningWallet {
541523 }
542524
543525 fn open_channel_with_lsp (
544- & self , _amt : Amount ,
526+ & self ,
545527 ) -> Pin < Box < dyn Future < Output = Result < u128 , Self :: Error > > + Send + ' _ > > {
546- Box :: pin ( async move {
547- // we don't use the amount and just use our full spendable balance in open_channel_with_lsp
548- self . open_channel_with_lsp ( ) . await . map ( |c| c. 0 )
549- } )
528+ Box :: pin ( async move { self . open_channel_with_lsp ( ) . await . map ( |c| c. 0 ) } )
550529 }
551530
552531 fn await_channel_pending (
@@ -570,21 +549,9 @@ impl graduated_rebalancer::LightningWallet for LightningWallet {
570549 }
571550
572551 fn splice_to_lsp_channel (
573- & self , amt : Amount ,
552+ & self ,
574553 ) -> Pin < Box < dyn Future < Output = Result < u128 , Self :: Error > > + Send + ' _ > > {
575- let bal = self . inner . ldk_node . list_balances ( ) ;
576- // if we don't have enough onchain balance, return error
577- // if we are within 1,000 sats of the amount, reduce the amount to account for fees
578- if bal. spendable_onchain_balance_sats < amt. sats_rounding_up ( ) {
579- return Box :: pin ( async move { Err ( NodeError :: InsufficientFunds ) } ) ;
580- } else if bal. spendable_onchain_balance_sats < amt. sats_rounding_up ( ) + 1_000 {
581- let reduced_amt = amt. saturating_sub ( Amount :: from_sats ( 1_000 ) . expect ( "valid amount" ) ) ;
582- return Box :: pin ( async move {
583- self . splice_balance_into_channel ( reduced_amt) . await . map ( |c| c. 0 )
584- } ) ;
585- }
586-
587- Box :: pin ( async move { self . splice_balance_into_channel ( amt) . await . map ( |c| c. 0 ) } )
554+ Box :: pin ( async move { self . splice_all_into_channel ( ) . await . map ( |c| c. 0 ) } )
588555 }
589556
590557 fn await_splice_pending (
0 commit comments