#lnd #tonic #grpc #async #rpc #api-bindings #rpc-client

fedimint-tonic-lnd

An async library implementing LND RPC via tonic and prost. Forked from https://github.com/Kixunil/tonic_lnd

5 releases

0.2.0 Jan 12, 2024
0.1.3 Oct 30, 2023
0.1.2 Oct 24, 2023
0.1.1 Oct 24, 2023
0.1.0 Sep 25, 2023

#115 in Magic Beans

Download history 137/week @ 2023-12-18 9/week @ 2023-12-25 92/week @ 2024-01-01 117/week @ 2024-01-08 174/week @ 2024-01-15 302/week @ 2024-01-22 335/week @ 2024-01-29 297/week @ 2024-02-05 342/week @ 2024-02-12 451/week @ 2024-02-19 317/week @ 2024-02-26 489/week @ 2024-03-04 492/week @ 2024-03-11 746/week @ 2024-03-18 388/week @ 2024-03-25 628/week @ 2024-04-01

2,288 downloads per month
Used in 5 crates (3 directly)

MITNFA license

77KB
357 lines

Tonic LND client

Crate Documentation

Rust implementation of LND RPC client using async gRPC library tonic.

About

Warning: this crate is in early development and may have unknown problems! Review it before using with mainnet funds!

This crate supports Lightning, WalletKit, Signer, and Peer RPC APIs from LND v0.15.4-beta

This crate implements LND GRPC using tonic and prost. Apart from being up-to-date at the time of writing (:D) it also allows async usage. It contains vendored *.proto files so LND source code is not required but accepts an environment variable LND_REPO_DIR which overrides the vendored *.proto files. This can be used to test new features in non-released lnd. (Actually, the motivating project using this library was that case. :))

Features

Since most of the LND RPCs supported by this crate can be used in isolation, and your project likely only needs a subset of these RPCs, we expose each RPC under Cargo feature gates. See the Cargo manifest for the latest supported features

All features are included by default, but you can explicitly select the features you want for a slimmer dependency and faster compilations.

Usage

There's no setup needed beyond adding the crate to your Cargo.toml. If you need to change the *.proto files from which the client is generated, set the environment variable LND_REPO_DIR to a directory with cloned lnd during build.

Here's an example of retrieving information from LND ([getinfo](https://api.lightning.community/#getinfo) call). You can find this and more examples in crate root for your convenience.

// This program accepts three arguments: address, cert file, macaroon file
// The address must start with `https://`!

#[tokio::main]
async fn main() {
    let mut args = std::env::args_os();
    args.next().expect("not even zeroth arg given");
    let address = args.next().expect("missing arguments: address, cert file, macaroon file");
    let cert_file = args.next().expect("missing arguments: cert file, macaroon file");
    let macaroon_file = args.next().expect("missing argument: macaroon file");
    let address = address.into_string().expect("address is not UTF-8");

    // Connecting to LND requires only address, cert file, and macaroon file
    let mut client = fedimint_tonic_lnd::connect(address, cert_file, macaroon_file)
        .await
        .expect("failed to connect");

    let info = client
        .lightning()
        // All calls require at least empty parameter
        .get_info(fedimint_tonic_lnd::lnrpc::GetInfoRequest {})
        .await
        .expect("failed to get info");

    // We only print it here, note that in real-life code you may want to call `.into_inner()` on
    // the response to get the message.
    println!("{:#?}", info);
}

MSRV

1.65.0

License

MITNFA

Dependencies

~15–25MB
~450K SLoC