Scorum
comment.cpp
Go to the documentation of this file.
3 
4 #include <boost/lambda/lambda.hpp>
5 #include <boost/multi_index/detail/unbounded.hpp>
6 
7 #include <tuple>
8 
9 using namespace scorum::protocol;
10 
11 namespace scorum {
12 namespace chain {
13 
14 dbs_comment::dbs_comment(database& db)
15  : base_service_type(db)
16 {
17 }
18 
19 const comment_object& dbs_comment::get(const comment_id_type& comment_id) const
20 {
21  try
22  {
23  return get_by(comment_id);
24  }
25  FC_CAPTURE_AND_RETHROW((comment_id))
26 }
27 
28 const comment_object& dbs_comment::get(const account_name_type& author, const std::string& permlink) const
29 {
30  try
31  {
32  return get_by<by_permlink>(boost::make_tuple(author, permlink));
33  }
34  FC_CAPTURE_AND_RETHROW((author)(permlink))
35 }
36 
38 {
39  try
40  {
41  return get_range_by<by_cashout_time>(::boost::multi_index::unbounded,
42  ::boost::lambda::_1 <= std::make_tuple(until, ALL_IDS));
43  }
44  FC_CAPTURE_AND_RETHROW((until))
45 }
46 
48  const checker_type& filter) const
49 {
50  try
51  {
52  return get_filtered_range_by<by_created>(::boost::multi_index::unbounded,
53  ::boost::lambda::_1 <= std::make_tuple(until, ALL_IDS), filter);
54  }
55  FC_CAPTURE_AND_RETHROW((until))
56 }
57 
58 bool dbs_comment::is_exists(const account_name_type& author, const std::string& permlink) const
59 {
60  return find_by<by_permlink>(std::make_tuple(author, permlink)) != nullptr;
61 }
62 
64  const std::string& parent_permlink) const
65 {
66  auto range = get_range_by<by_parent>(
67  boost::make_tuple(parent_author, parent_permlink.c_str(), 0) <= ::boost::lambda::_1,
68  ::boost::lambda::_1 <= std::make_tuple(parent_author, parent_permlink.c_str(), ALL_IDS));
69 
70  return range;
71 }
72 
73 void dbs_comment::set_rewarded_flag(const comment_object& comment)
74 {
75  try
76  {
77  if (!comment.rewarded)
78  {
79  update(comment, [](comment_object& c) { c.rewarded = true; });
80  }
81  }
82  FC_CAPTURE_AND_RETHROW((comment.author)(comment.permlink))
83 }
84 
85 } // namespace chain
86 } // namespace scorum
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
comment_refs_type get_by_create_time(const fc::time_point_sec &until, const checker_type &) const override
Definition: comment.cpp:47
comment_refs_type get_children(const account_name_type &parent_author, const std::string &parent_permlink) const override
Definition: comment.cpp:63
void set_rewarded_flag(const comment_object &comment) override
Definition: comment.cpp:73
comment_refs_type get_by_cashout_time(const fc::time_point_sec &until) const override
Definition: comment.cpp:37
virtual void update(const modifier_type &modifier) override
virtual const object_type & get() const override
const object_type & get_by(const Key &arg) const
const unbounded_placeholder unbounded
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
Definition: asset.cpp:15
#define ALL_IDS
std::vector< typename base_service_i::object_cref_type > comment_refs_type
Definition: comment.hpp:17
std::function< bool(const comment_object &)> checker_type
Definition: comment.hpp:21