core-lightning/cln-rpc/examples/getinfo.rs
Christian Decker 33960be040 cln-rpc: Test that we forward errors correctly
So far we were papering over the actual error with a generic string
that isn't very useful. Now we decode the error and forward it through
the grpc layer as well (though still as a string).
2022-04-02 09:46:01 +10:30

23 lines
653 B
Rust

use anyhow::{anyhow, Context};
use cln_rpc::{model::GetinfoRequest, ClnRpc, Request};
use std::env::args;
use std::path::Path;
use tokio;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// initialize the log inside the library
env_logger::init();
let rpc_path = args().nth(1).context("missing argument: socket path")?;
let p = Path::new(&rpc_path);
let mut rpc = ClnRpc::new(p).await?;
let response = rpc
.call(Request::Getinfo(GetinfoRequest {}))
.await
.map_err(|e| anyhow!("Error calling getinfo: {:?}", e))?;
println!("{}", serde_json::to_string_pretty(&response)?);
Ok(())
}