BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
template_plugin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 template_plugin 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 
26 
27 namespace graphene { namespace template_plugin {
28 
29 namespace detail
30 {
31 
33 {
34  public:
35  explicit template_plugin_impl( template_plugin& _plugin );
36  virtual ~template_plugin_impl();
37 
38  void on_block( const signed_block& b );
39 
41  {
42  return _self.database();
43  }
44 
46 
47  private:
48  template_plugin& _self;
49 
50  std::string _plugin_option = "";
51 
52 };
53 
54 void template_plugin_impl::on_block( const signed_block& b )
55 {
56  wdump((b.block_num()));
57 }
58 
60  _self( _plugin )
61 {
62  // Put other code here
63 }
64 
66 {
67  // Put the real code here. If none, remove the destructor.
68 }
69 
70 } // end namespace detail
71 
73  plugin(app),
74  my( std::make_unique<detail::template_plugin_impl>(*this) )
75 {
76  // Add needed code here
77 }
78 
80 {
81  cleanup();
82 }
83 
84 std::string template_plugin::plugin_name()const
85 {
86  return "template_plugin";
87 }
89 {
90  return "template_plugin description";
91 }
92 
94  boost::program_options::options_description& cli,
95  boost::program_options::options_description& cfg
96  )
97 {
98  cli.add_options()
99  ("template_plugin_option", boost::program_options::value<std::string>(), "template_plugin option")
100  ;
101  cfg.add(cli);
102 }
103 
104 void template_plugin::plugin_initialize(const boost::program_options::variables_map& options)
105 {
106  // connect with group 0 by default to process before some special steps (e.g. snapshot or next_object_id)
107  database().applied_block.connect( 0, [this]( const signed_block& b) {
108  my->on_block(b);
109  } );
110 
111  if (options.count("template_plugin") > 0) {
112  my->_plugin_option = options["template_plugin"].as<std::string>();
113  }
114 }
115 
117 {
118  ilog("template_plugin: plugin_startup() begin");
119 }
120 
122 {
123  ilog("template_plugin: plugin_shutdown() begin");
124  cleanup();
125 }
126 
127 void template_plugin::cleanup()
128 {
129  // Add cleanup code here
130 }
131 
132 } }
graphene::template_plugin::template_plugin::plugin_name
std::string plugin_name() const override
Get the name of the plugin.
Definition: template_plugin.cpp:84
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::template_plugin::detail::template_plugin_impl::database
graphene::chain::database & database()
Definition: template_plugin.cpp:40
graphene::template_plugin::detail::template_plugin_impl::on_block
void on_block(const signed_block &b)
Definition: template_plugin.cpp:54
graphene::app::plugin::database
chain::database & database()
Definition: plugin.hpp:115
graphene::template_plugin::template_plugin::template_plugin
template_plugin(graphene::app::application &app)
Definition: template_plugin.cpp:72
graphene::template_plugin::template_plugin::plugin_startup
void plugin_startup() override
Begin normal runtime operations.
Definition: template_plugin.cpp:116
graphene::template_plugin::template_plugin::~template_plugin
~template_plugin() override
Definition: template_plugin.cpp:79
graphene::chain::database::applied_block
fc::signal< void(const signed_block &)> applied_block
Definition: database.hpp:624
graphene::app::application
Definition: application.hpp:91
wdump
#define wdump(SEQ)
Definition: logger.hpp:174
ilog
#define ilog(FORMAT,...)
Definition: logger.hpp:117
graphene::template_plugin::template_plugin::plugin_initialize
void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
Definition: template_plugin.cpp:104
graphene::template_plugin::template_plugin
Definition: template_plugin.hpp:52
graphene::template_plugin::detail::template_plugin_impl::~template_plugin_impl
virtual ~template_plugin_impl()
Definition: template_plugin.cpp:65
graphene::template_plugin::detail::template_plugin_impl
Definition: template_plugin.cpp:32
std
Definition: zeroed_array.hpp:76
graphene::template_plugin::template_plugin::plugin_shutdown
void plugin_shutdown() override
Cleanly shut down the plugin.
Definition: template_plugin.cpp:121
graphene::template_plugin::template_plugin::plugin_description
std::string plugin_description() const override
Get the description of the plugin.
Definition: template_plugin.cpp:88
graphene::protocol::signed_block
Definition: block.hpp:64
graphene::app::abstract_plugin::app
application & app() const
Get a reference of the application bound to the plugin.
Definition: plugin.hpp:46
graphene
Definition: api.cpp:48
graphene::template_plugin::template_plugin::plugin_set_program_options
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.
Definition: template_plugin.cpp:93
graphene::template_plugin::detail::template_plugin_impl::template_plugin_impl
template_plugin_impl(template_plugin &_plugin)
Definition: template_plugin.cpp:59
template_plugin.hpp