From 15c5527c29b1eb3ffe69cc64cbe231f0ed5858d7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 18 Jan 2014 17:15:21 +0000 Subject: [PATCH] TrieDB framework and insertion. LevelDB overlay and map backends. --- main.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 35f3fc20d..bab0d2809 100644 --- a/main.cpp +++ b/main.cpp @@ -113,6 +113,37 @@ int main() cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << endl; } */ + + { + BasicMap m; + GenericTrieDB t(&m); + t.init(); // initialise as empty tree. + cout << m; + cout << t.root() << endl; + cout << hash256(StringMap()) << endl; + + t.insert(string("test"), string("test")); + cout << m; + cout << t.root() << endl; + cout << hash256({{"test", "test"}}) << endl; + + t.insert(string("te"), string("test")); + cout << m; + cout << t.root() << endl; + cout << hash256({{"test", "test"}, {"te", "test"}}) << endl; + } + { + BasicMap m; + GenericTrieDB t(&m); + t.init(); // initialise as empty tree. + t.insert(string("a"), string("A")); + t.insert(string("b"), string("B")); + cout << m; + cout << t.root() << endl; + cout << hash256({{"b", "B"}, {"a", "A"}}) << endl; + cout << RLP(rlp256({{"b", "B"}, {"a", "A"}})) << endl; + } + return 0; cout << escaped(asString(rlp256({{"b", "B"}, {"a", "A"}})), false) << " == " << RLP(rlp256({{"b", "B"}, {"a", "A"}})) << endl; cout << escaped(asString(rlp256({{"test", "test"}})), false) << " == " << RLP(rlp256({{"test", "test"}})) << endl; cout << asHex(rlp256({{"test", "test"}, {"te", "test"}})) << endl; @@ -204,7 +235,7 @@ int main() assert(asString(rlp("dog")) == "\x43""dog"); // 2-item list - RLP twoItemList("\x82\x0f\x43""dog"); + RLP twoItemList((byte const*)"\x82\x0f\x43""dog", 6); assert(twoItemList.itemCount() == 2); assert(twoItemList[0] == 15); assert(twoItemList[1] == "dog");