Scorum
withdraw_scorumpower_objects.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <boost/multi_index/composite_key.hpp>
3 
5 
6 #include <fc/exception/exception.hpp>
7 #include <functional>
8 
9 namespace scorum {
10 namespace chain {
11 
13  : public object<withdraw_scorumpower_route_object_type, withdraw_scorumpower_route_object>
14 {
15 public:
16  CHAINBASE_DEFAULT_CONSTRUCTOR(withdraw_scorumpower_route_object)
17 
18  id_type id;
19 
22 
23  uint16_t percent = 0;
24  bool auto_vest = false;
25 };
26 
29 {
30 public:
31  CHAINBASE_DEFAULT_CONSTRUCTOR(withdraw_scorumpower_route_statistic_object)
32 
33  id_type id;
34 
36 
37  uint16_t withdraw_routes = 0u;
38 };
39 
40 using scorum::protocol::asset;
41 
43 {
44 public:
45  CHAINBASE_DEFAULT_CONSTRUCTOR(withdraw_scorumpower_object)
46 
47  id_type id;
48 
50 
51  asset vesting_withdraw_rate
52  = asset(0, SP_SYMBOL);
53  time_point_sec next_vesting_withdrawal
54  = fc::time_point_sec::maximum();
55  asset withdrawn = asset(0, SP_SYMBOL);
56  asset to_withdraw = asset(0, SP_SYMBOL);
57 };
58 
59 namespace withdraw_scorumpower_objects {
60 
62 {
63 public:
64  typedef bool result_type;
65 
66  template <typename Op> bool operator()(const Op&) const
67  {
68  FC_ASSERT(false, "Unknown type.");
69  return false;
70  }
71 
72 protected:
74  : _right(right)
75  {
76  }
77 
79 };
80 
82 {
83 public:
85  : ids_visitor(right)
86  {
87  }
88 
89  bool operator()(const account_id_type& left) const
90  {
91  return left < _right.get<account_id_type>();
92  }
93 
94  bool operator()(const dev_committee_id_type& left) const
95  {
96  return left < _right.get<dev_committee_id_type>();
97  }
98 };
99 
101 {
102 public:
104  : ids_visitor(right)
105  {
106  }
107 
108  bool operator()(const account_id_type& left) const
109  {
110  return _right.get<account_id_type>() == left;
111  }
112 
113  bool operator()(const dev_committee_id_type& left) const
114  {
115  return _right.get<dev_committee_id_type>() == left;
116  }
117 };
118 }
119 
120 struct less_for_withdrawable_id : public std::binary_function<withdrawable_id_type, withdrawable_id_type, bool>
121 {
122  bool operator()(const withdrawable_id_type& a, const withdrawable_id_type& b) const
123  {
124  using namespace withdraw_scorumpower_objects;
125 
126  if (a.which() == b.which()) // both have same type
127  {
128  return a.visit(less_ids_visitor(b));
129  }
130  return a.which() < b.which(); // compare by type
131  }
132 };
133 
135 {
136  using namespace withdraw_scorumpower_objects;
137 
138  if (a.which() == b.which())
139  {
140  return a.visit(equal_ids_visitor(b));
141  }
142 
143  return false;
144 }
145 
146 struct by_withdraw_route;
147 struct by_destination;
148 typedef shared_multi_index_container<withdraw_scorumpower_route_object,
149  indexed_by<ordered_unique<tag<by_id>,
150  member<withdraw_scorumpower_route_object,
153  ordered_unique<tag<by_withdraw_route>,
154  composite_key<withdraw_scorumpower_route_object,
155  member<withdraw_scorumpower_route_object,
157  &withdraw_scorumpower_route_object::
158  from_id>,
159  member<withdraw_scorumpower_route_object,
161  &withdraw_scorumpower_route_object::
162  to_id>>,
163  composite_key_compare<less_for_withdrawable_id,
164  less_for_withdrawable_id>>,
165  ordered_unique<tag<by_destination>,
166  composite_key<withdraw_scorumpower_route_object,
167  member<withdraw_scorumpower_route_object,
169  &withdraw_scorumpower_route_object::
170  to_id>,
171  member<withdraw_scorumpower_route_object,
173  &withdraw_scorumpower_route_object::
174  id>>,
175  composite_key_compare<less_for_withdrawable_id,
176  std::
177  less<withdraw_scorumpower_route_id_type>>>>>
179 
180 typedef shared_multi_index_container<withdraw_scorumpower_route_statistic_object,
181  indexed_by<ordered_unique<tag<by_id>,
184  &withdraw_scorumpower_route_statistic_object::
185  id>>,
186  ordered_unique<tag<by_destination>,
189  &withdraw_scorumpower_route_statistic_object::
190  from_id>,
193 
194 struct by_next_vesting_withdrawal;
195 typedef shared_multi_index_container<withdraw_scorumpower_object,
196  indexed_by<ordered_unique<tag<by_id>,
200  ordered_unique<tag<by_destination>,
205  ordered_unique<tag<by_next_vesting_withdrawal>,
206  composite_key<withdraw_scorumpower_object,
208  time_point_sec,
209  &withdraw_scorumpower_object::
210  next_vesting_withdrawal>,
213  &withdraw_scorumpower_object::
214  id>>>>>
216 
217 } // namespace chain
218 } // namespace scorum
219 
220 // clang-format off
221 FC_REFLECT_TYPENAME(scorum::chain::withdrawable_id_type)
223  (id)
224  (from_id)
225  (to_id)
226  (percent)
227  (auto_vest))
229 
231  (id)
232  (from_id)
233  (withdraw_routes))
235 
237  (id)
238  (from_id)
239  (vesting_withdraw_rate)
240  (next_vesting_withdrawal)
241  (withdrawn)
242  (to_withdraw))
244 // clang-format on
#define SP_SYMBOL
Definition: config.hpp:104
FC_REFLECT(appender_args,(appender)(stream)) FC_REFLECT_DERIVED(file_appender_args
Definition: game.cpp:4
bool is_equal_withdrawable_id(const withdrawable_id_type &a, const withdrawable_id_type &b)
oid< withdraw_scorumpower_object > withdraw_scorumpower_id_type
fc::static_variant< account_id_type, dev_committee_id_type > withdrawable_id_type
shared_multi_index_container< withdraw_scorumpower_route_statistic_object, indexed_by< ordered_unique< tag< by_id >, member< withdraw_scorumpower_route_statistic_object, withdraw_scorumpower_route_statistic_id_type, &withdraw_scorumpower_route_statistic_object::id > >, ordered_unique< tag< by_destination >, member< withdraw_scorumpower_route_statistic_object, withdrawable_id_type, &withdraw_scorumpower_route_statistic_object::from_id >, less_for_withdrawable_id > > > withdraw_scorumpower_route_statistic_index
oid< withdraw_scorumpower_route_statistic_object > withdraw_scorumpower_route_statistic_id_type
@ withdraw_scorumpower_route_statistic_object_type
shared_multi_index_container< withdraw_scorumpower_route_object, indexed_by< ordered_unique< tag< by_id >, member< withdraw_scorumpower_route_object, withdraw_scorumpower_route_id_type, &withdraw_scorumpower_route_object::id > >, ordered_unique< tag< by_withdraw_route >, composite_key< withdraw_scorumpower_route_object, member< withdraw_scorumpower_route_object, withdrawable_id_type, &withdraw_scorumpower_route_object::from_id >, member< withdraw_scorumpower_route_object, withdrawable_id_type, &withdraw_scorumpower_route_object::to_id > >, composite_key_compare< less_for_withdrawable_id, less_for_withdrawable_id > >, ordered_unique< tag< by_destination >, composite_key< withdraw_scorumpower_route_object, member< withdraw_scorumpower_route_object, withdrawable_id_type, &withdraw_scorumpower_route_object::to_id >, member< withdraw_scorumpower_route_object, withdraw_scorumpower_route_id_type, &withdraw_scorumpower_route_object::id > >, composite_key_compare< less_for_withdrawable_id, std::less< withdraw_scorumpower_route_id_type > > > > > withdraw_scorumpower_route_index
oid< withdraw_scorumpower_route_object > withdraw_scorumpower_route_id_type
shared_multi_index_container< withdraw_scorumpower_object, indexed_by< ordered_unique< tag< by_id >, member< withdraw_scorumpower_object, withdraw_scorumpower_id_type, &withdraw_scorumpower_object::id > >, ordered_unique< tag< by_destination >, member< withdraw_scorumpower_object, withdrawable_id_type, &withdraw_scorumpower_object::from_id >, less_for_withdrawable_id >, ordered_unique< tag< by_next_vesting_withdrawal >, composite_key< withdraw_scorumpower_object, member< withdraw_scorumpower_object, time_point_sec, &withdraw_scorumpower_object::next_vesting_withdrawal >, member< withdraw_scorumpower_object, withdraw_scorumpower_id_type, &withdraw_scorumpower_object::id > > > > > withdraw_scorumpower_index
Definition: asset.cpp:15
bool operator()(const withdrawable_id_type &a, const withdrawable_id_type &b) const