4343//!
4444//! node.start().unwrap();
4545//!
46- //! let funding_address = node.new_onchain_address ();
46+ //! let funding_address = node.onchain_payment().new_address ();
4747//!
4848//! // .. fund address ..
4949//!
@@ -130,7 +130,7 @@ use connection::ConnectionManager;
130130use event:: { EventHandler , EventQueue } ;
131131use gossip:: GossipSource ;
132132use liquidity:: LiquiditySource ;
133- use payment:: { Bolt11PaymentHandler , SpontaneousPaymentHandler } ;
133+ use payment:: { Bolt11PaymentHandler , OnchainPaymentHandler , SpontaneousPaymentHandler } ;
134134use payment_store:: PaymentStore ;
135135pub use payment_store:: { LSPFeeLimits , PaymentDetails , PaymentDirection , PaymentStatus } ;
136136use peer_store:: { PeerInfo , PeerStore } ;
@@ -154,7 +154,6 @@ use lightning_background_processor::process_events_async;
154154use lightning_transaction_sync:: EsploraSyncClient ;
155155
156156use bitcoin:: secp256k1:: PublicKey ;
157- use bitcoin:: { Address , Txid } ;
158157
159158use rand:: Rng ;
160159
@@ -770,38 +769,13 @@ impl Node {
770769 ) )
771770 }
772771
773- /// Retrieve a new on-chain/funding address.
774- pub fn new_onchain_address ( & self ) -> Result < Address , Error > {
775- let funding_address = self . wallet . get_new_address ( ) ?;
776- log_info ! ( self . logger, "Generated new funding address: {}" , funding_address) ;
777- Ok ( funding_address)
778- }
779-
780- /// Send an on-chain payment to the given address.
781- pub fn send_to_onchain_address (
782- & self , address : & bitcoin:: Address , amount_sats : u64 ,
783- ) -> Result < Txid , Error > {
784- let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
785- if rt_lock. is_none ( ) {
786- return Err ( Error :: NotRunning ) ;
787- }
788-
789- let cur_balance = self . wallet . get_balance ( ) ?;
790- if cur_balance. get_spendable ( ) < amount_sats {
791- log_error ! ( self . logger, "Unable to send payment due to insufficient funds." ) ;
792- return Err ( Error :: InsufficientFunds ) ;
793- }
794- self . wallet . send_to_address ( address, Some ( amount_sats) )
795- }
796-
797- /// Send an on-chain payment to the given address, draining all the available funds.
798- pub fn send_all_to_onchain_address ( & self , address : & bitcoin:: Address ) -> Result < Txid , Error > {
799- let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
800- if rt_lock. is_none ( ) {
801- return Err ( Error :: NotRunning ) ;
802- }
803-
804- self . wallet . send_to_address ( address, None )
772+ /// Returns a payment handler allowing to send and receive on-chain payments.
773+ pub fn onchain_payment ( & self ) -> Arc < OnchainPaymentHandler > {
774+ Arc :: new ( OnchainPaymentHandler :: new (
775+ Arc :: clone ( & self . runtime ) ,
776+ Arc :: clone ( & self . wallet ) ,
777+ Arc :: clone ( & self . logger ) ,
778+ ) )
805779 }
806780
807781 /// Retrieve a list of known channels.
0 commit comments