Kagome
Polkadot Runtime Engine in C++17
module_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_BINARYEN_WASM_MODULE_IMPL
7 #define KAGOME_CORE_RUNTIME_BINARYEN_WASM_MODULE_IMPL
8 
9 #include "runtime/module.hpp"
10 
11 #include "common/buffer.hpp"
14 
15 namespace wasm {
16  using namespace ::wasm; // NOLINT(google-build-using-namespace)
17  class Module;
18 } // namespace wasm
19 
20 namespace kagome::storage::trie {
21  class EphemeralTrieBatch;
22 }
23 
24 namespace kagome::runtime::binaryen {
25 
26  class InstanceEnvironmentFactory;
27 
32  class ModuleImpl final : public runtime::Module,
33  public std::enable_shared_from_this<ModuleImpl> {
34  public:
35  static constexpr auto kDefaultHeappages = 1024;
36  enum class Error { EMPTY_STATE_CODE = 1, INVALID_STATE_CODE };
37 
38  ModuleImpl(ModuleImpl &&) = default;
39  ModuleImpl &operator=(ModuleImpl &&) = delete;
40 
41  ModuleImpl(const ModuleImpl &) = delete;
42  ModuleImpl &operator=(const ModuleImpl &) = delete;
43 
44  ~ModuleImpl() override = default;
45 
46  static outcome::result<std::unique_ptr<ModuleImpl>> createFromCode(
47  const std::vector<uint8_t> &code,
48  std::shared_ptr<const InstanceEnvironmentFactory> env_factory_,
49  const common::Hash256 &code_hash);
50 
51  outcome::result<std::shared_ptr<ModuleInstance>> instantiate()
52  const override;
53 
54  private:
55  ModuleImpl(std::unique_ptr<wasm::Module> &&module,
56  std::shared_ptr<const InstanceEnvironmentFactory> env_factory,
57  const common::Hash256 &code_hash);
58 
59  std::shared_ptr<const InstanceEnvironmentFactory> env_factory_;
60  std::shared_ptr<wasm::Module> module_; // shared to module instances
62  };
63 
64 } // namespace kagome::runtime::binaryen
65 
67 
68 #endif // KAGOME_CORE_RUNTIME_BINARYEN_WASM_MODULE_IMPL
std::shared_ptr< wasm::Module > module_
Definition: module_impl.hpp:60
std::shared_ptr< const InstanceEnvironmentFactory > env_factory_
Definition: module_impl.hpp:59
OUTCOME_HPP_DECLARE_ERROR(kagome::runtime::binaryen, ModuleImpl::Error)