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