8 #define RAPIDJSON_NO_SIZETYPEDEFINE 12 #include <rapidjson/document.h> 13 #include <rapidjson/ostreamwrapper.h> 14 #include <rapidjson/writer.h> 22 int PrintChainInfoMode::run()
const {
23 auto &genesis_hash = block_tree_->getGenesisBlockHash();
24 auto finalized = block_tree_->getLastFinalized();
25 auto best = block_tree_->deepestLeaf();
27 rapidjson::Document document;
29 auto &allocator = document.GetAllocator();
30 auto str_val = [&](std::string_view str) {
31 return rapidjson::Value(str.data(), str.size(), allocator);
34 "genesis_hash", str_val(
hex_lower_0x(genesis_hash)), allocator);
36 "finalized_hash", str_val(
hex_lower_0x(finalized.hash)), allocator);
37 document.AddMember(
"finalized_number", finalized.number, allocator);
39 "best_hash", str_val(
hex_lower_0x(best.hash)), allocator);
40 document.AddMember(
"best_number", best.number, allocator);
42 rapidjson::OStreamWrapper stream = std::cout;
43 rapidjson::Writer writer(stream);
44 document.Accept(writer);
45 std::cout << std::endl;
std::string hex_lower_0x(gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation with prefix 0x.