Skip to content
Snippets Groups Projects

Draft: Nostr

Open poka requested to merge nostr into master
2 files
+ 91
51
Compare changes
  • Side-by-side
  • Inline

Files

  • dfcc91f2
    ok · dfcc91f2
    fred authored
+ 89
51
@@ -191,59 +191,97 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
let i_latest_h = convert_hash_bytea(i_latest_block.hash);
let i_latest_n = i_latest_block.height;
fn color(x: bool) -> Color {
match x {
true => Color::Green,
false => Color::Red,
match data.args.output_format {
OutputFormat::Json => {
let output = serde_json::json!({
"duniter": {
"url": d_url,
"genesis_hash": d_gen_hash,
"finalized_block": {
"number": d_finalized_n,
"hash": d_finalized_h.to_string()
},
"latest_block": {
"number": d_latest_n,
"hash": d_latest_h.to_string()
}
},
"indexer": {
"url": i_url,
"genesis_hash": i_gen_hash,
"finalized_block": {
"number": i_finalized_n,
"hash": i_finalized_h.map(|h| h.to_string())
},
"latest_block": {
"number": i_latest_n,
"hash": i_latest_h.to_string()
}
},
"status": {
"genesis_hash_match": d_gen_hash == i_gen_hash,
"finalized_block_match": i_finalized_h.map_or(false, |h| h == d_finalized_h),
"latest_block_match": i_latest_n == d_latest_n as i64 && i_latest_h == d_latest_h
}
});
println!("{}", serde_json::to_string_pretty(&output).unwrap());
},
OutputFormat::Human => {
fn color(x: bool) -> Color {
match x {
true => Color::Green,
false => Color::Red,
}
}
let mut table = Table::new();
table
.load_preset(presets::UTF8_FULL)
.apply_modifier(modifiers::UTF8_ROUND_CORNERS)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_width(120)
.set_header(vec!["Variable", "Duniter", "Indexer"])
.add_row(vec!["URL", d_url, i_url])
.add_row(vec![
Cell::new("genesis hash"),
Cell::new(d_gen_hash),
Cell::new(i_gen_hash).fg(color(d_gen_hash == i_gen_hash)),
])
.add_row(vec![
Cell::new("finalized block number"),
Cell::new(d_finalized_n),
match i_finalized_n {
None => Cell::new("not indexed").fg(Color::Yellow),
Some(n) => {
// if it exists, it must be the same
assert_eq!(n, d_finalized_n as i64);
Cell::new("")
}
},
])
.add_row(vec![
Cell::new("finalized block hash"),
Cell::new(d_finalized_h),
match i_finalized_h {
// number already tells it is not indexed
None => Cell::new(""),
Some(h) => Cell::new(h).fg(color(h == d_finalized_h)),
},
])
.add_row(vec![
Cell::new("latest block number"),
Cell::new(d_latest_n),
Cell::new(i_latest_n).fg(color(i_latest_n == d_latest_n as i64)),
])
.add_row(vec![
Cell::new("latest block hash"),
Cell::new(d_latest_h),
Cell::new(i_latest_h).fg(color(i_latest_h == d_latest_h)),
]);
println!("{table}");
}
}
let mut table = Table::new();
table
.load_preset(presets::UTF8_FULL)
.apply_modifier(modifiers::UTF8_ROUND_CORNERS)
.set_content_arrangement(ContentArrangement::Dynamic)
.set_width(120)
.set_header(vec!["Variable", "Duniter", "Indexer"])
.add_row(vec!["URL", d_url, i_url])
.add_row(vec![
Cell::new("genesis hash"),
Cell::new(d_gen_hash),
Cell::new(i_gen_hash).fg(color(d_gen_hash == i_gen_hash)),
])
.add_row(vec![
Cell::new("finalized block number"),
Cell::new(d_finalized_n),
match i_finalized_n {
None => Cell::new("not indexed").fg(Color::Yellow),
Some(n) => {
// if it exists, it must be the same
assert_eq!(n, d_finalized_n as i64);
Cell::new("")
}
},
])
.add_row(vec![
Cell::new("finalized block hash"),
Cell::new(d_finalized_h),
match i_finalized_h {
// number already tells it is not indexed
None => Cell::new(""),
Some(h) => Cell::new(h).fg(color(h == d_finalized_h)),
},
])
.add_row(vec![
Cell::new("latest block number"),
Cell::new(d_latest_n),
Cell::new(i_latest_n).fg(color(i_latest_n == d_latest_n as i64)),
])
.add_row(vec![
Cell::new("latest block hash"),
Cell::new(d_latest_h),
Cell::new(i_latest_h).fg(color(i_latest_h == d_latest_h)),
]);
println!("{table}");
}
};
Loading