Kagome
Polkadot Runtime Engine in C++17
state_protocol_observer_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STATE_PROTOCOL_OBSERVER_IMPL
7 #define KAGOME_STATE_PROTOCOL_OBSERVER_IMPL
8 
11 
12 #include "log/logger.hpp"
14 #include "storage/trie/types.hpp"
15 
16 namespace kagome {
17  namespace blockchain {
18  class BlockHeaderRepository;
19  }
20  namespace storage::trie {
21  class TrieStorage;
22  }
23 } // namespace kagome
24 
25 namespace kagome::network {
26 
28  : public StateProtocolObserver,
29  public std::enable_shared_from_this<StateProtocolObserverImpl> {
30  public:
31  enum class Error { INVALID_CHILD_ROOTHASH = 1, NOTFOUND_CHILD_ROOTHASH };
32 
34  std::shared_ptr<blockchain::BlockHeaderRepository> blocks_headers,
35  std::shared_ptr<storage::trie::TrieStorage> storage);
36 
37  ~StateProtocolObserverImpl() override = default;
38 
39  outcome::result<StateResponse> onStateRequest(
40  const StateRequest &request) const override;
41 
42  private:
43  outcome::result<std::pair<KeyValueStateEntry, size_t>> getEntry(
44  const storage::trie::RootHash &hash,
45  const common::Buffer &key,
46  size_t limit) const;
47 
48  std::shared_ptr<blockchain::BlockHeaderRepository> blocks_headers_;
49  std::shared_ptr<storage::trie::TrieStorage> storage_;
51  };
52 } // namespace kagome::network
53 
55 
56 #endif // KAGOME_STATE_PROTOCOL_OBSERVER_IMPL
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
OUTCOME_HPP_DECLARE_ERROR(kagome::network, StateProtocolObserverImpl::Error)
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::shared_ptr< storage::trie::TrieStorage > storage_
std::shared_ptr< blockchain::BlockHeaderRepository > blocks_headers_