pub struct Client { /* private fields */ }Expand description
A handle to a remote JSONRPC server
Implementations§
Source§impl Client
impl Client
Sourcepub fn new<P: AsRef<Path>>(sockpath: P) -> Client
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
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}Sourcepub fn set_timeout(&mut self, timeout: Option<Duration>)
pub fn set_timeout(&mut self, timeout: Option<Duration>)
Set an optional timeout for requests
Sourcepub fn send_request<S: Serialize, D: DeserializeOwned>(
&self,
method: &str,
params: S,
) -> Result<Response<D>, Error>
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
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§
Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl UnwindSafe for Client
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