ClnRpc

Struct ClnRpc 

Source
pub struct ClnRpc { /* private fields */ }
Expand description

An RPC-client for Core Lightning

Implementations§

Source§

impl ClnRpc

Source

pub async fn new<P>(path: P) -> Result<ClnRpc>
where P: AsRef<Path>,

Source

pub async fn call_raw<R, P>( &mut self, method: &str, params: &P, ) -> Result<R, RpcError>

Low-level API to call the rpc.

An interesting choice of R and P is serde_json::Value because it allows ad-hoc calls to custom RPC-methods

If you are using a model such as crate::model::requests::GetinfoRequest you’d probably want to use Self::call_typed instead.

Example:

use cln_rpc::ClnRpc;
use cln_rpc::model::{requests::GetinfoRequest, responses::GetinfoResponse, responses::ListfundsResponse};
use std::path::Path;
use tokio_test;
tokio_test::block_on( async {

   // Call using json-values
   let mut cln = ClnRpc::new(Path::new("./lightningd/rpc")).await.unwrap();
   let request = serde_json::json!({});
   let response : serde_json::Value = cln.call_raw("getinfo", &request).await.unwrap();

   // Using a model
   // Prefer to use call_typed instead
   let request = GetinfoRequest {};
   let response : GetinfoResponse = cln.call_raw("getinfo", &request).await.unwrap();
})
Source

pub async fn call(&mut self, req: Request) -> Result<Response, RpcError>

Source

pub async fn call_enum(&mut self, req: Request) -> Result<Response, RpcError>

Performs an rpc-call

Source

pub async fn call_typed<R>( &mut self, request: &R, ) -> Result<R::Response, RpcError>

Performs an rpc-call and performs type-checking.

use cln_rpc::ClnRpc;
use cln_rpc::model::requests::GetinfoRequest;
use std::path::Path;
use tokio_test;
tokio_test::block_on( async {
   let mut rpc = ClnRpc::new(Path::new("path_to_rpc")).await.unwrap();
   let request = GetinfoRequest {};
   let response = rpc.call_typed(&request);
})

Auto Trait Implementations§

§

impl !Freeze for ClnRpc

§

impl RefUnwindSafe for ClnRpc

§

impl Send for ClnRpc

§

impl Sync for ClnRpc

§

impl Unpin for ClnRpc

§

impl UnwindSafe for ClnRpc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.