2828//! ```no_run
2929//! use ldk_node::Builder;
3030//! use ldk_node::lightning_invoice::Invoice;
31+ //! use ldk_node::bitcoin::secp256k1::PublicKey;
3132//! use std::str::FromStr;
3233//!
3334//! fn main() {
4445//!
4546//! node.sync_wallets().unwrap();
4647//!
47- //! node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, None, false).unwrap();
48+ //! let node_id = PublicKey::from_str("NODE_ID").unwrap();
49+ //! let node_addr = "IP_ADDR:PORT".parse().unwrap();
50+ //! node.connect_open_channel(node_id, node_addr, 10000, None, false).unwrap();
4851//!
4952//! let invoice = Invoice::from_str("INVOICE_STR").unwrap();
50- //! node.send_payment(invoice).unwrap();
53+ //! node.send_payment(& invoice).unwrap();
5154//!
5255//! node.stop().unwrap();
5356//! }
6063//! [`send_payment`]: Node::send_payment
6164//!
6265#![ deny( missing_docs) ]
63- #![ deny( broken_intra_doc_links) ]
64- #![ deny( private_intra_doc_links) ]
66+ #![ deny( rustdoc :: broken_intra_doc_links) ]
67+ #![ deny( rustdoc :: private_intra_doc_links) ]
6568#![ allow( bare_trait_objects) ]
6669#![ allow( ellipsis_inclusive_range_patterns) ]
6770#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
@@ -133,7 +136,7 @@ use bitcoin::BlockHash;
133136
134137use rand:: Rng ;
135138
136- use std:: convert:: { TryFrom , TryInto } ;
139+ use std:: convert:: TryInto ;
137140use std:: default:: Default ;
138141use std:: fs;
139142use std:: net:: SocketAddr ;
@@ -167,7 +170,7 @@ pub struct Config {
167170 /// The used Bitcoin network.
168171 pub network : bitcoin:: Network ,
169172 /// The IP address and TCP port the node will listen on.
170- pub listening_address : Option < String > ,
173+ pub listening_address : Option < SocketAddr > ,
171174 /// The default CLTV expiry delta to be used for payments.
172175 pub default_cltv_expiry_delta : u32 ,
173176}
@@ -178,7 +181,7 @@ impl Default for Config {
178181 storage_dir_path : "/tmp/ldk_node/" . to_string ( ) ,
179182 esplora_server_url : "http://localhost:3002" . to_string ( ) ,
180183 network : bitcoin:: Network :: Regtest ,
181- listening_address : Some ( "0.0.0.0:9735" . to_string ( ) ) ,
184+ listening_address : Some ( "0.0.0.0:9735" . parse ( ) . unwrap ( ) ) ,
182185 default_cltv_expiry_delta : 144 ,
183186 }
184187 }
@@ -262,9 +265,8 @@ impl Builder {
262265
263266 /// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
264267 ///
265- /// Format: `ADDR:PORT`
266268 /// Default: `0.0.0.0:9735`
267- pub fn set_listening_address ( & mut self , listening_address : String ) -> & mut Self {
269+ pub fn set_listening_address ( & mut self , listening_address : SocketAddr ) -> & mut Self {
268270 self . config . listening_address = Some ( listening_address) ;
269271 self
270272 }
@@ -819,9 +821,9 @@ impl Node {
819821 self . channel_manager . get_our_node_id ( )
820822 }
821823
822- /// Returns our own listening address and port .
823- pub fn listening_address ( & self ) -> Option < String > {
824- self . config . listening_address . clone ( )
824+ /// Returns our own listening address.
825+ pub fn listening_address ( & self ) -> Option < & SocketAddr > {
826+ self . config . listening_address . as_ref ( )
825827 }
826828
827829 /// Retrieve a new on-chain/funding address.
@@ -851,7 +853,7 @@ impl Node {
851853 ///
852854 /// Returns a temporary channel id.
853855 pub fn connect_open_channel (
854- & self , node_pubkey_and_address : & str , channel_amount_sats : u64 ,
856+ & self , node_id : PublicKey , address : SocketAddr , channel_amount_sats : u64 ,
855857 push_to_counterparty_msat : Option < u64 > , announce_channel : bool ,
856858 ) -> Result < ( ) , Error > {
857859 let runtime_lock = self . running . read ( ) . unwrap ( ) ;
@@ -867,7 +869,7 @@ impl Node {
867869 return Err ( Error :: InsufficientFunds ) ;
868870 }
869871
870- let peer_info = PeerInfo :: try_from ( node_pubkey_and_address . to_string ( ) ) ? ;
872+ let peer_info = PeerInfo { pubkey : node_id , address } ;
871873
872874 let con_peer_pubkey = peer_info. pubkey . clone ( ) ;
873875 let con_peer_addr = peer_info. address . clone ( ) ;
@@ -1005,7 +1007,7 @@ impl Node {
10051007 }
10061008
10071009 /// Send a payement given an invoice.
1008- pub fn send_payment ( & self , invoice : Invoice ) -> Result < PaymentHash , Error > {
1010+ pub fn send_payment ( & self , invoice : & Invoice ) -> Result < PaymentHash , Error > {
10091011 if self . running . read ( ) . unwrap ( ) . is_none ( ) {
10101012 return Err ( Error :: NotRunning ) ;
10111013 }
@@ -1070,7 +1072,7 @@ impl Node {
10701072 /// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
10711073 /// amount paid to be determined by the user.
10721074 pub fn send_payment_using_amount (
1073- & self , invoice : Invoice , amount_msat : u64 ,
1075+ & self , invoice : & Invoice , amount_msat : u64 ,
10741076 ) -> Result < PaymentHash , Error > {
10751077 if self . running . read ( ) . unwrap ( ) . is_none ( ) {
10761078 return Err ( Error :: NotRunning ) ;
@@ -1158,20 +1160,18 @@ impl Node {
11581160
11591161 /// Send a spontaneous, aka. "keysend", payment
11601162 pub fn send_spontaneous_payment (
1161- & self , amount_msat : u64 , node_id : & str ,
1163+ & self , amount_msat : u64 , node_id : & PublicKey ,
11621164 ) -> Result < PaymentHash , Error > {
11631165 if self . running . read ( ) . unwrap ( ) . is_none ( ) {
11641166 return Err ( Error :: NotRunning ) ;
11651167 }
11661168
1167- let pubkey = hex_utils:: to_compressed_pubkey ( node_id) . ok_or ( Error :: PeerInfoParseFailed ) ?;
1168-
11691169 let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
11701170 let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
11711171
11721172 let route_params = RouteParameters {
11731173 payment_params : PaymentParameters :: from_node_id (
1174- pubkey ,
1174+ * node_id ,
11751175 self . config . default_cltv_expiry_delta ,
11761176 ) ,
11771177 final_value_msat : amount_msat,
@@ -1330,15 +1330,15 @@ async fn do_connect_peer(
13301330 pubkey : PublicKey , peer_addr : SocketAddr , peer_manager : Arc < PeerManager > ,
13311331 logger : Arc < FilesystemLogger > ,
13321332) -> Result < ( ) , Error > {
1333- log_info ! ( logger, "connecting to peer: {}@{}" , pubkey, peer_addr) ;
1333+ log_info ! ( logger, "Connecting to peer: {}@{}" , pubkey, peer_addr) ;
13341334 match lightning_net_tokio:: connect_outbound ( Arc :: clone ( & peer_manager) , pubkey, peer_addr) . await
13351335 {
13361336 Some ( connection_closed_future) => {
13371337 let mut connection_closed_future = Box :: pin ( connection_closed_future) ;
13381338 loop {
13391339 match futures:: poll!( & mut connection_closed_future) {
13401340 std:: task:: Poll :: Ready ( _) => {
1341- log_info ! ( logger, "peer connection closed: {}@{}" , pubkey, peer_addr) ;
1341+ log_info ! ( logger, "Peer connection closed: {}@{}" , pubkey, peer_addr) ;
13421342 return Err ( Error :: ConnectionFailed ) ;
13431343 }
13441344 std:: task:: Poll :: Pending => { }
@@ -1351,7 +1351,7 @@ async fn do_connect_peer(
13511351 }
13521352 }
13531353 None => {
1354- log_error ! ( logger, "failed to connect to peer: {}@{}" , pubkey, peer_addr) ;
1354+ log_error ! ( logger, "Failed to connect to peer: {}@{}" , pubkey, peer_addr) ;
13551355 Err ( Error :: ConnectionFailed )
13561356 }
13571357 }
0 commit comments