BitShares-Core  5.0.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  uint64_t api_limit_get_account_history_operations = 100;
47  uint64_t api_limit_get_account_history = 100;
48  uint64_t api_limit_get_grouped_limit_orders = 101;
49  uint64_t api_limit_get_relative_account_history = 100;
50  uint64_t api_limit_get_account_history_by_operations = 100;
51  uint64_t api_limit_get_asset_holders = 100;
52  uint64_t api_limit_get_key_references = 100;
53  uint64_t api_limit_get_htlc_by = 100;
54  uint64_t api_limit_get_full_accounts = 50;
55  uint64_t api_limit_get_full_accounts_lists = 500;
56  uint64_t api_limit_get_top_voters = 200;
57  uint64_t api_limit_get_call_orders = 300;
58  uint64_t api_limit_get_settle_orders = 300;
59  uint64_t api_limit_get_assets = 101;
60  uint64_t api_limit_get_limit_orders = 300;
61  uint64_t api_limit_get_limit_orders_by_account = 101;
62  uint64_t api_limit_get_order_book = 50;
63  uint64_t api_limit_list_htlcs = 100;
64  uint64_t api_limit_lookup_accounts = 1000;
65  uint64_t api_limit_lookup_witness_accounts = 1000;
66  uint64_t api_limit_lookup_committee_member_accounts = 1000;
67  uint64_t api_limit_lookup_vote_ids = 1000;
68  uint64_t api_limit_get_account_limit_orders = 101;
69  uint64_t api_limit_get_collateral_bids = 100;
70  uint64_t api_limit_get_top_markets = 100;
71  uint64_t api_limit_get_trade_history = 100;
72  uint64_t api_limit_get_trade_history_by_sequence = 100;
73  uint64_t api_limit_get_withdraw_permissions_by_giver = 101;
74  uint64_t api_limit_get_withdraw_permissions_by_recipient = 101;
75  uint64_t api_limit_get_liquidity_pools = 101;
76  };
77 
79  {
80  public:
81  application();
82  ~application();
83 
84  void set_program_options(boost::program_options::options_description& command_line_options,
85  boost::program_options::options_description& configuration_file_options)const;
86  void initialize(const fc::path& data_dir, const boost::program_options::variables_map& options);
87  void initialize_plugins(const boost::program_options::variables_map& options);
88  void startup();
89  void shutdown();
90  void startup_plugins();
91  void shutdown_plugins();
92 
93  template<typename PluginType>
94  std::shared_ptr<PluginType> register_plugin(bool auto_load = false) {
95  auto plug = std::make_shared<PluginType>();
96  plug->plugin_set_app(this);
97 
98  string cli_plugin_desc = plug->plugin_name() + " plugin. " + plug->plugin_description() + "\nOptions";
99  boost::program_options::options_description plugin_cli_options( cli_plugin_desc ), plugin_cfg_options;
100  plug->plugin_set_program_options(plugin_cli_options, plugin_cfg_options);
101 
102  if( !plugin_cli_options.options().empty() )
103  _cli_options.add(plugin_cli_options);
104 
105  if( !plugin_cfg_options.options().empty() )
106  {
107  std::string header_name = "plugin-cfg-header-" + plug->plugin_name();
108  std::string header_desc = plug->plugin_name() + " plugin options";
109  _cfg_options.add_options()(header_name.c_str(), header_desc.c_str());
110  _cfg_options.add(plugin_cfg_options);
111  }
112 
113  add_available_plugin( plug );
114 
115  if (auto_load)
116  enable_plugin(plug->plugin_name());
117 
118  return plug;
119  }
120  std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
121 
122  template<typename PluginType>
123  std::shared_ptr<PluginType> get_plugin( const string& name ) const
124  {
125  std::shared_ptr<abstract_plugin> abs_plugin = get_plugin( name );
126  std::shared_ptr<PluginType> result = std::dynamic_pointer_cast<PluginType>( abs_plugin );
127  FC_ASSERT( result != std::shared_ptr<PluginType>(), "Unable to load plugin '${p}'", ("p",name) );
128  return result;
129  }
130 
131  net::node_ptr p2p_node();
132  std::shared_ptr<chain::database> chain_database()const;
133  void set_api_limit();
134  void set_block_production(bool producing_blocks);
135  fc::optional< api_access_info > get_api_access_info( const string& username )const;
136  void set_api_access_info(const string& username, api_access_info&& permissions);
137 
138  bool is_finished_syncing()const;
140  boost::signals2::signal<void()> syncing_finished;
141 
142  const application_options& get_options();
143 
144  void enable_plugin( const string& name );
145 
146  bool is_plugin_enabled(const string& name) const;
147 
148  std::shared_ptr<fc::thread> elasticsearch_thread;
149 
150  private:
151  void add_available_plugin( std::shared_ptr<abstract_plugin> p );
152  std::shared_ptr<detail::application_impl> my;
153 
154  boost::program_options::options_description _cli_options;
155  boost::program_options::options_description _cfg_options;
156  };
157 
158 } }
std::shared_ptr< fc::thread > elasticsearch_thread
boost::signals2::signal< void()> syncing_finished
Emitted when syncing finishes (is_finished_syncing will return true)
std::shared_ptr< node > node_ptr
Definition: node.hpp:345
Definition: api.cpp:56
std::shared_ptr< PluginType > register_plugin(bool auto_load=false)
Definition: application.hpp:94
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
#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