Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
merkle.cpp
Go to the documentation of this file.
2#include <fc/io/raw.hpp>
3
4namespace sysio { namespace chain {
5
15 digest_type canonical_l = val;
16 canonical_l._hash[0] &= 0xFFFFFFFFFFFFFF7FULL;
17 return canonical_l;
18}
19
21 digest_type canonical_r = val;
22 canonical_r._hash[0] |= 0x0000000000000080ULL;
23 return canonical_r;
24}
25
27 return (val._hash[0] & 0x0000000000000080ULL) == 0;
28}
29
31 return (val._hash[0] & 0x0000000000000080ULL) != 0;
32}
33
34
36 if( 0 == ids.size() ) { return digest_type(); }
37
38 while( ids.size() > 1 ) {
39 if( ids.size() % 2 )
40 ids.push_back(ids.back());
41
42 for (size_t i = 0; i < ids.size() / 2; i++) {
43 ids[i] = digest_type::hash(make_canonical_pair(ids[2 * i], ids[(2 * i) + 1]));
44 }
45
46 ids.resize(ids.size() / 2);
47 }
48
49 return ids.front();
50}
51
52} } // sysio::chain
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
uint64_t _hash[4]
Definition sha256.hpp:100
checksum_type digest_type
Definition types.hpp:237
digest_type make_canonical_right(const digest_type &val)
Definition merkle.cpp:20
digest_type make_canonical_left(const digest_type &val)
Definition merkle.cpp:14
bool is_canonical_right(const digest_type &val)
Definition merkle.cpp:30
digest_type merkle(vector< digest_type > ids)
Definition merkle.cpp:35
bool is_canonical_left(const digest_type &val)
Definition merkle.cpp:26
auto make_canonical_pair(const digest_type &l, const digest_type &r)
Definition merkle.hpp:13