Scorum
budgets.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace scorum {
5 namespace chain {
6 
7 class fund_budget_object;
8 template <budget_type> class adv_budget_object;
9 
10 namespace detail {
11 asset fund_calculate_per_block(time_point_sec start, time_point_sec deadline, const asset& balance);
12 asset adv_calculate_per_block(time_point_sec start,
13  time_point_sec deadline,
14  time_point_sec block_time_sec,
15  const asset& balance);
16 }
17 
18 struct fund_budget_service_i : public base_service_i<fund_budget_object>
19 {
20  virtual const fund_budget_object&
21  create_budget(const asset& balance, fc::time_point_sec start, fc::time_point_sec end)
22  = 0;
23  virtual asset allocate_cash(const fund_budget_object& budget) = 0;
24 };
25 
26 class dbs_fund_budget : public dbs_service_base<fund_budget_service_i>
27 {
28  friend class dbservice_dbs_factory;
29 
30 protected:
31  explicit dbs_fund_budget(database& db);
32 
33 public:
34  const fund_budget_object&
35  create_budget(const asset& balance, fc::time_point_sec start, fc::time_point_sec end) override;
36 
37  asset allocate_cash(const fund_budget_object& budget) override;
38 
39 private:
41 };
42 
43 template <budget_type budget_type_v>
44 struct adv_budget_service_i : public base_service_i<adv_budget_object<budget_type_v>>
45 {
48 
50  using budgets_type = std::vector<budget_cref_type>;
51 
53  const account_name_type& owner,
54  const asset& balance,
55  fc::time_point_sec start,
56  fc::time_point_sec end,
57  const std::string& json_metadata)
58  = 0;
59 
61  virtual const adv_budget_object<budget_type_v>& get(const uuid_type& uuid) const = 0;
62  virtual bool is_exists(const uuid_type& uuid) const = 0;
64 
65  virtual budgets_type get_budgets() const = 0;
66  virtual budgets_type get_pending_budgets() const = 0;
67  virtual budgets_type get_top_budgets(const fc::time_point_sec& until, uint16_t limit) const = 0;
68  virtual budgets_type get_top_budgets(const fc::time_point_sec& until) const = 0;
69  virtual std::set<std::string> lookup_budget_owners(const std::string& lower_bound_owner_name,
70  uint32_t limit) const = 0;
71  virtual budgets_type get_budgets(const account_name_type& owner) const = 0;
72 
75  const asset& owner_incoming,
76  const asset& budget_outgoing)
77  = 0;
78 
79  virtual asset perform_pending_payouts(const budgets_type& budgets) = 0;
80  virtual void finish_budget(const uuid_type& uuid) = 0;
81  virtual budgets_type get_empty_budgets() const = 0;
82 };
83 
84 struct banner_budget_service_i : public adv_budget_service_i<budget_type::banner>
85 {
86 };
87 struct post_budget_service_i : public adv_budget_service_i<budget_type::post>
88 {
89 };
90 
91 template <budget_type> struct budget_service_traits;
93 {
95 };
97 {
99 };
100 
101 template <budget_type budget_type_v>
102 class dbs_advertising_budget : public dbs_service_base<typename budget_service_traits<budget_type_v>::service_type>
103 {
104  friend class dbservice_dbs_factory;
105 
106 protected:
107  explicit dbs_advertising_budget(database& db);
108 
109 public:
113 
115  const account_name_type& owner,
116  const asset& balance,
117  fc::time_point_sec start_date,
118  fc::time_point_sec end_date,
119  const std::string& json_metadata) override;
120 
122  const adv_budget_object<budget_type_v>& get(const uuid_type& uuid) const override;
123  bool is_exists(const uuid_type& uuid) const override;
125 
126  budgets_type get_budgets() const override;
127  budgets_type get_budgets(const account_name_type& owner) const override;
128  budgets_type get_pending_budgets() const override;
129 
130  // TODO: cover these method with unit tests after db_accessors will be introduced
131  budgets_type get_top_budgets(const fc::time_point_sec& until, uint16_t limit) const override;
132  budgets_type get_top_budgets(const fc::time_point_sec& until) const override;
133 
134  std::set<std::string> lookup_budget_owners(const std::string& lower_bound_owner_name,
135  uint32_t limit) const override;
136 
137  asset allocate_cash(const adv_budget_object<budget_type_v>& budget) override;
138 
140  const asset& owner_incoming,
141  const asset& budget_outgoing) override;
142 
143  asset perform_pending_payouts(const budgets_type& budgets) override;
144 
145  void finish_budget(const uuid_type& uuid) override;
146  budgets_type get_empty_budgets() const override;
147 
148 private:
149  void update_totals(std::function<void(adv_total_stats::budget_type_stat&)> callback);
150 
152  account_service_i& _account_svc;
153 };
154 
157 
158 } // namespace chain
159 } // namespace scorum
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
const adv_budget_object< budget_type_v > * find(const oid< adv_budget_object< budget_type_v >> &id) const override
Definition: budgets.cpp:179
budgets_type get_budgets() const override
Definition: budgets.cpp:189
std::set< std::string > lookup_budget_owners(const std::string &lower_bound_owner_name, uint32_t limit) const override
Definition: budgets.cpp:239
typename adv_budget_service_i< budget_type_v >::budgets_type budgets_type
Definition: budgets.hpp:112
void finish_budget(const uuid_type &uuid) override
Definition: budgets.cpp:338
const adv_budget_object< budget_type_v > & create_budget(const uuid_type &uuid, const account_name_type &owner, const asset &balance, fc::time_point_sec start_date, fc::time_point_sec end_date, const std::string &json_metadata) override
Definition: budgets.cpp:105
budgets_type get_pending_budgets() const override
Definition: budgets.cpp:274
budgets_type get_top_budgets(const fc::time_point_sec &until, uint16_t limit) const override
Definition: budgets.cpp:200
void update_pending_payouts(const adv_budget_object< budget_type_v > &budget, const asset &owner_incoming, const asset &budget_outgoing) override
Definition: budgets.cpp:299
budgets_type get_empty_budgets() const override
Definition: budgets.cpp:356
asset allocate_cash(const adv_budget_object< budget_type_v > &budget) override
Definition: budgets.cpp:286
asset perform_pending_payouts(const budgets_type &budgets) override
Definition: budgets.cpp:315
asset allocate_cash(const fund_budget_object &budget) override
Definition: budgets.cpp:84
dbs_fund_budget(database &db)
Definition: budgets.cpp:58
const fund_budget_object & create_budget(const asset &balance, fc::time_point_sec start, fc::time_point_sec end) override
Definition: budgets.cpp:64
asset adv_calculate_per_block(time_point_sec start, time_point_sec deadline, time_point_sec block_time_sec, const asset &balance)
Definition: budgets.cpp:35
asset fund_calculate_per_block(time_point_sec start, time_point_sec deadline, const asset &balance)
Definition: budgets.cpp:18
@ post
Rate limiting posting reward eligibility over time.
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
Definition: asset.cpp:15
boost::uuids::uuid uuid_type
Definition: types.hpp:53
virtual budgets_type get_top_budgets(const fc::time_point_sec &until) const =0
virtual budgets_type get_budgets(const account_name_type &owner) const =0
typename base_service_i< adv_budget_object< budget_type_v > >::object_cref_type budget_cref_type
Definition: budgets.hpp:49
virtual budgets_type get_budgets() const =0
virtual const adv_budget_object< budget_type_v > * find(const oid< adv_budget_object< budget_type_v >> &) const =0
virtual bool is_exists(const uuid_type &uuid) const =0
virtual budgets_type get_top_budgets(const fc::time_point_sec &until, uint16_t limit) const =0
virtual const adv_budget_object< budget_type_v > & get(const uuid_type &uuid) const =0
virtual void finish_budget(const uuid_type &uuid)=0
virtual budgets_type get_empty_budgets() const =0
virtual void update_pending_payouts(const adv_budget_object< budget_type_v > &budget, const asset &owner_incoming, const asset &budget_outgoing)=0
virtual budgets_type get_pending_budgets() const =0
virtual const adv_budget_object< budget_type_v > & get(const oid< adv_budget_object< budget_type_v >> &) const =0
std::vector< budget_cref_type > budgets_type
Definition: budgets.hpp:50
virtual asset perform_pending_payouts(const budgets_type &budgets)=0
virtual const adv_budget_object< budget_type_v > & create_budget(const uuid_type &uuid, const account_name_type &owner, const asset &balance, fc::time_point_sec start, fc::time_point_sec end, const std::string &json_metadata)=0
virtual std::set< std::string > lookup_budget_owners(const std::string &lower_bound_owner_name, uint32_t limit) const =0
virtual asset allocate_cash(const adv_budget_object< budget_type_v > &budget)=0
std::reference_wrapper< const object_type > object_cref_type
virtual const fund_budget_object & create_budget(const asset &balance, fc::time_point_sec start, fc::time_point_sec end)=0
virtual asset allocate_cash(const fund_budget_object &budget)=0