-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathv2_get_ancestors.rs
48 lines (42 loc) · 1.31 KB
/
v2_get_ancestors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Test the `GetAncestors` endpoint.
use anyhow::Context;
use clap::AppSettings;
use concordium_rust_sdk::{types::hashes::BlockHash, v2, v2::BlockIdentifier};
use futures::StreamExt;
use structopt::StructOpt;
#[derive(StructOpt)]
struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:20000"
)]
endpoint: v2::Endpoint,
#[structopt(
long = "block_hash",
help = "Block hash to query. Default: \"best\" block."
)]
block: Option<BlockHash>,
#[structopt(long = "amount", help = "Maximum amount of ancestors to be returned.")]
amount: u64,
}
#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
let app = {
let app = App::clap().global_setting(AppSettings::ColoredHelp);
let matches = app.get_matches();
App::from_clap(&matches)
};
let mut client = v2::Client::new(app.endpoint)
.await
.context("Cannot connect.")?;
let bi = app
.block
.map_or(BlockIdentifier::Best, BlockIdentifier::Given);
let mut res = client.get_ancestors(&bi, app.amount).await?;
println!("Blockhash: {}", res.block_hash);
while let Some(a) = res.response.next().await {
println!("{}", a?);
}
Ok(())
}