@@ -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 ( )
@@ -1213,23 +1238,6 @@ impl Node {
12131238 }
12141239 }
12151240
1216- /// Send an on-chain payment to the given address.
1217- pub fn send_onchain_payment (
1218- & self , address : & bitcoin:: Address , amount_sats : u64 ,
1219- ) -> Result < Txid , Error > {
1220- let runtime_lock = self . running . read ( ) . unwrap ( ) ;
1221- if runtime_lock. is_none ( ) {
1222- return Err ( Error :: NotRunning ) ;
1223- }
1224-
1225- let cur_balance = self . wallet . get_balance ( ) ?;
1226- if cur_balance. get_spendable ( ) < amount_sats {
1227- log_error ! ( self . logger, "Unable to send payment due to insufficient funds." ) ;
1228- return Err ( Error :: InsufficientFunds ) ;
1229- }
1230- self . wallet . send_to_address ( address, amount_sats)
1231- }
1232-
12331241 /// Returns a payable invoice that can be used to request and receive a payment of the amount
12341242 /// given.
12351243 pub fn receive_payment (
0 commit comments