pub struct ClnRpc { /* private fields */ }Expand description
An RPC-client for Core Lightning
Implementations§
Source§impl ClnRpc
impl ClnRpc
pub async fn new<P>(path: P) -> Result<ClnRpc>
Sourcepub async fn call_raw<R, P>(
&mut self,
method: &str,
params: &P,
) -> Result<R, RpcError>
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();
})pub async fn call(&mut self, req: Request) -> Result<Response, RpcError>
Sourcepub async fn call_enum(&mut self, req: Request) -> Result<Response, RpcError>
pub async fn call_enum(&mut self, req: Request) -> Result<Response, RpcError>
Performs an rpc-call
Sourcepub async fn call_typed<R>(
&mut self,
request: &R,
) -> Result<R::Response, RpcError>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more