Kagome
Polkadot Runtime Engine in C++17
extrinsic_event_key_repository.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_EXTRINSIC_EVENT_KEY_REPOSITORY_HPP
7 #define KAGOME_EXTRINSIC_EVENT_KEY_REPOSITORY_HPP
8 
11 
12 namespace kagome::subscription {
13 
15  public:
17 
19  : logger_{log::createLogger("ExtrinsicEventKeyRepo", "transactions")} {}
20 
22  if (auto it = keys_.find(hash); it != keys_.end()) {
23  return it->second;
24  }
25  auto key = last_key_++;
26  keys_[hash] = key;
27  SL_DEBUG(logger_, "Registered tx {}, key is {}", hash, key);
28  return key;
29  }
30 
31  bool remove(const primitives::Transaction::Hash &hash) noexcept {
32  return keys_.erase(hash) > 0;
33  }
34 
35  std::optional<ExtrinsicKey> get(
36  const primitives::Transaction::Hash &hash) const noexcept {
37  if (auto it = keys_.find(hash); it != keys_.end()) {
38  return it->second;
39  }
40  return std::nullopt;
41  }
42 
43  private:
44  std::atomic<ExtrinsicKey> last_key_{};
45  std::unordered_map<primitives::Transaction::Hash, ExtrinsicKey> keys_;
47  };
48 
49 } // namespace kagome::subscription
50 
51 #endif // KAGOME_EXTRINSIC_EVENT_KEY_REPOSITORY_HPP
std::unordered_map< primitives::Transaction::Hash, ExtrinsicKey > keys_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
ExtrinsicKey add(const primitives::Transaction::Hash &hash) noexcept