Kagome
Polkadot Runtime Engine in C++17
get_runtime_version.cpp
Go to the documentation of this file.
1 
7 
9 
10  GetRuntimeVersion::GetRuntimeVersion(std::shared_ptr<StateApi> api)
11  : api_(std::move(api)) {
12  BOOST_ASSERT(api_ != nullptr);
13  }
14 
15  outcome::result<void> GetRuntimeVersion::init(
16  const jsonrpc::Request::Parameters &params) {
17  if (params.size() > 1) {
18  throw jsonrpc::InvalidParametersFault("Incorrect number of params");
19  }
20 
21  auto const no_args = params.empty();
22  auto const have_nil_arg = (!no_args && params[0].IsNil());
23  auto const have_str_arg = (!no_args && params[0].IsString());
24 
25  if (no_args || have_nil_arg) {
26  at_ = std::nullopt;
27  } else if (have_str_arg) {
28  auto &&at_str = params[0].AsString();
29  OUTCOME_TRY(at_span, common::unhexWith0x(at_str));
30  OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span));
31  at_ = at;
32  } else {
33  throw jsonrpc::InvalidParametersFault(
34  "Parameter 'at' must be a hex string");
35  }
36 
37  return outcome::success();
38  }
39 
40  outcome::result<primitives::Version> GetRuntimeVersion::execute() {
41  BOOST_ASSERT(api_);
42  return api_->getRuntimeVersion(at_);
43  }
44 
45 } // namespace kagome::api::state::request
outcome::result< primitives::Version > execute()
outcome::result< std::vector< uint8_t > > unhexWith0x(std::string_view hex_with_prefix)
Unhex hex-string with 0x in the begining.
Definition: hexutil.cpp:89
STL namespace.
GetRuntimeVersion(const GetRuntimeVersion &)=delete
static outcome::result< Blob< size_ > > fromSpan(const gsl::span< const uint8_t > &span)
Definition: blob.hpp:208
std::optional< primitives::BlockHash > at_
outcome::result< void > init(jsonrpc::Request::Parameters const &params)