use core::iter;
use futures::{channel::mpsc, prelude::*};
fn main() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let mut client = smoldot_light::Client::<
smoldot_light::platform::async_std::AsyncStdTcpWebSocket,
>::new(smoldot_light::ClientConfig {
tasks_spawner: Box::new(move |_name, task| {
async_std::task::spawn(task);
}),
system_name: env!("CARGO_PKG_NAME").into(),
system_version: env!("CARGO_PKG_VERSION").into(),
});
let (json_rpc_responses_tx, mut json_rpc_responses_rx) = mpsc::channel(32);
let chain_id = client
.add_chain(smoldot_light::AddChainConfig {
specification: include_str!("../../polkadot.json"),
json_rpc_responses: Some(json_rpc_responses_tx),
potential_relay_chains: iter::empty(),
database_content: "",
user_data: (),
})
.unwrap();
client
.json_rpc_request(
r#"{"id":1,"jsonrpc":"2.0","method":"chain_subscribeNewHeads","params":[]}"#,
chain_id,
)
.unwrap();
async_std::task::block_on(async move {
loop {
let response = json_rpc_responses_rx.next().await.unwrap();
println!("JSON-RPC response: {}", response);
}
})
}