Scorum
debug_node_plugin.hpp
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <scorum/app/plugin.hpp>
5 
6 #include <fc/variant_object.hpp>
7 
8 #include <map>
9 #include <fstream>
10 
11 namespace scorum {
12 namespace protocol {
13 struct chain_properties;
14 struct pow2;
15 struct signed_block;
16 } // namespace protocol
17 } // namespace scorum
18 
19 namespace graphene {
20 namespace db {
21 struct object_id_type;
22 class object;
23 } // namespace db
24 } // namespace graphene
25 
26 namespace scorum {
27 namespace plugin {
28 namespace debug_node {
29 using app::application;
30 
31 namespace detail {
32 class debug_node_plugin_impl;
33 }
34 
37 {
38 public:
40  {
41  }
43  {
44  }
45  virtual void maybe_get_private_key(fc::optional<fc::ecc::private_key>& result,
46  const scorum::chain::public_key_type& pubkey,
47  const std::string& account_name)
48  = 0;
49 };
50 
52 
60 {
61 public:
63  virtual ~debug_node_plugin();
64 
65  virtual std::string plugin_name() const override;
66  virtual void plugin_initialize(const boost::program_options::variables_map& options) override;
67  virtual void plugin_set_program_options(boost::program_options::options_description& cli,
68  boost::program_options::options_description& cfg) override;
69  virtual void plugin_startup() override;
70  virtual void plugin_shutdown() override;
71 
72  template <typename Lambda>
73  void debug_update(Lambda&& callback, uint32_t skip = scorum::chain::database::skip_nothing)
74  {
75  // this was a method on database in Graphene
76  chain::database& db = database();
77  chain::block_id_type head_id = db.head_block_id();
78  auto it = _debug_updates.find(head_id);
79  if (it == _debug_updates.end())
80  it = _debug_updates.emplace(head_id, std::vector<std::function<void(chain::database&)>>()).first;
81  it->second.emplace_back(callback);
82 
83  fc::optional<chain::signed_block> head_block = db.fetch_block_by_id(head_id);
84  FC_ASSERT(head_block.valid());
85 
86  // What the last block does has been changed by adding to node_property_object, so we have to re-apply it
87  db.pop_block();
88  db.push_block(*head_block, skip);
89  }
90 
91  uint32_t debug_generate_blocks(const std::string& debug_key,
92  uint32_t count,
94  uint32_t miss_blocks = 0,
95  private_key_storage* key_storage = nullptr);
96  uint32_t debug_generate_blocks_until(const std::string& debug_key,
97  const fc::time_point_sec& head_block_time,
98  bool generate_sparsely,
100  private_key_storage* key_storage = nullptr);
101 
102  void set_json_object_stream(const std::string& filename);
104 
105  void save_debug_updates(fc::mutable_variant_object& target);
106  void load_debug_updates(const fc::variant_object& target);
107 
108  bool logging = true;
109 
110 private:
111  void on_changed_objects(const std::vector<graphene::db::object_id_type>& ids);
112  void on_removed_objects(const std::vector<const graphene::db::object*> objs);
113  void on_applied_block(const protocol::signed_block& b);
114 
115  void apply_debug_updates();
116 
117  std::map<protocol::public_key_type, fc::ecc::private_key> _private_keys;
118 
119  boost::signals2::scoped_connection _applied_block_conn;
120 
121  std::map<protocol::block_id_type, std::vector<std::function<void(chain::database&)>>> _debug_updates;
122 };
123 } // namespace debug_node
124 } // namespace plugin
125 } // namespace scorum
application & app() const
Definition: plugin.hpp:119
chain::database & database()
Definition: plugin.hpp:115
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
optional< signed_block > fetch_block_by_id(const block_id_type &id) const
Definition: database.cpp:447
bool push_block(const signed_block &b, uint32_t skip=skip_nothing)
Definition: database.cpp:573
block_id_type head_block_id() const
Definition: database.cpp:1232
virtual void plugin_startup() override
Begin normal runtime operations.
uint32_t debug_generate_blocks_until(const std::string &debug_key, const fc::time_point_sec &head_block_time, bool generate_sparsely, uint32_t skip=scorum::chain::database::skip_nothing, private_key_storage *key_storage=nullptr)
void set_json_object_stream(const std::string &filename)
void debug_update(Lambda &&callback, uint32_t skip=scorum::chain::database::skip_nothing)
uint32_t debug_generate_blocks(const std::string &debug_key, uint32_t count, uint32_t skip=scorum::chain::database::skip_nothing, uint32_t miss_blocks=0, private_key_storage *key_storage=nullptr)
virtual void plugin_set_program_options(boost::program_options::options_description &cli, boost::program_options::options_description &cfg) override
Fill in command line parameters used by the plugin.
virtual std::string plugin_name() const override
void load_debug_updates(const fc::variant_object &target)
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
void save_debug_updates(fc::mutable_variant_object &target)
virtual void plugin_shutdown() override
Cleanly shut down the plugin.
virtual void maybe_get_private_key(fc::optional< fc::ecc::private_key > &result, const scorum::chain::public_key_type &pubkey, const std::string &account_name)=0
scorum::protocol::chain_properties chain_properties
Definition: witness.hpp:18
fc::ripemd160 block_id_type
Definition: types.hpp:63
Definition: asset.cpp:15