BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
application.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., 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 
27 #include <graphene/net/node.hpp>
29 
30 #include <boost/program_options.hpp>
31 
32 namespace graphene { namespace app {
33  namespace detail { class application_impl; }
34  using std::string;
35 
36  class abstract_plugin;
37 
39  {
40  public:
41  bool enable_subscribe_to_all = false;
42 
43  bool has_api_helper_indexes_plugin = false;
44  bool has_market_history_plugin = false;
45 
46  uint32_t api_limit_get_account_history = 100;
47  uint32_t api_limit_get_account_history_operations = 100;
48  uint32_t api_limit_get_account_history_by_operations = 100;
49  uint32_t api_limit_get_relative_account_history = 100;
50  uint32_t api_limit_get_market_history = 200;
51  uint32_t api_limit_get_trade_history = 100;
52  uint32_t api_limit_get_trade_history_by_sequence = 100;
53  uint32_t api_limit_get_liquidity_pool_history = 101;
54  uint32_t api_limit_get_top_markets = 100;
55  uint32_t api_limit_get_assets = 101;
56  uint32_t api_limit_get_asset_holders = 100;
57  uint32_t api_limit_get_key_references = 100;
58  uint32_t api_limit_get_full_accounts = 50;
59  uint32_t api_limit_get_full_accounts_lists = 500;
60  uint32_t api_limit_get_full_accounts_subscribe = 100;
61  uint32_t api_limit_get_top_voters = 200;
62  uint32_t api_limit_get_limit_orders = 300;
63  uint32_t api_limit_get_limit_orders_by_account = 101;
64  uint32_t api_limit_get_account_limit_orders = 101;
65  uint32_t api_limit_get_grouped_limit_orders = 101;
66  uint32_t api_limit_get_order_book = 50;
67  uint32_t api_limit_get_call_orders = 300;
68  uint32_t api_limit_get_settle_orders = 300;
69  uint32_t api_limit_get_collateral_bids = 100;
70  uint32_t api_limit_lookup_accounts = 1000;
71  uint32_t api_limit_lookup_witness_accounts = 1000;
72  uint32_t api_limit_lookup_committee_member_accounts = 1000;
73  uint32_t api_limit_lookup_vote_ids = 1000;
74  uint32_t api_limit_list_htlcs = 100;
75  uint32_t api_limit_get_htlc_by = 100;
76  uint32_t api_limit_get_withdraw_permissions_by_giver = 101;
77  uint32_t api_limit_get_withdraw_permissions_by_recipient = 101;
78  uint32_t api_limit_get_tickets = 101;
79  uint32_t api_limit_get_liquidity_pools = 101;
80  uint32_t api_limit_get_samet_funds = 101;
81  uint32_t api_limit_get_credit_offers = 101;
82  uint32_t api_limit_get_storage_info = 101;
83 
84  static constexpr application_options get_default()
85  {
86  constexpr application_options default_options;
87  return default_options;
88  }
89  };
90 
92  {
93  public:
94  application();
95  ~application();
96 
97  void set_program_options(boost::program_options::options_description& command_line_options,
98  boost::program_options::options_description& configuration_file_options)const;
99  void initialize(const fc::path& data_dir,
100  std::shared_ptr<boost::program_options::variables_map> options) const;
101  void startup();
102 
103  template<typename PluginType>
104  std::shared_ptr<PluginType> register_plugin(bool auto_load = false) {
105  auto plug = std::make_shared<PluginType>(*this);
106 
107  string cli_plugin_desc = plug->plugin_name() + " plugin. " + plug->plugin_description() + "\nOptions";
108  boost::program_options::options_description plugin_cli_options( cli_plugin_desc );
109  boost::program_options::options_description plugin_cfg_options;
110  plug->plugin_set_program_options(plugin_cli_options, plugin_cfg_options);
111 
112  if( !plugin_cli_options.options().empty() )
113  _cli_options.add(plugin_cli_options);
114 
115  if( !plugin_cfg_options.options().empty() )
116  {
117  std::string header_name = "plugin-cfg-header-" + plug->plugin_name();
118  std::string header_desc = plug->plugin_name() + " plugin options";
119  _cfg_options.add_options()(header_name.c_str(), header_desc.c_str());
120  _cfg_options.add(plugin_cfg_options);
121  }
122 
123  add_available_plugin( plug );
124 
125  if (auto_load)
126  enable_plugin(plug->plugin_name());
127 
128  return plug;
129  }
130  std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
131 
132  template<typename PluginType>
133  std::shared_ptr<PluginType> get_plugin( const string& name ) const
134  {
135  std::shared_ptr<abstract_plugin> abs_plugin = get_plugin( name );
136  std::shared_ptr<PluginType> result = std::dynamic_pointer_cast<PluginType>( abs_plugin );
137  FC_ASSERT( result != std::shared_ptr<PluginType>(), "Unable to load plugin '${p}'", ("p",name) );
138  return result;
139  }
140 
141  net::node_ptr p2p_node();
142  std::shared_ptr<chain::database> chain_database()const;
143  void set_api_limit();
144  void set_block_production(bool producing_blocks);
145  fc::optional< api_access_info > get_api_access_info( const string& username )const;
146  void set_api_access_info(const string& username, api_access_info&& permissions);
147 
148  bool is_finished_syncing()const;
150  boost::signals2::signal<void()> syncing_finished;
151 
152  const application_options& get_options() const;
153 
154  void enable_plugin( const string& name ) const;
155 
156  bool is_plugin_enabled(const string& name) const;
157 
158  std::shared_ptr<fc::thread> elasticsearch_thread;
159 
160  const string& get_node_info() const;
161 
162  private:
164  void add_available_plugin( std::shared_ptr<abstract_plugin> p ) const;
165 
166  std::shared_ptr<detail::application_impl> my;
167 
168  boost::program_options::options_description _cli_options;
169  boost::program_options::options_description _cfg_options;
170  };
171 
172 } }
173 
175  ( enable_subscribe_to_all )
176  ( has_api_helper_indexes_plugin )
177  ( has_market_history_plugin )
178  ( api_limit_get_account_history )
179  ( api_limit_get_account_history_operations )
180  ( api_limit_get_account_history_by_operations )
181  ( api_limit_get_relative_account_history )
182  ( api_limit_get_market_history )
183  ( api_limit_get_trade_history )
184  ( api_limit_get_trade_history_by_sequence )
185  ( api_limit_get_liquidity_pool_history )
186  ( api_limit_get_top_markets )
187  ( api_limit_get_assets )
188  ( api_limit_get_asset_holders )
189  ( api_limit_get_key_references )
190  ( api_limit_get_full_accounts )
191  ( api_limit_get_full_accounts_lists )
192  ( api_limit_get_full_accounts_subscribe )
193  ( api_limit_get_top_voters )
194  ( api_limit_get_limit_orders )
195  ( api_limit_get_limit_orders_by_account )
196  ( api_limit_get_account_limit_orders )
197  ( api_limit_get_grouped_limit_orders )
198  ( api_limit_get_order_book )
199  ( api_limit_get_call_orders )
200  ( api_limit_get_settle_orders )
201  ( api_limit_get_collateral_bids )
202  ( api_limit_lookup_accounts )
203  ( api_limit_lookup_witness_accounts )
204  ( api_limit_lookup_committee_member_accounts )
205  ( api_limit_lookup_vote_ids )
206  ( api_limit_list_htlcs )
207  ( api_limit_get_htlc_by )
208  ( api_limit_get_withdraw_permissions_by_giver )
209  ( api_limit_get_withdraw_permissions_by_recipient )
210  ( api_limit_get_tickets )
211  ( api_limit_get_liquidity_pools )
212  ( api_limit_get_samet_funds )
213  ( api_limit_get_credit_offers )
214  ( api_limit_get_storage_info )
215  )
216 
std::shared_ptr< fc::thread > elasticsearch_thread
boost::signals2::signal< void()> syncing_finished
Emitted when syncing finishes (is_finished_syncing will return true)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
static constexpr application_options get_default()
Definition: application.hpp:84
Definition: api.cpp:48
std::shared_ptr< PluginType > register_plugin(bool auto_load=false)
std::shared_ptr< node > node_ptr
Definition: node.hpp:326
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
std::shared_ptr< PluginType > get_plugin(const string &name) const
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28