Struct Client

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

A handle to a remote JSONRPC server

Implementations§

Source§

impl Client

Source

pub fn new<P: AsRef<Path>>(sockpath: P) -> Client

Creates a new client

Examples found in repository?
examples/lowlevel_1.rs (line 10)
7fn main() {
8    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
9    println!("Using socket {}", sock.display());
10    let client = client::Client::new(&sock);
11    let method = "getinfo";
12    let params = requests::GetInfo {};
13    match client
14        .send_request(method, params)
15        .and_then(|res: clightningrpc::Response<responses::GetInfo>| res.into_result())
16    {
17        Ok(d) => {
18            println!("Ok! {:?}", d);
19        }
20        Err(e) => {
21            println!("Error! {}", e);
22        }
23    }
24}
More examples
Hide additional examples
examples/lowlevel_2.rs (line 11)
8fn main() {
9    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
10    println!("Using socket {}", sock.display());
11    let client = client::Client::new(&sock);
12    for style in &["perkb", "perkw"] {
13        let method = "feerates";
14        let params = requests::FeeRates {
15            style: style,
16        };
17
18        match client
19            .send_request(method, params)
20            .and_then(|res: clightningrpc::Response<responses::FeeRates>| res.into_result())
21        {
22            Ok(d) => {
23                println!("Ok! {:?}", d);
24            }
25            Err(e) => {
26                println!("Error! {}", e);
27            }
28        }
29    }
30}
Source

pub fn set_timeout(&mut self, timeout: Option<Duration>)

Set an optional timeout for requests

Source

pub fn send_request<S: Serialize, D: DeserializeOwned>( &self, method: &str, params: S, ) -> Result<Response<D>, Error>

Sends a request to a client

Examples found in repository?
examples/lowlevel_1.rs (line 14)
7fn main() {
8    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
9    println!("Using socket {}", sock.display());
10    let client = client::Client::new(&sock);
11    let method = "getinfo";
12    let params = requests::GetInfo {};
13    match client
14        .send_request(method, params)
15        .and_then(|res: clightningrpc::Response<responses::GetInfo>| res.into_result())
16    {
17        Ok(d) => {
18            println!("Ok! {:?}", d);
19        }
20        Err(e) => {
21            println!("Error! {}", e);
22        }
23    }
24}
More examples
Hide additional examples
examples/lowlevel_2.rs (line 19)
8fn main() {
9    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
10    println!("Using socket {}", sock.display());
11    let client = client::Client::new(&sock);
12    for style in &["perkb", "perkw"] {
13        let method = "feerates";
14        let params = requests::FeeRates {
15            style: style,
16        };
17
18        match client
19            .send_request(method, params)
20            .and_then(|res: clightningrpc::Response<responses::FeeRates>| res.into_result())
21        {
22            Ok(d) => {
23                println!("Ok! {:?}", d);
24            }
25            Err(e) => {
26                println!("Error! {}", e);
27            }
28        }
29    }
30}

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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.