1313#include < util/logging.h>
1414
1515#include < cstdlib>
16- #include < format>
1716#include < string>
1817
19- namespace {
20- std::string BytesToString (const grovedb::Bytes& b)
21- {
22- return std::string (b.begin (), b.end ());
23- }
24-
25- grovedb::Bytes StringToBytes (const std::string& s)
26- {
27- return grovedb::Bytes (s.begin (), s.end ());
28- }
29-
30- std::string HashToHex (const grovedb::Hash& h)
31- {
32- std::string hex;
33- hex.reserve (64 );
34- for (auto b : h) hex += std::format (" {:02x}" , b);
35- return hex;
36- }
37- } // namespace
38-
3918int main ()
4019{
4120 Log (INFO, " === Absence Proofs ===" );
@@ -56,12 +35,12 @@ int main()
5635 // -------------------------------------------------------------------------
5736
5837 for (const char * k : {" a" , " c" , " e" }) {
59- auto elem = grovedb::Element::Item (StringToBytes (std::string (" val_" ) + k));
38+ auto elem = grovedb::Element::Item (grovedb::Bytes::FromString (std::string (" val_" ) + k));
6039 if (!elem.has_value ()) {
6140 Log (ERROR, " failed to create element: {}" , elem.error ().message ());
6241 return EXIT_FAILURE;
6342 }
64- auto cost = db.Put (root, StringToBytes (k), *elem);
43+ auto cost = db.Put (root, grovedb::Bytes::FromString (k), *elem);
6544 if (!cost.has_value ()) {
6645 Log (ERROR, " put failed: {}" , cost.error ().message ());
6746 return EXIT_FAILURE;
@@ -76,11 +55,11 @@ int main()
7655
7756 Log (INFO, " --- VerifyQueryWithAbsenceProof ---" );
7857 auto q1 = grovedb::PathQuery::New (root,
79- {grovedb::QueryItem::Key (StringToBytes (" a" )),
80- grovedb::QueryItem::Key (StringToBytes (" b" )),
81- grovedb::QueryItem::Key (StringToBytes (" c" )),
82- grovedb::QueryItem::Key (StringToBytes (" d" )),
83- grovedb::QueryItem::Key (StringToBytes (" e" ))},
58+ {grovedb::QueryItem::Key (grovedb::Bytes::FromString (" a" )),
59+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" b" )),
60+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" c" )),
61+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" d" )),
62+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" e" ))},
8463 /* limit=*/ 100 );
8564 if (!q1.has_value ()) {
8665 Log (ERROR, " PathQuery::New failed: {}" , q1.error ().message ());
@@ -95,11 +74,11 @@ int main()
9574 Log (INFO, " proof generated: {} bytes" , proof->value ().size ());
9675
9776 auto q1v = grovedb::PathQuery::New (root,
98- {grovedb::QueryItem::Key (StringToBytes (" a" )),
99- grovedb::QueryItem::Key (StringToBytes (" b" )),
100- grovedb::QueryItem::Key (StringToBytes (" c" )),
101- grovedb::QueryItem::Key (StringToBytes (" d" )),
102- grovedb::QueryItem::Key (StringToBytes (" e" ))},
77+ {grovedb::QueryItem::Key (grovedb::Bytes::FromString (" a" )),
78+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" b" )),
79+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" c" )),
80+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" d" )),
81+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" e" ))},
10382 /* limit=*/ 100 );
10483 if (!q1v.has_value ()) {
10584 Log (ERROR, " PathQuery::New failed: {}" , q1v.error ().message ());
@@ -112,11 +91,11 @@ int main()
11291 return EXIT_FAILURE;
11392 }
11493
115- Log (INFO, " verification succeeded, root hash: {}" , HashToHex ( vap->value ().m_root_hash ));
94+ Log (INFO, " verification succeeded, root hash: {}" , vap->value ().m_root_hash . ToString ( ));
11695 Log (INFO, " {} entries in result" , vap->value ().m_entries .size ());
11796 for (const auto & entry : vap->value ().m_entries ) {
11897 Log (INFO, " key='{}', present={}" ,
119- BytesToString ( entry.m_key ), entry.m_element .has_value ());
98+ entry.m_key . ToString ( ), entry.m_element .has_value ());
12099 }
121100
122101 // -------------------------------------------------------------------------
@@ -125,7 +104,7 @@ int main()
125104
126105 Log (INFO, " --- VerifySubsetQuery ---" );
127106 auto q_sub = grovedb::PathQuery::New (root,
128- {grovedb::QueryItem::Key (StringToBytes (" c" ))});
107+ {grovedb::QueryItem::Key (grovedb::Bytes::FromString (" c" ))});
129108 if (!q_sub.has_value ()) {
130109 Log (ERROR, " PathQuery::New failed: {}" , q_sub.error ().message ());
131110 return EXIT_FAILURE;
@@ -144,7 +123,7 @@ int main()
144123
145124 Log (INFO, " --- VerifySubsetQueryWithAbsenceProof ---" );
146125 auto q_suba = grovedb::PathQuery::New (root,
147- {grovedb::QueryItem::Key (StringToBytes (" c" ))},
126+ {grovedb::QueryItem::Key (grovedb::Bytes::FromString (" c" ))},
148127 /* limit=*/ 100 );
149128 if (!q_suba.has_value ()) {
150129 Log (ERROR, " PathQuery::New failed: {}" , q_suba.error ().message ());
@@ -165,11 +144,11 @@ int main()
165144
166145 Log (INFO, " --- VerifyQueryWithOptions ---" );
167146 auto q_opts = grovedb::PathQuery::New (root,
168- {grovedb::QueryItem::Key (StringToBytes (" a" )),
169- grovedb::QueryItem::Key (StringToBytes (" b" )),
170- grovedb::QueryItem::Key (StringToBytes (" c" )),
171- grovedb::QueryItem::Key (StringToBytes (" d" )),
172- grovedb::QueryItem::Key (StringToBytes (" e" ))},
147+ {grovedb::QueryItem::Key (grovedb::Bytes::FromString (" a" )),
148+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" b" )),
149+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" c" )),
150+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" d" )),
151+ grovedb::QueryItem::Key (grovedb::Bytes::FromString (" e" ))},
173152 /* limit=*/ 100 );
174153 if (!q_opts.has_value ()) {
175154 Log (ERROR, " PathQuery::New failed: {}" , q_opts.error ().message ());
0 commit comments