#lightning #protocols #bitcoin #rpc

clightningrpc-common

Crate that provides an Generic RPC binding from rust code to the core lightning daemon

4 releases

0.3.0-beta.4 Jun 13, 2023
0.3.0-beta.3 Nov 17, 2022
0.3.0-beta.2 Jul 29, 2022
0.3.0-beta.1 May 23, 2022

#107 in #lightning

Download history 230/week @ 2023-12-17 375/week @ 2023-12-24 94/week @ 2023-12-31 119/week @ 2024-01-07 93/week @ 2024-01-14 97/week @ 2024-01-21 81/week @ 2024-01-28 238/week @ 2024-02-04 190/week @ 2024-02-11 231/week @ 2024-02-18 287/week @ 2024-02-25 312/week @ 2024-03-03 218/week @ 2024-03-10 184/week @ 2024-03-17 174/week @ 2024-03-24 164/week @ 2024-03-31

753 downloads per month
Used in 3 crates (via clightningrpc-plugin)

CC0 license

14KB
188 lines

Common client in Rust for core lightning

This crate provides a generic interface to the core lightning daemon through RPC.

Project Homepage

GitHub Workflow Status (branch) Crates.io docs.rs

This crate provides a generic interface to the core lightning daemon through RPC.

From the crate clightningrpc you can find this quote

Be aware that the API (of rust-clighting-rpc, but also that of c-lightning itself) is not finalized. This means that it is likely to change between versions and may break your compile, sorry!

This crate solve the versioning with core lightning by offering a strongly type library with a generic interface, an example can be:

extern crate clightningrpc_common;

use serde::{Deserialize, Serialize};
use std::env;

use clightningrpc_common::client;
use clightningrpc_common::types::Response;

/// Example of type definition
#[derive(Debug, Clone, Deserialize, Serialize)]
struct GetInfoResponse {
    pub id: String,
}

/// Example of type definition
#[derive(Debug, Clone, Deserialize, Serialize)]
struct GetInfoRequest {}

fn main() {
    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
    println!("Using socket {}", sock.display());
    let client = client::Client::new(&sock);
    let method = "getinfo";
    let params = GetInfoRequest {};
    match client
        .send_request(method, params)
        .and_then(|res: Response<GetInfoResponse>| res.into_result())
    {
        Ok(d) => {
            println!("Ok! {:?}", d);
        }
        Err(e) => {
            println!("Error! {}", e);
        }
    }
}

Contributing guidelines

  • Four spaces
  • Call make fmt before committing
  • If you can, GPG-sign at least your top commit when filing a PR

Supports

If you want support this library consider to donate with the following methods

Credits

This library is based on Andrew Poelstra's rust-jsonrpc.

Dependencies

~0.7–1.4MB
~33K SLoC