BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
witness.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 
26 #include <graphene/app/plugin.hpp>
28 
29 #include <fc/thread/future.hpp>
30 
31 namespace graphene { namespace witness_plugin {
32 
33 namespace block_production_condition
34 {
36  {
37  produced = 0,
43  lag = 6,
46  };
47 }
48 
50 public:
51  ~witness_plugin() { stop_block_production(); }
52 
53  std::string plugin_name()const override;
54 
55  virtual void plugin_set_program_options(
56  boost::program_options::options_description &command_line_options,
57  boost::program_options::options_description &config_file_options
58  ) override;
59 
60  void set_block_production(bool allow) { _production_enabled = allow; }
61  void stop_block_production();
62 
63  virtual void plugin_initialize( const boost::program_options::variables_map& options ) override;
64  virtual void plugin_startup() override;
65  virtual void plugin_shutdown() override;
66 
67  inline const fc::flat_map< chain::witness_id_type, fc::optional<chain::public_key_type> >& get_witness_key_cache()
68  { return _witness_key_cache; }
69 
70 private:
71  void schedule_production_loop();
74  void add_private_key(const std::string& key_id_to_wif_pair_string);
75 
77  void refresh_witness_key_cache();
78 
79  boost::program_options::variables_map _options;
80  bool _production_enabled = false;
81  bool _shutting_down = false;
82  uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT;
83  uint32_t _production_skip_flags = graphene::chain::database::skip_nothing;
84 
85  std::map<chain::public_key_type, fc::ecc::private_key, chain::pubkey_comparator> _private_keys;
86  std::set<chain::witness_id_type> _witnesses;
87  fc::future<void> _block_production_task;
88 
90  fc::flat_map< chain::witness_id_type, fc::optional<chain::public_key_type> > _witness_key_cache;
91 
92 };
93 
94 } } //graphene::witness_plugin
Definition: api.cpp:56
#define GRAPHENE_1_PERCENT
Definition: config.hpp:103
const fc::flat_map< chain::witness_id_type, fc::optional< chain::public_key_type > > & get_witness_key_cache()
Definition: witness.hpp:67