@@ -836,6 +836,31 @@ impl Node {
836836 self . wallet . get_balance ( )
837837 }
838838
839+ /// Send an on-chain payment to the given address.
840+ pub fn withdraw ( & self , address : & bitcoin:: Address , amount_sats : u64 ) -> Result < Txid , Error > {
841+ let runtime_lock = self . running . read ( ) . unwrap ( ) ;
842+ if runtime_lock. is_none ( ) {
843+ return Err ( Error :: NotRunning ) ;
844+ }
845+
846+ let cur_balance = self . wallet . get_balance ( ) ?;
847+ if cur_balance. get_spendable ( ) < amount_sats {
848+ log_error ! ( self . logger, "Unable to send payment due to insufficient funds." ) ;
849+ return Err ( Error :: InsufficientFunds ) ;
850+ }
851+ self . wallet . send_to_address ( address, amount_sats)
852+ }
853+
854+ /// Send an on-chain payment to the given address, draining all the available funds.
855+ pub fn withdraw_all ( & self , address : & bitcoin:: Address ) -> Result < Txid , Error > {
856+ let runtime_lock = self . running . read ( ) . unwrap ( ) ;
857+ if runtime_lock. is_none ( ) {
858+ return Err ( Error :: NotRunning ) ;
859+ }
860+
861+ self . wallet . drain_to_address ( address)
862+ }
863+
839864 /// Retrieve a list of known channels.
840865 pub fn list_channels ( & self ) -> Vec < ChannelDetails > {
841866 self . channel_manager . list_channels ( )
@@ -1218,23 +1243,6 @@ impl Node {
12181243 }
12191244 }
12201245
1221- /// Send an on-chain payment to the given address.
1222- pub fn send_onchain_payment (
1223- & self , address : & bitcoin:: Address , amount_sats : u64 ,
1224- ) -> Result < Txid , Error > {
1225- let runtime_lock = self . running . read ( ) . unwrap ( ) ;
1226- if runtime_lock. is_none ( ) {
1227- return Err ( Error :: NotRunning ) ;
1228- }
1229-
1230- let cur_balance = self . wallet . get_balance ( ) ?;
1231- if cur_balance. get_spendable ( ) < amount_sats {
1232- log_error ! ( self . logger, "Unable to send payment due to insufficient funds." ) ;
1233- return Err ( Error :: InsufficientFunds ) ;
1234- }
1235- self . wallet . send_to_address ( address, amount_sats)
1236- }
1237-
12381246 /// Returns a payable invoice that can be used to request and receive a payment of the amount
12391247 /// given.
12401248 pub fn receive_payment (
0 commit comments