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
@@ -841,38 +840,13 @@ impl Node {
841840 ) )
842841 }
843842
844- /// Retrieve a new on-chain/funding address.
845- pub fn new_onchain_address ( & self ) -> Result < Address , Error > {
846- let funding_address = self . wallet . get_new_address ( ) ?;
847- log_info ! ( self . logger, "Generated new funding address: {}" , funding_address) ;
848- Ok ( funding_address)
849- }
850-
851- /// Send an on-chain payment to the given address.
852- pub fn send_to_onchain_address (
853- & self , address : & bitcoin:: Address , amount_sats : u64 ,
854- ) -> Result < Txid , Error > {
855- let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
856- if rt_lock. is_none ( ) {
857- return Err ( Error :: NotRunning ) ;
858- }
859-
860- let cur_balance = self . wallet . get_balance ( ) ?;
861- if cur_balance. get_spendable ( ) < amount_sats {
862- log_error ! ( self . logger, "Unable to send payment due to insufficient funds." ) ;
863- return Err ( Error :: InsufficientFunds ) ;
864- }
865- self . wallet . send_to_address ( address, Some ( amount_sats) )
866- }
867-
868- /// Send an on-chain payment to the given address, draining all the available funds.
869- pub fn send_all_to_onchain_address ( & self , address : & bitcoin:: Address ) -> Result < Txid , Error > {
870- let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
871- if rt_lock. is_none ( ) {
872- return Err ( Error :: NotRunning ) ;
873- }
874-
875- self . wallet . send_to_address ( address, None )
843+ /// Returns a payment handler allowing to send and receive on-chain payments.
844+ pub fn onchain_payment ( & self ) -> Arc < OnchainPaymentHandler > {
845+ Arc :: new ( OnchainPaymentHandler :: new (
846+ Arc :: clone ( & self . runtime ) ,
847+ Arc :: clone ( & self . wallet ) ,
848+ Arc :: clone ( & self . logger ) ,
849+ ) )
876850 }
877851
878852 /// Retrieve a list of known channels.
0 commit comments