Kagome
Polkadot Runtime Engine in C++17
version.cpp
Go to the documentation of this file.
1 
6 #include "primitives/version.hpp"
7 
8 #include <algorithm>
9 
11 
12 namespace {
13 
14  // We break DI principle here since we need to use hasher in decode scale
15  // operator overload and we cannot inject it there
16  static std::unique_ptr<kagome::crypto::Hasher> kHasher =
17  std::make_unique<kagome::crypto::HasherImpl>();
18 } // namespace
19 
21 
22  std::optional<uint32_t> coreVersionFromApis(const ApisVec &apis) {
23  auto result = std::find_if(apis.begin(), apis.end(), [](auto &api) {
24  static auto api_id =
25  kHasher->blake2b_64(common::Buffer::fromString("Core"));
26  return api.first == api_id;
27  });
28  if (result == apis.end()) {
29  return std::nullopt;
30  }
31  return result->second;
32  }
33 
34 } // namespace kagome::primitives::detail
std::vector< Api > ApisVec
A vector of pairs of ApiId and a u32 for version.
Definition: version.hpp:36
static SLBuffer fromString(const std::string_view &src)
stores content of a string to byte array
Definition: buffer.hpp:205
std::optional< uint32_t > coreVersionFromApis(const ApisVec &apis)
Definition: version.cpp:22