Scorum
account_statistics_plugin.cpp
Go to the documentation of this file.
4 
7 
9 
10 namespace scorum {
11 namespace account_statistics {
12 
13 namespace detail {
14 
16  : public common_statistics::common_statistics_plugin_impl<bucket_object, account_statistics_plugin>
17 {
18 public:
20  : base_plugin_impl(plugin)
21  {
22  }
24  {
25  }
26 
27  virtual void process_post_operation(const bucket_object& bucket, const operation_notification& o) override;
28 };
29 
31 {
34 
36  : _db(db)
37  , _bucket(b)
38  {
39  }
40 
41  template <typename T> void operator()(const T&) const
42  {
43  }
44 };
45 
47 {
50 
52  : _db(db)
53  , _bucket(b)
54  {
55  }
56 
57  template <typename T> void operator()(const T&) const
58  {
59  }
60 
61  void operator()(const transfer_operation& op) const
62  {
63  _db.modify(_bucket, [&](bucket_object& b) {
64  auto& from_stat = b.account_statistic[op.from];
65  from_stat.transfers_from++;
66  from_stat.scorum_sent += op.amount;
67 
68  auto& to_stat = b.account_statistic[op.to];
69  to_stat.transfers_to++;
70  to_stat.scorum_received += op.amount;
71  });
72  }
73 };
74 
76  const operation_notification& o)
77 {
78  auto& db = _self.database();
79 
80  o.op.visit(operation_process(db, bucket));
81 }
82 
83 } // namespace detail
84 
86  : plugin(app)
87  , _my(new detail::account_statistics_plugin_impl(*this))
88 {
89 }
90 
92 {
93 }
94 
95 void account_statistics_plugin::plugin_set_program_options(boost::program_options::options_description& cli,
96  boost::program_options::options_description& cfg)
97 {
98  cli.add_options()(
99  "account-stats-bucket-size",
100  boost::program_options::value<std::string>()->default_value("[60,3600,21600,86400,604800,2592000]"),
101  "Track account statistics by grouping orders into buckets of equal size measured in seconds specified as a "
102  "JSON array of numbers")(
103  "account-stats-history-per-bucket", boost::program_options::value<uint32_t>()->default_value(100),
104  "How far back in time to track history for each bucker size, measured in the number of buckets (default: 100)")(
105  "account-stats-tracked-accounts", boost::program_options::value<std::string>()->default_value("[]"),
106  "Which accounts to track the statistics of. Empty list tracks all accounts.");
107  cfg.add(cli);
108 }
109 
110 void account_statistics_plugin::plugin_initialize(const boost::program_options::variables_map& options)
111 {
112  try
113  {
114  _my->initialize();
115  }
116  FC_LOG_AND_RETHROW()
117 
118  print_greeting();
119 }
120 
122 {
124 }
125 
126 const flat_set<uint32_t>& account_statistics_plugin::get_tracked_buckets() const
127 {
128  return _my->_tracked_buckets;
129 }
130 
132 {
133  return _my->_maximum_history_per_bucket_size;
134 }
135 } // namespace account_statistics
136 } // namespace scorum
137 
#define API_ACCOUNT_STATISTICS
SCORUM_DEFINE_PLUGIN(account_statistics, scorum::account_statistics::account_statistics_plugin)
virtual void plugin_startup() override
Begin normal runtime operations.
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
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 void process_post_operation(const bucket_object &bucket, const operation_notification &o) override
void register_api_factory(const std::string &name, std::function< fc::api_ptr(const api_context &)> factory)
application & app() const
Definition: plugin.hpp:119
void print_greeting()
Definition: plugin.cpp:69
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
Definition: asset.cpp:15
fc::shared_map< account_name_type, account_metric > account_statistic
Definition: objects.hpp:42
activity_operation_process(chain::database &db, const activity_bucket_object &b)
operation_process(chain::database &db, const bucket_object &b)
Transfers SCR from one account to another.
account_name_type to
Account to transfer asset to.
asset amount
The amount of asset to transfer from from to to.