Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
block_header.cpp
Go to the documentation of this file.
3#include <fc/io/raw.hpp>
4#include <fc/bitutil.hpp>
5#include <algorithm>
6
7namespace sysio { namespace chain {
9 {
10 return digest_type::hash(*this);
11 }
12
14 {
15 return fc::endian_reverse_u32(id._hash[0]);
16 }
17
19 {
20 // Do not include signed_block_header attributes in id, specifically exclude producer_signature.
21 block_id_type result = digest(); //fc::sha256::hash(*static_cast<const block_header*>(this));
22 result._hash[0] &= 0xffffffff00000000;
23 result._hash[0] += fc::endian_reverse_u32(block_num()); // store the block num in the ID, 160 bits is plenty for the hash
24 return result;
25 }
26
27 flat_multimap<uint16_t, block_header_extension> block_header::validate_and_extract_header_extensions()const {
29
30 flat_multimap<uint16_t, block_header_extension> results;
31
32 uint16_t id_type_lower_bound = 0;
33
34 for( size_t i = 0; i < header_extensions.size(); ++i ) {
35 const auto& e = header_extensions[i];
36 auto id = e.first;
37
38 SYS_ASSERT( id >= id_type_lower_bound, invalid_block_header_extension,
39 "Block header extensions are not in the correct order (ascending id types required)"
40 );
41
42 auto iter = results.emplace(std::piecewise_construct,
43 std::forward_as_tuple(id),
44 std::forward_as_tuple()
45 );
46
47 auto match = decompose_t::extract<block_header_extension>( id, e.second, iter->second );
48 SYS_ASSERT( match, invalid_block_header_extension,
49 "Block header extension with id type ${id} is not supported",
50 ("id", id)
51 );
52
53 if( match->enforce_unique ) {
54 SYS_ASSERT( i == 0 || id > id_type_lower_bound, invalid_block_header_extension,
55 "Block header extension with id type ${id} is not allowed to repeat",
56 ("id", id)
57 );
58 }
59
60
61 id_type_lower_bound = id;
62 }
63
64 return results;
65 }
66
67} }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
uint64_t id
Definition code_cache.cpp:0
uint32_t endian_reverse_u32(uint32_t x)
Definition bitutil.hpp:19
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
static uint32_t num_from_id(const block_id_type &id)
digest_type digest() const
extensions_type header_extensions
block_id_type calculate_id() const
flat_multimap< uint16_t, block_header_extension > validate_and_extract_header_extensions() const
account_query_db::get_accounts_by_authorizers_result results