Kagome
Polkadot Runtime Engine in C++17
query_info.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_QUERY_INFO_HPP
7 #define KAGOME_QUERY_INFO_HPP
8 
9 #include <jsonrpc-lean/request.h>
10 
13 #include "primitives/extrinsic.hpp"
15 
17 
18  class QueryInfo final
19  : public details::RequestType<primitives::RuntimeDispatchInfo,
20  std::string,
21  std::string> {
22  public:
23  explicit QueryInfo(std::shared_ptr<PaymentApi> api) : api_(std::move(api)) {
24  BOOST_ASSERT(api_);
25  };
26 
27  outcome::result<primitives::RuntimeDispatchInfo> execute() override {
28  auto ext_hex = getParam<0>();
29  OUTCOME_TRY(ext_bytes, common::unhexWith0x(ext_hex));
30  auto len = ext_bytes.size();
31  OUTCOME_TRY(extrinsic, scale::decode<primitives::Extrinsic>(ext_bytes));
32 
33  auto at_hex = getParam<1>();
34  if (at_hex.empty()) {
35  return api_->queryInfo(extrinsic, len, std::nullopt);
36  }
37  common::Hash256 at_hash;
38  OUTCOME_TRY(at, common::unhexWith0x(at_hex));
39  BOOST_ASSERT(at.size() == common::Hash256::size());
40  std::copy_n(at.cbegin(), common::Hash256::size(), at_hash.begin());
41  return api_->queryInfo(extrinsic, len, std::cref(at_hash));
42  }
43 
44  private:
45  std::shared_ptr<PaymentApi> api_;
46  };
47 
48 } // namespace kagome::api::payment::request
49 
50 #endif // KAGOME_QUERY_INFO_HPP
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.
QueryInfo(std::shared_ptr< PaymentApi > api)
Definition: query_info.hpp:23
outcome::result< primitives::RuntimeDispatchInfo > execute() override
Definition: query_info.hpp:27
static constexpr size_t size()
Definition: blob.hpp:146
std::shared_ptr< PaymentApi > api_
Definition: query_info.hpp:45