Kagome
Polkadot Runtime Engine in C++17
get_storage_hash.cpp
Go to the documentation of this file.
1 
7 
9 
10  outcome::result<void> GetStorageHash::init(
11  const jsonrpc::Request::Parameters &params) {
12  if (params.size() > 3 or params.size() < 2) {
13  throw jsonrpc::InvalidParametersFault("Incorrect number of params");
14  }
15  auto &param0 = params[0];
16 
17  if (not param0.IsString()) {
18  throw jsonrpc::InvalidParametersFault(
19  "Parameter '[child_storage_key]' must be a hex string");
20  }
21 
22  OUTCOME_TRY(child_storage_key, common::unhexWith0x(param0.AsString()));
23  child_storage_key_ = common::Buffer(std::move(child_storage_key));
24 
25  auto &param1 = params[1];
26  if (not param1.IsString()) {
27  throw jsonrpc::InvalidParametersFault(
28  "Parameter 'key' must be a hex string");
29  }
30  auto &&key_str = param1.AsString();
31  OUTCOME_TRY(key, common::unhexWith0x(key_str));
32 
33  key_ = common::Buffer(std::move(key));
34 
35  if (params.size() == 3) {
36  auto &param2 = params[2];
37  if (param2.IsString()) {
38  auto &&at_str = param2.AsString();
39  OUTCOME_TRY(at_span, common::unhexWith0x(at_str));
40  OUTCOME_TRY(at, primitives::BlockHash::fromSpan(at_span));
41  at_.emplace(at);
42  } else if (param2.IsNil()) {
43  at_ = std::nullopt;
44  } else {
45  throw jsonrpc::InvalidParametersFault(
46  "Parameter 'at' must be a hex string or null");
47  }
48  } else {
49  at_.reset();
50  }
51  return outcome::success();
52  }
53 
54  outcome::result<std::optional<primitives::BlockHash>>
56  return api_->getStorageHash(child_storage_key_, key_, at_);
57  }
58 
59 } // namespace kagome::api::child_state::request
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
std::optional< kagome::primitives::BlockHash > at_
outcome::result< std::optional< kagome::primitives::BlockHash > > execute()
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
Definition: buffer.hpp:244
static outcome::result< Blob< size_ > > fromSpan(const gsl::span< const uint8_t > &span)
Definition: blob.hpp:208
outcome::result< void > init(const jsonrpc::Request::Parameters &params)