BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
es_objects.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 oxarbitrage, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/app/plugin.hpp>
28 
29 namespace graphene { namespace es_objects {
30 
31 using namespace chain;
32 
33 namespace detail
34 {
35  class es_objects_plugin_impl;
36 }
37 
39 {
40  public:
42  virtual ~es_objects_plugin();
43 
44  std::string plugin_name()const override;
45  std::string plugin_description()const override;
46  virtual void plugin_set_program_options(
47  boost::program_options::options_description& cli,
48  boost::program_options::options_description& cfg) override;
49  virtual void plugin_initialize(const boost::program_options::variables_map& options) override;
50  virtual void plugin_startup() override;
51 
53  std::unique_ptr<detail::es_objects_plugin_impl> my;
54 };
55 
59  vector<string> keys_to_rename;
60  for (auto i = o.begin(); i != o.end(); ++i) {
61  auto &element = (*i).value();
62  if (element.is_object()) {
63  const string &name = (*i).key();
64  auto &vo = element.get_object();
65  if (vo.contains(name.c_str()))
66  keys_to_rename.emplace_back(name);
67  element = adapt(vo);
68  } else if (element.is_array())
69  adapt(element.get_array());
70  }
71  for (const auto &i : keys_to_rename) {
72  string new_name = i + "_";
73  o[new_name] = variant(o[i]);
74  o.erase(i);
75  }
76  if (o.find("owner") != o.end() && o["owner"].is_string())
77  {
78  o["owner_"] = o["owner"].as_string();
79  o.erase("owner");
80  }
81  if (o.find("active_special_authority") != o.end())
82  {
83  o["active_special_authority"] = fc::json::to_string(o["active_special_authority"]);
84  }
85  if (o.find("owner_special_authority") != o.end())
86  {
87  o["owner_special_authority"] = fc::json::to_string(o["owner_special_authority"]);
88  }
89  if (o.find("feeds") != o.end())
90  {
91  o["feeds"] = fc::json::to_string(o["feeds"]);
92  }
93  if (o.find("operations") != o.end())
94  {
95  o["operations"] = fc::json::to_string(o["operations"]);
96  }
97 
98  return o;
99  }
100 
101  void adapt(fc::variants &v) {
102  for (auto &array_element : v) {
103  if (array_element.is_object())
104  array_element = adapt(array_element.get_object());
105  else if (array_element.is_array())
106  adapt(array_element.get_array());
107  else
108  array_element = array_element.as_string();
109  }
110  }
111 };
112 
113 } } //graphene::es_objects
static string to_string(const variant &v, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
Definition: json.cpp:638
void erase(const string &key)
An order-perserving dictionary of variant&#39;s.
Definition: api.cpp:56
std::vector< variant > variants
Definition: variant.hpp:170
std::unique_ptr< detail::es_objects_plugin_impl > my
Definition: es_objects.hpp:53
iterator find(const string &key) const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
An order-perserving dictionary of variant&#39;s.
fc::mutable_variant_object adapt(const variant_object &obj)
Definition: es_objects.hpp:57