Kagome
Polkadot Runtime Engine in C++17
state_api_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STATE_API_IMPL_HPP
7 #define KAGOME_STATE_API_IMPL_HPP
8 
15 
16 namespace kagome::runtime {
17  class RawExecutor;
18 }
19 
20 namespace kagome::api {
21 
22  class StateApiImpl final : public StateApi {
23  public:
24  enum class Error {
25  MAX_BLOCK_RANGE_EXCEEDED = 1,
26  MAX_KEY_SET_SIZE_EXCEEDED,
27  END_BLOCK_LOWER_THAN_BEGIN_BLOCK
28  };
29 
30  static constexpr size_t kMaxBlockRange = 256;
31  static constexpr size_t kMaxKeySetSize = 64;
32 
33  StateApiImpl(std::shared_ptr<blockchain::BlockHeaderRepository> block_repo,
34  std::shared_ptr<const storage::trie::TrieStorage> trie_storage,
35  std::shared_ptr<blockchain::BlockTree> block_tree,
36  std::shared_ptr<runtime::Core> runtime_core,
37  std::shared_ptr<runtime::Metadata> metadata,
38  std::shared_ptr<runtime::RawExecutor> executor);
39 
40  void setApiService(
41  std::shared_ptr<api::ApiService> const &api_service) override;
42 
43  outcome::result<common::Buffer> call(
44  std::string_view method,
45  common::Buffer data,
46  const std::optional<primitives::BlockHash> &opt_at) const override;
47 
48  outcome::result<std::vector<common::Buffer>> getKeysPaged(
49  const std::optional<common::BufferView> &prefix,
50  uint32_t keys_amount,
51  const std::optional<common::BufferView> &prev_key,
52  const std::optional<primitives::BlockHash> &block_hash_opt)
53  const override;
54 
55  outcome::result<std::optional<common::Buffer>> getStorage(
56  const common::BufferView &key) const override;
57 
58  outcome::result<std::optional<common::Buffer>> getStorageAt(
59  const common::BufferView &key,
60  const primitives::BlockHash &at) const override;
61 
62  outcome::result<std::vector<StorageChangeSet>> queryStorage(
63  gsl::span<const common::Buffer> keys,
64  const primitives::BlockHash &from,
65  std::optional<primitives::BlockHash> to) const override;
66 
67  outcome::result<std::vector<StorageChangeSet>> queryStorageAt(
68  gsl::span<const common::Buffer> keys,
69  std::optional<primitives::BlockHash> at) const override;
70 
71  outcome::result<uint32_t> subscribeStorage(
72  const std::vector<common::Buffer> &keys) override;
73 
74  outcome::result<bool> unsubscribeStorage(
75  const std::vector<uint32_t> &subscription_id) override;
76 
77  outcome::result<primitives::Version> getRuntimeVersion(
78  const std::optional<primitives::BlockHash> &at) const override;
79 
80  outcome::result<uint32_t> subscribeRuntimeVersion() override;
81  outcome::result<void> unsubscribeRuntimeVersion(
82  uint32_t subscription_id) override;
83 
84  outcome::result<std::string> getMetadata() override;
85  outcome::result<std::string> getMetadata(
86  std::string_view hex_block_hash) override;
87 
88  private:
89  std::shared_ptr<blockchain::BlockHeaderRepository> header_repo_;
90  std::shared_ptr<const storage::trie::TrieStorage> storage_;
91  std::shared_ptr<blockchain::BlockTree> block_tree_;
92  std::shared_ptr<runtime::Core> runtime_core_;
93 
94  std::weak_ptr<api::ApiService> api_service_;
95  std::shared_ptr<runtime::Metadata> metadata_;
96  std::shared_ptr<runtime::RawExecutor> executor_;
97  };
98 
99 } // namespace kagome::api
100 
102 
103 #endif // KAGOME_STATE_API_IMPL_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
std::shared_ptr< runtime::Core > runtime_core_
OUTCOME_HPP_DECLARE_ERROR(kagome::api, StateApiImpl::Error)
std::shared_ptr< blockchain::BlockHeaderRepository > header_repo_
std::shared_ptr< blockchain::BlockTree > block_tree_
std::shared_ptr< runtime::Metadata > metadata_
std::shared_ptr< runtime::RawExecutor > executor_
std::weak_ptr< api::ApiService > api_service_
std::shared_ptr< const storage::trie::TrieStorage > storage_