Kagome
Polkadot Runtime Engine in C++17
insert_key.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_REQUESTS_INSERT_KEY_HPP
7 #define KAGOME_REQUESTS_INSERT_KEY_HPP
8 
9 #include <jsonrpc-lean/request.h>
10 
13 #include "outcome/outcome.hpp"
14 
16 
17  class InsertKey final
18  : public details::
19  RequestType<void, std::string, std::string, std::string> {
20  public:
21  explicit InsertKey(std::shared_ptr<AuthorApi> api) : api_(std::move(api)) {
22  BOOST_ASSERT(api_);
23  };
24 
25  outcome::result<Return> execute() override {
26  OUTCOME_TRY(seed, common::unhexWith0x(getParam<1>()));
27  OUTCOME_TRY(public_key, common::unhexWith0x(getParam<2>()));
28  return api_->insertKey(crypto::decodeKeyTypeIdFromStr(getParam<0>()),
29  gsl::span(seed.data(), seed.size()),
30  gsl::span(public_key.data(), public_key.size()));
31  }
32 
33  private:
34  std::shared_ptr<AuthorApi> api_;
35  };
36 
37 } // namespace kagome::api::author::request
38 
39 #endif // KAGOME_REQUESTS_INSERT_KEY_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.
std::shared_ptr< AuthorApi > api_
Definition: insert_key.hpp:34
outcome::result< Return > execute() override
Definition: insert_key.hpp:25
InsertKey(std::shared_ptr< AuthorApi > api)
Definition: insert_key.hpp:21
KeyTypeId decodeKeyTypeIdFromStr(std::string_view str)
restores KeyTypeId from its string representation
Definition: key_type.cpp:35