28
28
//! ```no_run
29
29
//! use ldk_node::Builder;
30
30
//! use ldk_node::lightning_invoice::Invoice;
31
+ //! use ldk_node::bitcoin::secp256k1::PublicKey;
31
32
//! use std::str::FromStr;
32
33
//!
33
34
//! fn main() {
44
45
//!
45
46
//! node.sync_wallets().unwrap();
46
47
//!
47
- //! node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, 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, false).unwrap();
48
51
//!
49
52
//! let invoice = Invoice::from_str("INVOICE_STR").unwrap();
50
- //! node.send_payment(invoice).unwrap();
53
+ //! node.send_payment(& invoice).unwrap();
51
54
//!
52
55
//! node.stop().unwrap();
53
56
//! }
60
63
//! [`send_payment`]: Node::send_payment
61
64
//!
62
65
#![ 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) ]
65
68
#![ allow( bare_trait_objects) ]
66
69
#![ allow( ellipsis_inclusive_range_patterns) ]
67
70
#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
@@ -133,7 +136,7 @@ use bitcoin::BlockHash;
133
136
134
137
use rand:: Rng ;
135
138
136
- use std:: convert:: { TryFrom , TryInto } ;
139
+ use std:: convert:: TryInto ;
137
140
use std:: default:: Default ;
138
141
use std:: fs;
139
142
use std:: net:: SocketAddr ;
@@ -167,7 +170,7 @@ pub struct Config {
167
170
/// The used Bitcoin network.
168
171
pub network : bitcoin:: Network ,
169
172
/// The IP address and TCP port the node will listen on.
170
- pub listening_address : Option < String > ,
173
+ pub listening_address : Option < SocketAddr > ,
171
174
/// The default CLTV expiry delta to be used for payments.
172
175
pub default_cltv_expiry_delta : u32 ,
173
176
}
@@ -178,7 +181,7 @@ impl Default for Config {
178
181
storage_dir_path : "/tmp/ldk_node/" . to_string ( ) ,
179
182
esplora_server_url : "http://localhost:3002" . to_string ( ) ,
180
183
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 ( ) ) ,
182
185
default_cltv_expiry_delta : 144 ,
183
186
}
184
187
}
@@ -262,9 +265,8 @@ impl Builder {
262
265
263
266
/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
264
267
///
265
- /// Format: `ADDR:PORT`
266
268
/// 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 {
268
270
self . config . listening_address = Some ( listening_address) ;
269
271
self
270
272
}
@@ -821,8 +823,8 @@ impl Node {
821
823
self . channel_manager . get_our_node_id ( )
822
824
}
823
825
824
- /// Returns our own listening address and port .
825
- pub fn listening_address ( & self ) -> Option < String > {
826
+ /// Returns our own listening address.
827
+ pub fn listening_address ( & self ) -> Option < SocketAddr > {
826
828
self . config . listening_address . clone ( )
827
829
}
828
830
@@ -847,7 +849,8 @@ impl Node {
847
849
///
848
850
/// Returns a temporary channel id
849
851
pub fn connect_open_channel (
850
- & self , node_pubkey_and_address : & str , channel_amount_sats : u64 , announce_channel : bool ,
852
+ & self , pubkey : & PublicKey , address : & SocketAddr , channel_amount_sats : u64 ,
853
+ announce_channel : bool ,
851
854
) -> Result < ( ) , Error > {
852
855
let runtime_lock = self . running . read ( ) . unwrap ( ) ;
853
856
if runtime_lock. is_none ( ) {
@@ -862,7 +865,7 @@ impl Node {
862
865
return Err ( Error :: InsufficientFunds ) ;
863
866
}
864
867
865
- let peer_info = PeerInfo :: try_from ( node_pubkey_and_address . to_string ( ) ) ? ;
868
+ let peer_info = PeerInfo { pubkey : pubkey . clone ( ) , address : address . clone ( ) } ;
866
869
867
870
let con_peer_pubkey = peer_info. pubkey . clone ( ) ;
868
871
let con_peer_addr = peer_info. address . clone ( ) ;
@@ -999,7 +1002,7 @@ impl Node {
999
1002
}
1000
1003
1001
1004
/// Send a payement given an invoice.
1002
- pub fn send_payment ( & self , invoice : Invoice ) -> Result < PaymentHash , Error > {
1005
+ pub fn send_payment ( & self , invoice : & Invoice ) -> Result < PaymentHash , Error > {
1003
1006
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
1004
1007
return Err ( Error :: NotRunning ) ;
1005
1008
}
@@ -1055,7 +1058,7 @@ impl Node {
1055
1058
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
1056
1059
/// amount paid to be determined by the user.
1057
1060
pub fn send_payment_using_amount (
1058
- & self , invoice : Invoice , amount_msat : u64 ,
1061
+ & self , invoice : & Invoice , amount_msat : u64 ,
1059
1062
) -> Result < PaymentHash , Error > {
1060
1063
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
1061
1064
return Err ( Error :: NotRunning ) ;
@@ -1281,15 +1284,15 @@ async fn do_connect_peer(
1281
1284
pubkey : PublicKey , peer_addr : SocketAddr , peer_manager : Arc < PeerManager > ,
1282
1285
logger : Arc < FilesystemLogger > ,
1283
1286
) -> Result < ( ) , Error > {
1284
- log_info ! ( logger, "connecting to peer: {}@{}" , pubkey, peer_addr) ;
1287
+ log_info ! ( logger, "Connecting to peer: {}@{}" , pubkey, peer_addr) ;
1285
1288
match lightning_net_tokio:: connect_outbound ( Arc :: clone ( & peer_manager) , pubkey, peer_addr) . await
1286
1289
{
1287
1290
Some ( connection_closed_future) => {
1288
1291
let mut connection_closed_future = Box :: pin ( connection_closed_future) ;
1289
1292
loop {
1290
1293
match futures:: poll!( & mut connection_closed_future) {
1291
1294
std:: task:: Poll :: Ready ( _) => {
1292
- log_info ! ( logger, "peer connection closed: {}@{}" , pubkey, peer_addr) ;
1295
+ log_info ! ( logger, "Peer connection closed: {}@{}" , pubkey, peer_addr) ;
1293
1296
return Err ( Error :: ConnectionFailed ) ;
1294
1297
}
1295
1298
std:: task:: Poll :: Pending => { }
@@ -1302,7 +1305,7 @@ async fn do_connect_peer(
1302
1305
}
1303
1306
}
1304
1307
None => {
1305
- log_error ! ( logger, "failed to connect to peer: {}@{}" , pubkey, peer_addr) ;
1308
+ log_error ! ( logger, "Failed to connect to peer: {}@{}" , pubkey, peer_addr) ;
1306
1309
Err ( Error :: ConnectionFailed )
1307
1310
}
1308
1311
}
0 commit comments