Kagome
Polkadot Runtime Engine in C++17
module_factory_impl.cpp
Go to the documentation of this file.
1 
7 
15 
16 namespace kagome::runtime::binaryen {
17 
19  std::shared_ptr<InstanceEnvironmentFactory> env_factory,
20  std::shared_ptr<storage::trie::TrieStorage> storage,
21  std::shared_ptr<crypto::Hasher> hasher)
22  : env_factory_{std::move(env_factory)},
23  storage_{std::move(storage)},
24  hasher_(std::move(hasher)) {
25  BOOST_ASSERT(env_factory_ != nullptr);
26  BOOST_ASSERT(storage_ != nullptr);
27  }
28 
29  outcome::result<std::unique_ptr<Module>> ModuleFactoryImpl::make(
30  gsl::span<const uint8_t> code) const {
31  std::vector<uint8_t> code_vec{code.begin(), code.end()};
32  auto res = ModuleImpl::createFromCode(
33  code_vec, env_factory_, hasher_->sha2_256(code));
34  if (res.has_value()) {
35  return std::unique_ptr<Module>(std::move(res.value()));
36  }
37  return res.error();
38  }
39 
40 } // namespace kagome::runtime::binaryen
std::shared_ptr< InstanceEnvironmentFactory > env_factory_
std::shared_ptr< storage::trie::TrieStorage > storage_
outcome::result< std::unique_ptr< Module > > make(gsl::span< const uint8_t > code) const override
ModuleFactoryImpl(std::shared_ptr< InstanceEnvironmentFactory > env_factory, std::shared_ptr< storage::trie::TrieStorage > storage, std::shared_ptr< crypto::Hasher > hasher)
std::shared_ptr< crypto::Hasher > hasher_
static outcome::result< std::unique_ptr< ModuleImpl > > createFromCode(const std::vector< uint8_t > &code, std::shared_ptr< const InstanceEnvironmentFactory > env_factory_, const common::Hash256 &code_hash)
Definition: module_impl.cpp:46