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.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(
23  logger::Logger log = logger::log("JsonQueryFactory"));
24 
30  optional_ptr<Query> deserialize(const std::string &query_json);
31 
37  std::string serialize(std::shared_ptr<const model::Query> model_query);
38 
39  private:
41 
42  optional_ptr<Query> deserialize(const rapidjson::Document &document);
43 
44  using Deserializer =
45  optional_ptr<Query> (JsonQueryFactory::*)(const rapidjson::Value &);
46 
47  std::unordered_map<std::string, Deserializer> deserializers_;
48  // Deserialize handlers
49  optional_ptr<Query> deserializeGetAccount(
50  const rapidjson::Value &obj_query);
51  optional_ptr<Query> deserializeGetSignatories(
52  const rapidjson::Value &obj_query);
53  optional_ptr<Query> deserializeGetAccountTransactions(
54  const rapidjson::Value &obj_query);
55  optional_ptr<Query> deserializeGetAccountAssetTransactions(
56  const rapidjson::Value &obj_query);
57  optional_ptr<Query> deserializeGetTransactions(
58  const rapidjson::Value &obj_query);
59  optional_ptr<Query> deserializeGetAccountAssets(
60  const rapidjson::Value &obj_query);
61  optional_ptr<Query> deserializeGetAccountDetail(
62  const rapidjson::Value &obj_query);
63  optional_ptr<Query> deserializeGetAssetInfo(
64  const rapidjson::Value &obj_query);
65  optional_ptr<Query> deserializeGetRoles(
66  const rapidjson::Value &obj_query);
67  optional_ptr<Query> deserializeGetRolePermissions(
68  const rapidjson::Value &obj_query);
69  // Serializers:
70  using Serializer = void (JsonQueryFactory::*)(
71  rapidjson::Document &, std::shared_ptr<const model::Query>);
72  std::unordered_map<std::type_index, Serializer> serializers_;
73  // Serialization handlers
74  void serializeGetAccount(rapidjson::Document &json_doc,
75  std::shared_ptr<const model::Query> query);
76  void serializeGetAccountAssets(
77  rapidjson::Document &json_doc,
78  std::shared_ptr<const model::Query> query);
79  void serializeGetAccountDetail(
80  rapidjson::Document &json_doc,
81  std::shared_ptr<const model::Query> query);
82  void serializeGetAccountTransactions(
83  rapidjson::Document &json_doc,
84  std::shared_ptr<const model::Query> query);
85  void serializeGetAccountAssetTransactions(
86  rapidjson::Document &json_doc,
87  std::shared_ptr<const model::Query> query);
88  void serializeGetTransactions(rapidjson::Document &json_doc,
89  std::shared_ptr<const Query> query);
90  void serializeGetSignatories(rapidjson::Document &json_doc,
91  std::shared_ptr<const model::Query> query);
92 
93  void serializeGetAssetInfo(rapidjson::Document &json_doc,
94  std::shared_ptr<const model::Query> query);
95  void serializeGetRoles(rapidjson::Document &json_doc,
96  std::shared_ptr<const model::Query> query);
97  void serializeGetRolePermissions(
98  rapidjson::Document &json_doc,
99  std::shared_ptr<const model::Query> query);
100 
101  // Logger
102  std::shared_ptr<spdlog::logger> log_;
103  };
104  } // namespace converters
105  } // namespace model
106 } // namespace iroha
107 
108 #endif // IROHA_JSON_QUERY_FACTORY_HPP
boost::optional< std::shared_ptr< T >> optional_ptr
Definition: common.hpp:16
string(REPLACE".""/"CMAKE_SWIG_OUTDIR ${SWIG_JAVA_PKG}) else() set(CMAKE_SWIG_FLAGS"") endif() myswig_add_library(irohajava LANGUAGE java SOURCES bindings.i) unset(CMAKE_SWIG_FLAGS) swig_link_libraries(irohajava $
Definition: CMakeLists.txt:54
std::shared_ptr< spdlog::logger > Logger
Definition: logger.hpp:26
Definition: block_query.hpp:16
Logger log(const std::string &tag)
Definition: logger.cpp:48
Definition: json_common.hpp:35
JsonQueryFactory(logger::Logger log=logger::log("JsonQueryFactory"))
Definition: json_query_factory.cpp:21
Definition: json_query_factory.hpp:20
optional_ptr< Query > deserialize(const std::string &query_json)
Definition: json_query_factory.cpp:61
std::string serialize(std::shared_ptr< const model::Query > model_query)
Definition: json_query_factory.cpp:153