Kagome
Polkadot Runtime Engine in C++17
subscribe_storage.cpp
Go to the documentation of this file.
1 
7 
9 
10  outcome::result<void> SubscribeStorage::init(
11  const jsonrpc::Request::Parameters &params) {
12  if (params.size() > 1 or params.empty()) {
13  throw jsonrpc::InvalidParametersFault("Incorrect number of params");
14  }
15  auto &keys = params[0];
16  if (!keys.IsArray()) {
17  throw jsonrpc::InvalidParametersFault(
18  "Parameter 'params' must be a string array of the storage keys");
19  }
20 
21  auto &key_str_array = keys.AsArray();
22  key_buffers_.clear();
23  key_buffers_.reserve(key_str_array.size());
24 
25  for (auto &key_str : key_str_array) {
26  if (!key_str.IsString())
27  throw jsonrpc::InvalidParametersFault(
28  "Parameter 'params' must be a string array of the storage keys");
29 
30  OUTCOME_TRY(key, common::unhexWith0x(key_str.AsString()));
31  key_buffers_.emplace_back(std::move(key));
32  }
33  return outcome::success();
34  }
35 
36  outcome::result<uint32_t> SubscribeStorage::execute() {
37  return api_->subscribeStorage(key_buffers_);
38  }
39 
40 } // namespace kagome::api::state::request
outcome::result< void > init(const jsonrpc::Request::Parameters &params)
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