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, 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();
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
}
@@ -819,9 +821,9 @@ impl Node {
819
821
self . channel_manager . get_our_node_id ( )
820
822
}
821
823
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 ( )
825
827
}
826
828
827
829
/// Retrieve a new on-chain/funding address.
@@ -851,7 +853,7 @@ impl Node {
851
853
///
852
854
/// Returns a temporary channel id.
853
855
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 ,
855
857
push_to_counterparty_msat : Option < u64 > , announce_channel : bool ,
856
858
) -> Result < ( ) , Error > {
857
859
let runtime_lock = self . running . read ( ) . unwrap ( ) ;
@@ -867,7 +869,7 @@ impl Node {
867
869
return Err ( Error :: InsufficientFunds ) ;
868
870
}
869
871
870
- let peer_info = PeerInfo :: try_from ( node_pubkey_and_address . to_string ( ) ) ? ;
872
+ let peer_info = PeerInfo { pubkey : node_id , address } ;
871
873
872
874
let con_peer_pubkey = peer_info. pubkey . clone ( ) ;
873
875
let con_peer_addr = peer_info. address . clone ( ) ;
@@ -1005,7 +1007,7 @@ impl Node {
1005
1007
}
1006
1008
1007
1009
/// 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 > {
1009
1011
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
1010
1012
return Err ( Error :: NotRunning ) ;
1011
1013
}
@@ -1070,7 +1072,7 @@ impl Node {
1070
1072
/// This can be used to pay a so-called "zero-amount" invoice, i.e., an invoice that leaves the
1071
1073
/// amount paid to be determined by the user.
1072
1074
pub fn send_payment_using_amount (
1073
- & self , invoice : Invoice , amount_msat : u64 ,
1075
+ & self , invoice : & Invoice , amount_msat : u64 ,
1074
1076
) -> Result < PaymentHash , Error > {
1075
1077
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
1076
1078
return Err ( Error :: NotRunning ) ;
@@ -1158,20 +1160,18 @@ impl Node {
1158
1160
1159
1161
/// Send a spontaneous, aka. "keysend", payment
1160
1162
pub fn send_spontaneous_payment (
1161
- & self , amount_msat : u64 , node_id : & str ,
1163
+ & self , amount_msat : u64 , node_id : & PublicKey ,
1162
1164
) -> Result < PaymentHash , Error > {
1163
1165
if self . running . read ( ) . unwrap ( ) . is_none ( ) {
1164
1166
return Err ( Error :: NotRunning ) ;
1165
1167
}
1166
1168
1167
- let pubkey = hex_utils:: to_compressed_pubkey ( node_id) . ok_or ( Error :: PeerInfoParseFailed ) ?;
1168
-
1169
1169
let payment_preimage = PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ;
1170
1170
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
1171
1171
1172
1172
let route_params = RouteParameters {
1173
1173
payment_params : PaymentParameters :: from_node_id (
1174
- pubkey ,
1174
+ * node_id ,
1175
1175
self . config . default_cltv_expiry_delta ,
1176
1176
) ,
1177
1177
final_value_msat : amount_msat,
@@ -1330,15 +1330,15 @@ async fn do_connect_peer(
1330
1330
pubkey : PublicKey , peer_addr : SocketAddr , peer_manager : Arc < PeerManager > ,
1331
1331
logger : Arc < FilesystemLogger > ,
1332
1332
) -> Result < ( ) , Error > {
1333
- log_info ! ( logger, "connecting to peer: {}@{}" , pubkey, peer_addr) ;
1333
+ log_info ! ( logger, "Connecting to peer: {}@{}" , pubkey, peer_addr) ;
1334
1334
match lightning_net_tokio:: connect_outbound ( Arc :: clone ( & peer_manager) , pubkey, peer_addr) . await
1335
1335
{
1336
1336
Some ( connection_closed_future) => {
1337
1337
let mut connection_closed_future = Box :: pin ( connection_closed_future) ;
1338
1338
loop {
1339
1339
match futures:: poll!( & mut connection_closed_future) {
1340
1340
std:: task:: Poll :: Ready ( _) => {
1341
- log_info ! ( logger, "peer connection closed: {}@{}" , pubkey, peer_addr) ;
1341
+ log_info ! ( logger, "Peer connection closed: {}@{}" , pubkey, peer_addr) ;
1342
1342
return Err ( Error :: ConnectionFailed ) ;
1343
1343
}
1344
1344
std:: task:: Poll :: Pending => { }
@@ -1351,7 +1351,7 @@ async fn do_connect_peer(
1351
1351
}
1352
1352
}
1353
1353
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) ;
1355
1355
Err ( Error :: ConnectionFailed )
1356
1356
}
1357
1357
}
0 commit comments