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