Kagome
Polkadot Runtime Engine in C++17
module_instance.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_RUNTIME_MODULE_INSTANCE_HPP
7 #define KAGOME_CORE_RUNTIME_MODULE_INSTANCE_HPP
8 
9 #include <string_view>
10 
11 #include <boost/variant.hpp>
12 #include <optional>
13 
14 #include "common/buffer.hpp"
15 #include "outcome/outcome.hpp"
18 #include "runtime/ptr_size.hpp"
19 
20 namespace kagome::runtime {
21 
22  static_assert(sizeof(float) == 4);
23  static_assert(sizeof(double) == 8);
24  using WasmValue = boost::variant<int32_t, int64_t, float, double>;
25 
31  public:
32  virtual ~ModuleInstance() = default;
33 
34  virtual const common::Hash256 &getCodeHash() const = 0;
35 
43  virtual outcome::result<PtrSize> callExportFunction(
44  std::string_view name, common::BufferView encoded_args) const = 0;
45 
46  virtual outcome::result<std::optional<WasmValue>> getGlobal(
47  std::string_view name) const = 0;
48 
49  using SegmentOffset = size_t;
50  using SegmentData = gsl::span<const uint8_t>;
51  using DataSegmentProcessor =
52  std::function<void(SegmentOffset, SegmentData)>;
53  virtual void forDataSegment(DataSegmentProcessor const &callback) const = 0;
54 
55  virtual InstanceEnvironment const &getEnvironment() const = 0;
56  virtual outcome::result<void> resetEnvironment() = 0;
57  };
58 
59 } // namespace kagome::runtime
60 
61 #endif // KAGOME_CORE_RUNTIME_MODULE_INSTANCE_HPP
std::function< void(SegmentOffset, SegmentData)> DataSegmentProcessor
virtual outcome::result< void > resetEnvironment()=0
virtual ~ModuleInstance()=default
gsl::span< const uint8_t > SegmentData
virtual void forDataSegment(DataSegmentProcessor const &callback) const =0
virtual const common::Hash256 & getCodeHash() const =0
boost::variant< int32_t, int64_t, float, double > WasmValue
virtual outcome::result< PtrSize > callExportFunction(std::string_view name, common::BufferView encoded_args) const =0
virtual outcome::result< std::optional< WasmValue > > getGlobal(std::string_view name) const =0
virtual InstanceEnvironment const & getEnvironment() const =0