Scorum
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
comments_cashout_impl.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
13 
18 
19 #include <scorum/rewards_math/curve.hpp>
20 #include <scorum/rewards_math/formulas.hpp>
21 
22 #include <boost/range/adaptor/reversed.hpp>
23 #include <map>
24 
25 namespace scorum {
26 namespace chain {
27 namespace database_ns {
28 
29 using scorum::rewards_math::shares_vector_type;
31 
33 {
34 public:
36  {
40  };
41 
43  {
46  };
47 
49 
50  template <typename FundService> void update_decreasing_total_claims(FundService& fund_service)
51  {
52  using fund_object_type = typename FundService::object_type;
53 
54  const auto& rf = fund_service.get();
55 
56  auto now = dgp_service.head_block_time();
57 
58  fc::uint128_t total_claims = rewards_math::calculate_decreasing_total_claims(
59  rf.recent_claims, now, rf.last_update, SCORUM_RECENT_RSHARES_DECAY_RATE);
60 
61  fund_service.update([&](fund_object_type& rfo) {
62  rfo.recent_claims = total_claims;
63  rfo.last_update = now;
64  });
65  }
66 
67  template <typename TFundService> void reward(TFundService& fund_service, const comment_refs_type& comments);
68 
69  asset pay_for_comments(const comment_refs_type& comments, const std::vector<asset>& fund_rewards);
70 
72  asset pay_for_comments_legacy(const comment_refs_type& comments, const std::vector<asset>& fund_rewards);
73  comment_payout_result pay_for_comment_legacy(const comment_object& comment,
74  const asset& publication_reward,
75  const asset& parent_payout_value);
76 
77  void close_comment_payout(const comment_object& comment);
78 
79 private:
80  std::vector<asset> calculate_comments_payout(const comment_refs_type& comments,
81  const asset& reward_fund_balance,
82  fc::uint128_t total_claims,
83  curve_id reward_curve) const;
84 
85  fc::uint128_t
86  get_total_claims(const comment_refs_type& comments, curve_id reward_curve, fc::uint128_t recent_claims) const;
87 
88  curators_author_rewards pay_curators(const comment_object& comment, const asset& fund_reward);
89  asset pay_beneficiaries(const comment_object& comment, const asset& author_reward);
90 
91  void pay_account(const account_object& recipient, const asset& reward);
92 
93  template <class CommentStatisticService>
94  void accumulate_comment_statistic(CommentStatisticService& stat_service,
95  const comment_object& comment,
96  const asset& fund_reward,
97  const asset& total_payout,
98  const asset& author_payout,
99  const asset& curation_payout,
100  const asset& payout_from_children,
101  const asset& payout_to_parent,
102  const asset& beneficiary_payout)
103  {
105 
106  const auto& stat = stat_service.get(comment.id);
107  stat_service.update(stat, [&](comment_object_type& c) {
108  c.fund_reward_value += fund_reward;
109  c.total_payout_value += total_payout;
110  c.author_payout_value += author_payout;
111  c.curator_payout_value += curation_payout;
112  c.beneficiary_payout_value += beneficiary_payout;
113  c.from_children_payout_value += payout_from_children;
114  c.to_parent_payout_value += payout_to_parent;
115  });
116  }
117 
118  void accumulate_statistic(const comment_object& comment,
119  const account_object& author,
120  const asset& fund_reward,
121  const asset& author_payout,
122  const asset& curation_payout,
123  const asset& payout_from_children,
124  const asset& payout_to_parent,
125  const asset& beneficiary_payout,
126  asset_symbol_type reward_symbol);
127 
128  void accumulate_statistic(const account_object& voter, const asset& curation_payout);
129 
130  comment_refs_type collect_parents(const comment_refs_type& comments);
131 
132  fc::shared_string get_permlink(const fc::shared_string& str) const;
133 
134 private:
135  block_task_context& _ctx;
136  dynamic_global_property_service_i& dgp_service;
137  account_service_i& account_service;
138  account_blogging_statistic_service_i& account_blogging_statistic_service;
139  comment_service_i& comment_service;
140  comment_statistic_scr_service_i& comment_statistic_scr_service;
141  comment_statistic_sp_service_i& comment_statistic_sp_service;
142  comment_vote_service_i& comment_vote_service;
143  hardfork_property_service_i& hardfork_service;
144 };
145 }
146 }
147 }
comment_payout_result pay_for_comment_legacy(const comment_object &comment, const asset &publication_reward, const asset &parent_payout_value)
asset pay_for_comments(const comment_refs_type &comments, const std::vector< asset > &fund_rewards)
asset pay_for_comments_legacy(const comment_refs_type &comments, const std::vector< asset > &fund_rewards)
These two methods distribute comments reward across all parent comments.
void reward(TFundService &fund_service, const comment_refs_type &comments)
scorum::chain::comment_service_i::comment_refs_type comment_refs_type
uint64_t asset_symbol_type
Definition: asset.hpp:13
Definition: asset.cpp:15
std::vector< typename base_service_i::object_cref_type > comment_refs_type
Definition: comment.hpp:17
asset total_claimed_reward
amount of tokens distributed within particular comment across author, beneficiars and curators
virtual fc::time_point_sec head_block_time() const =0