Kagome
Polkadot Runtime Engine in C++17
block_builder_factory_impl.cpp
Go to the documentation of this file.
1 
7 
9 
10 namespace kagome::authorship {
11 
13  std::shared_ptr<runtime::Core> r_core,
14  std::shared_ptr<runtime::BlockBuilder> r_block_builder,
15  std::shared_ptr<blockchain::BlockHeaderRepository> header_backend)
16  : r_core_(std::move(r_core)),
17  r_block_builder_(std::move(r_block_builder)),
18  header_backend_(std::move(header_backend)),
19  logger_{log::createLogger("BlockBuilderFactory", "authorship")} {
20  BOOST_ASSERT(r_core_ != nullptr);
21  BOOST_ASSERT(r_block_builder_ != nullptr);
22  BOOST_ASSERT(header_backend_ != nullptr);
23  }
24 
25  outcome::result<std::unique_ptr<BlockBuilder>> BlockBuilderFactoryImpl::make(
26  const kagome::primitives::BlockInfo &parent,
27  primitives::Digest inherent_digest) const {
28 #ifndef BOOST_ASSERT_IS_VOID
29  OUTCOME_TRY(parent_number, header_backend_->getNumberById(parent.hash));
30 #endif
31  BOOST_ASSERT(parent_number == parent.number);
32 
33  auto number = parent.number + 1;
35  header.number = number;
36  header.parent_hash = parent.hash;
37  header.digest = std::move(inherent_digest);
38 
39  if (auto res = r_core_->initialize_block(header); not res) {
40  logger_->error("Core_initialize_block failed: {}", res.error().message());
41  return res.error();
42  } else {
43  return std::make_unique<BlockBuilderImpl>(
44  header, res.value(), r_block_builder_);
45  }
46  }
47 
48 } // namespace kagome::authorship
outcome::result< std::unique_ptr< BlockBuilder > > make(const kagome::primitives::BlockInfo &parent_block, primitives::Digest inherent_digest) const override
STL namespace.
Digest digest
chain-specific auxiliary data
std::shared_ptr< blockchain::BlockHeaderRepository > header_backend_
BlockBuilderFactoryImpl(std::shared_ptr< runtime::Core > r_core, std::shared_ptr< runtime::BlockBuilder > r_block_builder, std::shared_ptr< blockchain::BlockHeaderRepository > header_backend)
std::shared_ptr< runtime::BlockBuilder > r_block_builder_
BlockNumber number
index of the block in the chain
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
BlockHash parent_hash
32-byte Blake2s hash of parent header