BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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:
42 
45 
54  uint32_t api_limit_get_top_markets = 100;
55  uint32_t api_limit_get_assets = 101;
61  uint32_t api_limit_get_top_voters = 200;
66  uint32_t api_limit_get_order_book = 50;
67  uint32_t api_limit_get_call_orders = 300;
70  uint32_t api_limit_lookup_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;
78  uint32_t api_limit_get_tickets = 101;
80  uint32_t api_limit_get_samet_funds = 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 
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;
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 
graphene::app::application_options::api_limit_get_asset_holders
uint32_t api_limit_get_asset_holders
Definition: application.hpp:56
graphene::app::application::set_api_access_info
void set_api_access_info(const string &username, api_access_info &&permissions)
Definition: application.cpp:1419
graphene::app::application::get_node_info
const string & get_node_info() const
Definition: application.cpp:1444
graphene::app::application_options::api_limit_get_collateral_bids
uint32_t api_limit_get_collateral_bids
Definition: application.hpp:69
graphene::app::application_options::api_limit_lookup_vote_ids
uint32_t api_limit_lookup_vote_ids
Definition: application.hpp:73
graphene::app::application::set_api_limit
void set_api_limit()
Definition: application.cpp:1377
database.hpp
graphene::app::application_options::api_limit_get_tickets
uint32_t api_limit_get_tickets
Definition: application.hpp:78
graphene::app::application_options::api_limit_get_samet_funds
uint32_t api_limit_get_samet_funds
Definition: application.hpp:80
graphene::app::application_options::api_limit_get_limit_orders_by_account
uint32_t api_limit_get_limit_orders_by_account
Definition: application.hpp:63
node.hpp
graphene::app::application_options::api_limit_get_withdraw_permissions_by_giver
uint32_t api_limit_get_withdraw_permissions_by_giver
Definition: application.hpp:76
graphene::app::application::enable_plugin
void enable_plugin(const string &name) const
Definition: application.cpp:1429
graphene::app::application_options::api_limit_lookup_committee_member_accounts
uint32_t api_limit_lookup_committee_member_accounts
Definition: application.hpp:72
api_access.hpp
fc::signal
boost::signals2::signal< T > signal
Definition: signals.hpp:20
graphene::net::node_ptr
std::shared_ptr< node > node_ptr
Definition: node.hpp:326
graphene::app::application_options::api_limit_get_relative_account_history
uint32_t api_limit_get_relative_account_history
Definition: application.hpp:49
graphene::app::application::get_plugin
std::shared_ptr< PluginType > get_plugin(const string &name) const
Definition: application.hpp:133
graphene::app::application::chain_database
std::shared_ptr< chain::database > chain_database() const
Definition: application.cpp:1404
graphene::app::application_options::api_limit_get_account_history_operations
uint32_t api_limit_get_account_history_operations
Definition: application.hpp:47
graphene::app::application_options::api_limit_get_account_history_by_operations
uint32_t api_limit_get_account_history_by_operations
Definition: application.hpp:48
graphene::app::application_options::api_limit_list_htlcs
uint32_t api_limit_list_htlcs
Definition: application.hpp:74
graphene::app::application_options::get_default
static constexpr application_options get_default()
Definition: application.hpp:84
graphene::app::application_options::api_limit_get_full_accounts_subscribe
uint32_t api_limit_get_full_accounts_subscribe
Definition: application.hpp:60
graphene::app::application
Definition: application.hpp:91
graphene::app::application::initialize
void initialize(const fc::path &data_dir, std::shared_ptr< boost::program_options::variables_map > options) const
Definition: application.cpp:1354
graphene::app::application_options::api_limit_get_htlc_by
uint32_t api_limit_get_htlc_by
Definition: application.hpp:75
graphene::app::application::~application
~application()
Definition: application.cpp:1167
graphene::app::application_options::api_limit_get_key_references
uint32_t api_limit_get_key_references
Definition: application.hpp:57
graphene::app::application_options::api_limit_get_account_history
uint32_t api_limit_get_account_history
Definition: application.hpp:46
graphene::app::application::get_api_access_info
fc::optional< api_access_info > get_api_access_info(const string &username) const
Definition: application.cpp:1414
graphene::app::application::elasticsearch_thread
std::shared_ptr< fc::thread > elasticsearch_thread
Definition: application.hpp:158
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
graphene::app::application_options::api_limit_get_call_orders
uint32_t api_limit_get_call_orders
Definition: application.hpp:67
graphene::app::application::get_plugin
std::shared_ptr< abstract_plugin > get_plugin(const string &name) const
Definition: application.cpp:1389
graphene::app::application_options::api_limit_get_full_accounts
uint32_t api_limit_get_full_accounts
Definition: application.hpp:58
graphene::app::application::syncing_finished
boost::signals2::signal< void()> syncing_finished
Emitted when syncing finishes (is_finished_syncing will return true)
Definition: application.hpp:150
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::app::application_options::api_limit_get_liquidity_pools
uint32_t api_limit_get_liquidity_pools
Definition: application.hpp:79
graphene::app::application_options::api_limit_get_account_limit_orders
uint32_t api_limit_get_account_limit_orders
Definition: application.hpp:64
graphene::app::application_options::api_limit_get_liquidity_pool_history
uint32_t api_limit_get_liquidity_pool_history
Definition: application.hpp:53
graphene::app::application_options::api_limit_get_withdraw_permissions_by_recipient
uint32_t api_limit_get_withdraw_permissions_by_recipient
Definition: application.hpp:77
graphene::app::application_options::api_limit_get_full_accounts_lists
uint32_t api_limit_get_full_accounts_lists
Definition: application.hpp:59
graphene::app::application_options::api_limit_get_limit_orders
uint32_t api_limit_get_limit_orders
Definition: application.hpp:62
graphene::app::application_options::api_limit_get_storage_info
uint32_t api_limit_get_storage_info
Definition: application.hpp:82
graphene::app::application_options::api_limit_get_credit_offers
uint32_t api_limit_get_credit_offers
Definition: application.hpp:81
graphene::app::application::set_program_options
void set_program_options(boost::program_options::options_description &command_line_options, boost::program_options::options_description &configuration_file_options) const
Definition: application.cpp:1173
graphene::app::application_options::api_limit_get_settle_orders
uint32_t api_limit_get_settle_orders
Definition: application.hpp:68
graphene::app::application::set_block_production
void set_block_production(bool producing_blocks)
Definition: application.cpp:1409
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::app::application::is_plugin_enabled
bool is_plugin_enabled(const string &name) const
Definition: application.cpp:1394
graphene::app::application_options::api_limit_get_assets
uint32_t api_limit_get_assets
Definition: application.hpp:55
graphene::app::application_options::api_limit_get_trade_history_by_sequence
uint32_t api_limit_get_trade_history_by_sequence
Definition: application.hpp:52
graphene::app::application::is_finished_syncing
bool is_finished_syncing() const
Definition: application.cpp:1424
graphene::app::application::register_plugin
std::shared_ptr< PluginType > register_plugin(bool auto_load=false)
Definition: application.hpp:104
graphene::app::application_options::has_market_history_plugin
bool has_market_history_plugin
Definition: application.hpp:44
graphene::app::application::startup
void startup()
Definition: application.cpp:1362
graphene::app::application::application
application()
Definition: application.cpp:1161
graphene::app::application_options::api_limit_get_market_history
uint32_t api_limit_get_market_history
Definition: application.hpp:50
graphene::app::application_options::api_limit_get_top_markets
uint32_t api_limit_get_top_markets
Definition: application.hpp:54
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
graphene::app::application::get_options
const application_options & get_options() const
Definition: application.cpp:1439
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::app::application_options::api_limit_get_top_voters
uint32_t api_limit_get_top_voters
Definition: application.hpp:61
graphene::app::api_access_info
Definition: api_access.hpp:36
graphene::app::application_options::api_limit_get_grouped_limit_orders
uint32_t api_limit_get_grouped_limit_orders
Definition: application.hpp:65
graphene::app::application_options::api_limit_lookup_witness_accounts
uint32_t api_limit_lookup_witness_accounts
Definition: application.hpp:71
graphene::app::application_options::api_limit_get_trade_history
uint32_t api_limit_get_trade_history
Definition: application.hpp:51
graphene::app::application_options::api_limit_lookup_accounts
uint32_t api_limit_lookup_accounts
Definition: application.hpp:70
graphene::app::application_options::api_limit_get_order_book
uint32_t api_limit_get_order_book
Definition: application.hpp:66
graphene
Definition: api.cpp:48
graphene::app::application_options
Definition: application.hpp:38
graphene::app::application_options::enable_subscribe_to_all
bool enable_subscribe_to_all
Definition: application.hpp:41
graphene::app::application_options::has_api_helper_indexes_plugin
bool has_api_helper_indexes_plugin
Definition: application.hpp:43
graphene::app::application::p2p_node
net::node_ptr p2p_node()
Definition: application.cpp:1399