Crate voltage_tonic_lnd

Crate voltage_tonic_lnd 

Source
Expand description

Async Rust client for the LND gRPC API using tonic and prost.

§Overview

This crate provides convenient, async access to the Lightning Network Daemon (LND) via gRPC, with vendored proto files for all major LND RPC APIs. It is designed for ergonomic integration with Rust async codebases, and supports feature flags for fine-grained control of enabled APIs and TLS implementations.

§Supported LND APIs (Features)

Each LND RPC API is behind a Cargo feature flag. All features are enabled by default for a complete client, but you can select a subset for slimmer builds. See the [features] section in Cargo.toml for details.

  • lightningrpc (core Lightning API)
  • walletrpc (WalletKit, depends on signrpc)
  • signrpc (Signer)
  • peersrpc (Peers)
  • routerrpc (Router)
  • invoicesrpc (Invoices)
  • staterpc (State)
  • versionrpc (Versioner)
  • all (enables all RPCs)
  • TLS backend selection: ring (default), aws-lc
  • TLS root CA selection: tls-native-roots, tls-webpki-roots, tls

Default features: all, ring, tls

At least one TLS backend is required. The default is ring.

§Example

Connect to LND using file paths for cert and macaroon:

use voltage_tonic_lnd::Client;

#[tokio::main]
async fn main() -> Result<(), voltage_tonic_lnd::Error> {
    let client = Client::builder()
        .address("https://localhost:10009")
        .macaroon_path("/path/to/admin.macaroon")
        .cert_path("/path/to/tls.cert")
        .build()
        .await?;
    // Use client.lightning(), client.wallet(), etc.
    Ok(())
}

Or using in-memory credentials:

use voltage_tonic_lnd::Client;

#[tokio::main]
async fn main() -> Result<(), voltage_tonic_lnd::Error> {
    let client = Client::builder()
        .address("https://localhost:10009")
        .macaroon_contents(HEX_MACAROON_STRING)
        .cert_contents(PEM_CERT_STRING)
        .build()
        .await?;
    Ok(())
}

See the crate README and ClientBuilder docs for more usage details.

§Example: Custom Timeout, No Cert

You can set a timeout and skip the cert (using system roots or insecure connection, depending on your TLS features):

use voltage_tonic_lnd::Client;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), voltage_tonic_lnd::Error> {
    let client = Client::builder()
        .address("https://localhost:10009")
        .macaroon_path("/path/to/admin.macaroon")
        .timeout(Duration::from_secs(10))
        .build()
        .await?;
    Ok(())
}

Re-exports§

pub use tonic;

Modules§

invoicesrpc
lnrpc
Messages and other types generated by tonic/prost
peersrpc
routerrpc
signrpc
verrpc
walletrpc

Structs§

Client
The client returned by connect function
ClientBuilder
A builder for configuring and constructing a Client to connect to LND via gRPC.
MacaroonInterceptor
Supplies requests with macaroon

Enums§

Error

Functions§

connectDeprecated
Connects to LND using given address and credentials
connect_from_memoryDeprecated
connect_from_memory connects to LND using in-memory cert and macaroon instead of from file paths. cert`` is a PEM encoded string macaroon`` is a hex-encoded string These credentials can get out of date! Make sure you are pulling fresh credentials when using this function.
connect_from_memory_with_system_certsDeprecated
connect_from_memory_with_system_certs connects to LND using in-memory macaroon and system certs. `macaroon`` is a hex-encoded string These credentials can get out of date! Make sure you are pulling fresh credentials when using this function.

Type Aliases§

InvoicesClient
Convenience type alias for invoices client.
LightningClient
Convenience type alias for lightning client.
PeersClient
Convenience type alias for peers service client.
Result
RouterClient
Convenience type alias for router client.
SignerClient
Convenience type alias for signer client.
StateClient
Convenience type alias for state service client.
VersionerClient
Convenience type alias for versioner service client.
WalletKitClient
Convenience type alias for wallet client.