pub async fn connect(
cert: String,
macaroon: String,
socket: String,
) -> Result<LndClient, Box<dyn Error>>Examples found in repository?
examples/getinfo.rs (line 19)
8async fn main() {
9 // Read the contents of the file into a vector of bytes
10 let cert_bytes = fs::read("path/to/tlscert").expect("FailedToReadTlsCertFile");
11 let mac_bytes = fs::read("path/to/macaroon").expect("FailedToReadMacaroonFile");
12
13 // Convert the bytes to a hex string
14 let cert = buffer_as_hex(cert_bytes);
15 let macaroon = buffer_as_hex(mac_bytes);
16
17 let socket = "localhost:10001".to_string();
18
19 let mut client = lnd_grpc_rust::connect(cert, macaroon, socket)
20 .await
21 .expect("failed to connect");
22
23 let info = client
24 .lightning()
25 // All calls require at least empty parameter
26 .get_info(lnd_grpc_rust::lnrpc::GetInfoRequest {})
27 .await
28 .expect("failed to get info");
29
30 // We only print it here, note that in real-life code you may want to call `.into_inner()` on
31 // the response to get the message.
32 println!("{:#?}", info);
33}More examples
examples/addholdinvoice.rs (line 15)
4async fn main() {
5 // Read the contents of the file into a vector of bytes
6 let cert_bytes = fs::read("path/to/tlscert").expect("FailedToReadTlsCertFile");
7 let mac_bytes = fs::read("path/to/macaroon").expect("FailedToReadMacaroonFile");
8
9 // Convert the bytes to a hex string
10 let cert = buffer_as_hex(cert_bytes);
11 let macaroon = buffer_as_hex(mac_bytes);
12
13 let socket = "localhost:10001".to_string();
14
15 let mut client = lnd_grpc_rust::connect(cert, macaroon, socket)
16 .await
17 .expect("failed to connect");
18
19 let add_hold_invoice_resp = client
20 .invoices()
21 .add_hold_invoice(lnd_grpc_rust::invoicesrpc::AddHoldInvoiceRequest {
22 hash: vec![0; 32],
23 value: 5555,
24 ..Default::default()
25 })
26 .await
27 .expect("failed to add hold invoice");
28
29 // We only print it here, note that in real-life code you may want to call `.into_inner()` on
30 // the response to get the message.
31 println!("{:#?}", add_hold_invoice_resp);
32}examples/subscribe_invoices.rs (line 17)
6async fn main() {
7 // Read the contents of the file into a vector of bytes
8 let cert_bytes = fs::read("path/to/tlscert").expect("FailedToReadTlsCertFile");
9 let mac_bytes = fs::read("path/to/macaroon").expect("FailedToReadMacaroonFile");
10
11 // Convert the bytes to a hex string
12 let cert = buffer_as_hex(cert_bytes);
13 let macaroon = buffer_as_hex(mac_bytes);
14
15 let socket = "localhost:10001".to_string();
16
17 let mut client = lnd_grpc_rust::connect(cert, macaroon, socket)
18 .await
19 .expect("failed to connect");
20
21 let mut invoice_stream = client
22 .lightning()
23 .subscribe_invoices(lnd_grpc_rust::lnrpc::InvoiceSubscription {
24 add_index: 0,
25 settle_index: 0,
26 })
27 .await
28 .expect("Failed to call subscribe_invoices")
29 .into_inner();
30
31 while let Some(invoice) = invoice_stream
32 .message()
33 .await
34 .expect("Failed to receive invoices")
35 {
36 if let Some(state) = lnd_grpc_rust::lnrpc::invoice::InvoiceState::from_i32(invoice.state) {
37 // If this invoice was Settled we can do something with it
38 if state == lnd_grpc_rust::lnrpc::invoice::InvoiceState::Settled {
39 println!("{:?}", invoice);
40 }
41 }
42 }
43}examples/htlc_interceptor.rs (line 33)
15async fn main() {
16 let mut args = std::env::args_os();
17 args.next().expect("not even zeroth arg given");
18
19 // Read the contents of the file into a vector of bytes
20 let cert_bytes = fs::read("path/to/tlscert").expect("FailedToReadTlsCertFile");
21 let mac_bytes = fs::read("path/to/macaroon").expect("FailedToReadMacaroonFile");
22
23 // Convert the bytes to a hex string
24 let cert = buffer_as_hex(cert_bytes);
25 let macaroon = buffer_as_hex(mac_bytes);
26
27 let socket = "localhost:10001".to_string();
28
29 let preimage = args.next().expect("missing argument: preimage");
30
31 let preimage = hex::decode(preimage.into_string().expect("preimage is invalid UTF-8")).unwrap();
32
33 let mut client = lnd_grpc_rust::connect(cert, macaroon, socket)
34 .await
35 .expect("failed to connect");
36
37 let (tx, rx) =
38 tokio::sync::mpsc::channel::<lnd_grpc_rust::routerrpc::ForwardHtlcInterceptResponse>(1024);
39 let stream = tokio_stream::wrappers::ReceiverStream::new(rx);
40
41 let mut htlc_stream = client
42 .router()
43 .htlc_interceptor(stream)
44 .await
45 .expect("Failed to call htlc_interceptor")
46 .into_inner();
47
48 while let Some(htlc) = htlc_stream
49 .message()
50 .await
51 .expect("Failed to receive htlcs")
52 {
53 println!("htlc {:?}", htlc);
54 let response = lnd_grpc_rust::routerrpc::ForwardHtlcInterceptResponse {
55 incoming_circuit_key: htlc.incoming_circuit_key,
56 action: 0,
57 preimage: preimage.clone(),
58 failure_code: 0,
59 failure_message: vec![],
60 in_amount_msat: todo!(),
61 out_amount_msat: todo!(),
62 out_wire_custom_records: todo!(),
63 };
64 tx.send(response).await.unwrap();
65 }
66}