connect

Function connect 

Source
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
Hide additional 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}