Kagome
Polkadot Runtime Engine in C++17
print_chain_info_mode.cpp
Go to the documentation of this file.
1 
7 
8 #define RAPIDJSON_NO_SIZETYPEDEFINE
9 namespace rapidjson {
10  typedef ::std::size_t SizeType;
11 }
12 #include <rapidjson/document.h>
13 #include <rapidjson/ostreamwrapper.h>
14 #include <rapidjson/writer.h>
15 #include <iostream>
16 
18 
21 
22  int PrintChainInfoMode::run() const {
23  auto &genesis_hash = block_tree_->getGenesisBlockHash();
24  auto finalized = block_tree_->getLastFinalized();
25  auto best = block_tree_->deepestLeaf();
26 
27  rapidjson::Document document;
28  document.SetObject();
29  auto &allocator = document.GetAllocator();
30  auto str_val = [&](std::string_view str) {
31  return rapidjson::Value(str.data(), str.size(), allocator);
32  };
33  document.AddMember(
34  "genesis_hash", str_val(hex_lower_0x(genesis_hash)), allocator);
35  document.AddMember(
36  "finalized_hash", str_val(hex_lower_0x(finalized.hash)), allocator);
37  document.AddMember("finalized_number", finalized.number, allocator);
38  document.AddMember(
39  "best_hash", str_val(hex_lower_0x(best.hash)), allocator);
40  document.AddMember("best_number", best.number, allocator);
41 
42  rapidjson::OStreamWrapper stream = std::cout;
43  rapidjson::Writer writer(stream);
44  document.Accept(writer);
45  std::cout << std::endl;
46 
47  return EXIT_SUCCESS;
48  }
49 } // namespace kagome::application::mode
std::string hex_lower_0x(gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation with prefix 0x.
Definition: hexutil.cpp:58
::std::size_t SizeType