hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
json_query_factory.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_JSON_QUERY_FACTORY_HPP
7 #define IROHA_JSON_QUERY_FACTORY_HPP
8 
9 #include <typeindex>
10 #include <unordered_map>
11 #include "logger/logger_fwd.hpp"
12 #include "model/common.hpp"
14 #include "model/query.hpp"
15 #include "queries.pb.h"
16 
17 namespace iroha {
18  namespace model {
19  namespace converters {
21  public:
22  explicit JsonQueryFactory(logger::LoggerPtr log);
23 
29  optional_ptr<Query> deserialize(const std::string &query_json);
30 
36  std::string serialize(std::shared_ptr<const model::Query> model_query);
37 
38  private:
40 
41  optional_ptr<Query> deserialize(const rapidjson::Document &document);
42 
43  using Deserializer =
44  optional_ptr<Query> (JsonQueryFactory::*)(const rapidjson::Value &);
45 
46  std::unordered_map<std::string, Deserializer> deserializers_;
47  // Deserialize handlers
48  optional_ptr<Query> deserializeGetAccount(
49  const rapidjson::Value &obj_query);
50  optional_ptr<Query> deserializeGetSignatories(
51  const rapidjson::Value &obj_query);
52  optional_ptr<Query> deserializeGetAccountTransactions(
53  const rapidjson::Value &obj_query);
54  optional_ptr<Query> deserializeGetAccountAssetTransactions(
55  const rapidjson::Value &obj_query);
56  optional_ptr<Query> deserializeGetTransactions(
57  const rapidjson::Value &obj_query);
58  optional_ptr<Query> deserializeGetAccountAssets(
59  const rapidjson::Value &obj_query);
60  optional_ptr<Query> deserializeGetAccountDetail(
61  const rapidjson::Value &obj_query);
62  optional_ptr<Query> deserializeGetAssetInfo(
63  const rapidjson::Value &obj_query);
64  optional_ptr<Query> deserializeGetRoles(
65  const rapidjson::Value &obj_query);
66  optional_ptr<Query> deserializeGetRolePermissions(
67  const rapidjson::Value &obj_query);
68  // Serializers:
69  using Serializer = void (JsonQueryFactory::*)(
70  rapidjson::Document &, std::shared_ptr<const model::Query>);
71  std::unordered_map<std::type_index, Serializer> serializers_;
72  // Serialization handlers
73  void serializeGetAccount(rapidjson::Document &json_doc,
74  std::shared_ptr<const model::Query> query);
75  void serializeGetAccountAssets(
76  rapidjson::Document &json_doc,
77  std::shared_ptr<const model::Query> query);
78  void serializeGetAccountDetail(
79  rapidjson::Document &json_doc,
80  std::shared_ptr<const model::Query> query);
81  void serializeGetAccountTransactions(
82  rapidjson::Document &json_doc,
83  std::shared_ptr<const model::Query> query);
84  void serializeGetAccountAssetTransactions(
85  rapidjson::Document &json_doc,
86  std::shared_ptr<const model::Query> query);
87  void serializeGetTransactions(rapidjson::Document &json_doc,
88  std::shared_ptr<const Query> query);
89  void serializeGetSignatories(rapidjson::Document &json_doc,
90  std::shared_ptr<const model::Query> query);
91 
92  void serializeGetAssetInfo(rapidjson::Document &json_doc,
93  std::shared_ptr<const model::Query> query);
94  void serializeGetRoles(rapidjson::Document &json_doc,
95  std::shared_ptr<const model::Query> query);
96  void serializeGetRolePermissions(
97  rapidjson::Document &json_doc,
98  std::shared_ptr<const model::Query> query);
99 
100  // Logger
101  logger::LoggerPtr log_;
102  };
103  } // namespace converters
104  } // namespace model
105 } // namespace iroha
106 
107 #endif // IROHA_JSON_QUERY_FACTORY_HPP
JsonQueryFactory(logger::LoggerPtr log)
Definition: json_query_factory.cpp:22
boost::optional< std::shared_ptr< T >> optional_ptr
Definition: common.hpp:16
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: block_query.hpp:14
Definition: json_common.hpp:35
Definition: json_query_factory.hpp:20
optional_ptr< Query > deserialize(const std::string &query_json)
Definition: json_query_factory.cpp:62
std::string serialize(std::shared_ptr< const model::Query > model_query)
Definition: json_query_factory.cpp:154