Skip to main content

Client

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 using the path to the socket file and initializing the timeout field to None

Examples found in repository?
examples/lowlevel_1.rs (line 23)
19fn main() {
20    #[allow(deprecated)]
21    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
22    println!("Using socket {}", sock.display());
23    let client = client::Client::new(&sock);
24    let method = "getinfo";
25    let params = GetInfoRequest {};
26    match client
27        .send_request(method, params)
28        .and_then(|res: Response<GetInfoResponse>| res.into_result())
29    {
30        Ok(d) => {
31            println!("Ok! {:?}", d);
32        }
33        Err(e) => {
34            println!("Error! {}", e);
35        }
36    }
37}
More examples
Hide additional examples
examples/lowlevel_2.rs (line 14)
10fn main() {
11    #[allow(deprecated)]
12    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
13    println!("Using socket {}", sock.display());
14    let client = client::Client::new(&sock);
15    for style in &["perkb", "perkw"] {
16        let method = "feerates";
17        let params = json!({
18            "style": style,
19        });
20        match client
21            .send_request(method, params)
22            .and_then(|res: types::Response<HashMap<String, Value>>| res.into_result())
23        {
24            Ok(d) => {
25                println!("Ok! {:?}", d);
26            }
27            Err(e) => {
28                println!("Error! {}", e);
29            }
30        }
31    }
32}
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 27)
19fn main() {
20    #[allow(deprecated)]
21    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
22    println!("Using socket {}", sock.display());
23    let client = client::Client::new(&sock);
24    let method = "getinfo";
25    let params = GetInfoRequest {};
26    match client
27        .send_request(method, params)
28        .and_then(|res: Response<GetInfoResponse>| res.into_result())
29    {
30        Ok(d) => {
31            println!("Ok! {:?}", d);
32        }
33        Err(e) => {
34            println!("Error! {}", e);
35        }
36    }
37}
More examples
Hide additional examples
examples/lowlevel_2.rs (line 21)
10fn main() {
11    #[allow(deprecated)]
12    let sock = env::home_dir().unwrap().join(".lightning/lightning-rpc");
13    println!("Using socket {}", sock.display());
14    let client = client::Client::new(&sock);
15    for style in &["perkb", "perkw"] {
16        let method = "feerates";
17        let params = json!({
18            "style": style,
19        });
20        match client
21            .send_request(method, params)
22            .and_then(|res: types::Response<HashMap<String, Value>>| res.into_result())
23        {
24            Ok(d) => {
25                println!("Ok! {:?}", d);
26            }
27            Err(e) => {
28                println!("Error! {}", e);
29            }
30        }
31    }
32}

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§

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.