diff options
author | Gav Wood <i@gavwood.com> | 2014-01-08 05:51:19 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-01-08 05:51:19 +0800 |
commit | 58d10e79be361d0c81010b7217c9d2251fdb9f1d (patch) | |
tree | fa9186507e8d407d675f770437903c966e9b921b /main.cpp | |
parent | 1d6b7cff0159a00d4eb3427bb70a02c04934714c (diff) | |
download | dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar.gz dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar.bz2 dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar.lz dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar.xz dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.tar.zst dexon-solidity-58d10e79be361d0c81010b7217c9d2251fdb9f1d.zip |
Move to semi-official new Trie format.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
@@ -33,6 +33,7 @@ using namespace eth; int main() { +/* // Test transaction. bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d"); cout << "TX: " << RLP(tx) << endl; @@ -46,10 +47,10 @@ int main() auto msg = t.rlp(false); cout << "TX w/o SIG: " << RLP(msg) << endl; cout << "RLP(TX w/o SIG): " << asHex(t.rlpString(false)) << endl; - std::string hmsg = sha256(t.rlpString(false), false); + std::string hmsg = sha3(t.rlpString(false), false); cout << "SHA256(RLP(TX w/o SIG)): 0x" << asHex(hmsg) << endl; - bytes privkey = sha256Bytes("123"); + bytes privkey = sha3Bytes("123"); secp256k1_start(); @@ -87,20 +88,32 @@ int main() int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v - 27); pubkey.resize(pubkeylen); cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl; - cout << "SENDER: " << hex << low160(eth::sha256(bytesConstRef(&pubkey).cropped(1))) << endl; + cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << endl; } - +*/ { Trie t; + cout << hex << hash256(StringMap({})) << endl; + cout << hex << t.hash256() << endl; + cout << hex << hash256({{"dog", "puppy"}, {"doe", "reindeer"}}) << endl; + t.insert("dog", "puppy"); + t.insert("doe", "reindeer"); + cout << hex << t.hash256() << endl; + cout << RLP(t.rlp()) << endl; + cout << asHex(t.rlp()) << endl; + } + { + Trie t; + t.insert("dog", "puppy"); - assert(t.sha256() == hash256({{"dog", "puppy"}})); + assert(t.hash256() == hash256({{"dog", "puppy"}})); assert(t.at("dog") == "puppy"); t.insert("doe", "reindeer"); - assert(t.sha256() == hash256({{"dog", "puppy"}, {"doe", "reindeer"}})); + assert(t.hash256() == hash256({{"dog", "puppy"}, {"doe", "reindeer"}})); assert(t.at("doe") == "reindeer"); assert(t.at("dog") == "puppy"); t.insert("dogglesworth", "cat"); - assert(t.sha256() == hash256({{"doe", "reindeer"}, {"dog", "puppy"}, {"dogglesworth", "cat"}})); + assert(t.hash256() == hash256({{"doe", "reindeer"}, {"dog", "puppy"}, {"dogglesworth", "cat"}})); assert(t.at("doe") == "reindeer"); assert(t.at("dog") == "puppy"); assert(t.at("dogglesworth") == "cat"); @@ -109,11 +122,11 @@ int main() assert(t.at("doe").empty()); assert(t.at("dogglesworth").empty()); assert(t.at("dog") == "puppy"); - assert(t.sha256() == hash256({{"dog", "puppy"}})); + assert(t.hash256() == hash256({{"dog", "puppy"}})); t.insert("horse", "stallion"); t.insert("do", "verb"); t.insert("doge", "coin"); - assert(t.sha256() == hash256({{"dog", "puppy"}, {"horse", "stallion"}, {"do", "verb"}, {"doge", "coin"}})); + assert(t.hash256() == hash256({{"dog", "puppy"}, {"horse", "stallion"}, {"do", "verb"}, {"doge", "coin"}})); assert(t.at("doge") == "coin"); assert(t.at("do") == "verb"); assert(t.at("horse") == "stallion"); @@ -121,7 +134,7 @@ int main() t.remove("horse"); t.remove("do"); t.remove("doge"); - assert(t.sha256() == hash256({{"dog", "puppy"}})); + assert(t.hash256() == hash256({{"dog", "puppy"}})); assert(t.at("dog") == "puppy"); t.remove("dog"); @@ -134,14 +147,14 @@ int main() auto v = toString(i); m.insert(make_pair(k, v)); t.insert(k, v); - assert(hash256(m) == t.sha256()); + assert(hash256(m) == t.hash256()); } while (!m.empty()) { auto k = m.begin()->first; t.remove(k); m.erase(k); - assert(hash256(m) == t.sha256()); + assert(hash256(m) == t.hash256()); } } } |