Scorum
account_objects.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <fc/fixed_string.hpp>
3 #include <fc/shared_string.hpp>
4 
7 
11 
12 #include <boost/multi_index/composite_key.hpp>
13 #include <boost/multi_index/hashed_index.hpp>
14 
15 #include <numeric>
16 
17 namespace scorum {
18 namespace chain {
19 
22 
23 // clang-format off
24 class account_object : public object<account_object_type, account_object>
25 {
26 public:
27  CHAINBASE_DEFAULT_DYNAMIC_CONSTRUCTOR(account_object, (json_metadata))
28 
29  id_type id;
30 
31  account_name_type name;
32  public_key_type memo_key;
33  fc::shared_string json_metadata;
34  account_name_type proxy;
35 
36  time_point_sec last_account_update;
37 
38  time_point_sec created;
39  bool created_by_genesis = false;
40  bool owner_challenged = false;
41  bool active_challenged = false;
42  time_point_sec last_owner_proved = time_point_sec::min();
43  time_point_sec last_active_proved = time_point_sec::min();
44  account_name_type recovery_account;
45  time_point_sec last_account_recovery;
46 
47  bool can_vote = true;
49  percent_type voting_power = SCORUM_100_PERCENT;
51  time_point_sec last_vote_time;
53  time_point_sec voting_power_restoring_time;
55  asset vote_reward_competitive_sp = asset(0, SP_SYMBOL);
56 
57  asset balance = asset(0, SCORUM_SYMBOL);
58 
59  asset scorumpower = asset(0, SP_SYMBOL);
60  asset delegated_scorumpower = asset(0, SP_SYMBOL);
61  asset received_scorumpower = asset(0, SP_SYMBOL);
62 
63  asset nft_spend_scorumpower = asset(0, SP_SYMBOL);
64 
65  fc::array<share_type, SCORUM_MAX_PROXY_RECURSION_DEPTH> proxied_vsf_votes; // = std::vector<share_type>(SCORUM_MAX_PROXY_RECURSION_DEPTH, 0 );
67 
68  uint16_t witnesses_voted_for = 0;
69 
70  time_point_sec last_post;
71  time_point_sec last_root_post = fc::time_point_sec::min();
72 
73  time_point_sec active_sp_holders_cashout_time = fc::time_point_sec::maximum();
74  asset active_sp_holders_pending_scr_reward = asset(0, SCORUM_SYMBOL);
75  asset active_sp_holders_pending_sp_reward = asset(0, SP_SYMBOL);
76 
78  share_type witness_vote_weight() const
79  {
80  return std::accumulate(proxied_vsf_votes.begin(), proxied_vsf_votes.end(), scorumpower.amount);
81  }
82  share_type proxied_vsf_votes_total() const
83  {
84  return std::accumulate(proxied_vsf_votes.begin(), proxied_vsf_votes.end(), share_type());
85  }
86 
87  asset effective_scorumpower() const
88  {
89  return scorumpower - delegated_scorumpower + received_scorumpower;
90  }
91 };
92 // clang-format on
93 
94 class account_blogging_statistic_object
95  : public object<account_blogging_statistic_object_type, account_blogging_statistic_object>
96 {
97 public:
98  CHAINBASE_DEFAULT_CONSTRUCTOR(account_blogging_statistic_object)
99 
100  id_type id;
101 
102  account_id_type account;
103 
104  uint32_t post_count = 0;
105  uint32_t comment_count = 0;
106  uint32_t vote_count = 0;
107 
108  asset curation_rewards_scr = asset(0, SCORUM_SYMBOL);
109  asset curation_rewards_sp = asset(0, SP_SYMBOL);
110 
111  asset posting_rewards_scr = asset(0, SCORUM_SYMBOL);
112  asset posting_rewards_sp = asset(0, SP_SYMBOL);
113 };
114 
115 class account_authority_object : public object<account_authority_object_type, account_authority_object>
116 {
117 public:
119  CHAINBASE_DEFAULT_DYNAMIC_CONSTRUCTOR(account_authority_object, (owner)(active)(posting))
120 
121  id_type id;
122 
123  account_name_type account;
124 
125  shared_authority owner;
126  shared_authority active;
127  shared_authority posting;
128 
129  time_point_sec last_owner_update;
130 };
131 
132 class scorumpower_delegation_object : public object<scorumpower_delegation_object_type, scorumpower_delegation_object>
133 {
134 public:
135  CHAINBASE_DEFAULT_CONSTRUCTOR(scorumpower_delegation_object)
136 
137  id_type id;
138  account_name_type delegator;
139  account_name_type delegatee;
140  asset scorumpower = asset(0, SP_SYMBOL);
141  time_point_sec min_delegation_time;
142 };
143 
144 class reg_pool_sp_delegation_object : public object<reg_pool_sp_delegation_object_type, reg_pool_sp_delegation_object>
145 {
146 public:
147  CHAINBASE_DEFAULT_CONSTRUCTOR(reg_pool_sp_delegation_object)
148 
149  id_type id;
150  account_name_type delegatee;
151  asset sp = asset(0, SP_SYMBOL);
152 };
153 
154 class scorumpower_delegation_expiration_object
155  : public object<scorumpower_delegation_expiration_object_type, scorumpower_delegation_expiration_object>
156 {
157 public:
158  CHAINBASE_DEFAULT_CONSTRUCTOR(scorumpower_delegation_expiration_object)
159 
160  id_type id;
161  account_name_type delegator;
162  asset scorumpower = asset(0, SP_SYMBOL);
163  time_point_sec expiration;
164 };
165 
166 class owner_authority_history_object
167  : public object<owner_authority_history_object_type, owner_authority_history_object>
168 {
169 public:
170  CHAINBASE_DEFAULT_DYNAMIC_CONSTRUCTOR(owner_authority_history_object, (previous_owner_authority))
171 
172  id_type id;
173 
174  account_name_type account;
175  shared_authority previous_owner_authority;
176  time_point_sec last_valid_time;
177 };
178 
179 class account_recovery_request_object
180  : public object<account_recovery_request_object_type, account_recovery_request_object>
181 {
182 public:
183  CHAINBASE_DEFAULT_DYNAMIC_CONSTRUCTOR(account_recovery_request_object, (new_owner_authority))
184 
185  id_type id;
186 
187  account_name_type account_to_recover;
188  shared_authority new_owner_authority;
189  time_point_sec expires;
190 };
191 
192 class change_recovery_account_request_object
193  : public object<change_recovery_account_request_object_type, change_recovery_account_request_object>
194 {
195 public:
196  CHAINBASE_DEFAULT_CONSTRUCTOR(change_recovery_account_request_object)
197 
198  id_type id;
199 
200  account_name_type account_to_recover;
201  account_name_type recovery_account;
202  time_point_sec effective_on;
203 };
204 
205 class account_registration_bonus_object
206  : public object<account_registration_bonus_object_type, account_registration_bonus_object>
207 {
208 public:
209  CHAINBASE_DEFAULT_CONSTRUCTOR(account_registration_bonus_object)
210 
211  id_type id;
212 
213  account_name_type account;
214 
215  asset bonus = asset(0, SP_SYMBOL);
216 
217  time_point_sec expires;
218 };
219 
220 struct by_name;
221 struct by_proxy;
222 struct by_last_post;
223 struct by_scorum_balance;
224 struct by_smp_balance;
225 struct by_created_by_genesis;
226 struct by_voting_power_restoring_time;
227 struct by_active_sp_holders_cashout_time;
228 // clang-format off
232 typedef shared_multi_index_container<account_object,
233  indexed_by<ordered_unique<tag<by_id>,
234  member<account_object,
236  &account_object::id>>,
237  ordered_unique<tag<by_name>,
238  member<account_object,
240  &account_object::name>>,
241  ordered_non_unique<tag<by_created_by_genesis>,
242  member<account_object,
243  bool,
244  &account_object::created_by_genesis>>,
245  ordered_unique<tag<by_proxy>,
246  composite_key<account_object,
247  member<account_object,
249  &account_object::proxy>,
250  member<account_object,
252  &account_object::id>>
255  >,
256  ordered_unique<tag<by_last_post>,
257  composite_key<account_object,
258  member<account_object,
259  time_point_sec,
260  &account_object::last_post>,
261  member<account_object,
263  &account_object::id>>,
264  composite_key_compare<std::greater<time_point_sec>,
265  std::less<account_id_type>>>,
266  ordered_unique<tag<by_scorum_balance>,
267  composite_key<account_object,
268  member<account_object,
269  asset,
270  &account_object::balance>,
271  member<account_object,
273  &account_object::id>>,
274  composite_key_compare<std::greater<asset>,
275  std::less<account_id_type>>>,
276  ordered_unique<tag<by_smp_balance>,
277  composite_key<account_object,
278  member<account_object,
279  asset,
280  &account_object::scorumpower>,
281  member<account_object,
283  &account_object::id>>,
284  composite_key_compare<std::greater<asset>,
285  std::less<account_id_type>>>,
286  ordered_non_unique<tag<by_voting_power_restoring_time>,
287  member<account_object,
288  time_point_sec,
289  &account_object::
290  voting_power_restoring_time>>,
291  ordered_unique<tag<by_active_sp_holders_cashout_time>,
292  composite_key<account_object,
293  member<account_object,
294  time_point_sec,
295  &account_object::
296  active_sp_holders_cashout_time>,
297  member<account_object,
299  &account_object::id>>>>>
300  account_index;
301 
302 struct by_account_id;
303 struct by_post_count;
304 struct by_vote_count;
305 
306 typedef shared_multi_index_container<account_blogging_statistic_object,
307  indexed_by<ordered_unique<tag<by_id>,
308  member<account_blogging_statistic_object,
310  &account_blogging_statistic_object::id>>,
311  ordered_unique<tag<by_account_id>,
312  member<account_blogging_statistic_object,
314  &account_blogging_statistic_object::account>>,
315  ordered_unique<tag<by_post_count>,
316  composite_key<account_blogging_statistic_object,
317  member<account_blogging_statistic_object,
318  uint32_t,
319  &account_blogging_statistic_object::
320  post_count>,
321  member<account_blogging_statistic_object,
323  &account_blogging_statistic_object::
324  account>>,
325  composite_key_compare<std::greater<uint32_t>,
326  std::less<account_id_type>>>,
327  ordered_unique<tag<by_vote_count>,
328  composite_key<account_blogging_statistic_object,
329  member<account_blogging_statistic_object,
330  uint32_t,
331  &account_blogging_statistic_object::
332  vote_count>,
333  member<account_blogging_statistic_object,
335  &account_blogging_statistic_object::
336  account>>,
337  composite_key_compare<std::greater<uint32_t>,
338  std::less<account_id_type>>>>>
339  account_blogging_statistic_index;
340 
341 struct by_account;
342 struct by_last_valid;
343 
344 typedef shared_multi_index_container<owner_authority_history_object,
345  indexed_by<ordered_unique<tag<by_id>,
346  member<owner_authority_history_object,
348  &owner_authority_history_object::id>>,
349  ordered_unique<tag<by_account>,
350  composite_key<owner_authority_history_object,
351  member<owner_authority_history_object,
353  &owner_authority_history_object::
354  account>,
355  member<owner_authority_history_object,
356  time_point_sec,
357  &owner_authority_history_object::
358  last_valid_time>,
359  member<owner_authority_history_object,
361  &owner_authority_history_object::
362  id>>,
363  composite_key_compare<std::less<account_name_type>,
364  std::less<time_point_sec>,
365  std::
366  less<owner_authority_history_id_type>>>>>
367  owner_authority_history_index;
368 
369 struct by_last_owner_update;
370 
371 typedef shared_multi_index_container<account_authority_object,
372  indexed_by<ordered_unique<tag<by_id>,
373  member<account_authority_object,
375  &account_authority_object::id>>,
376  ordered_unique<tag<by_account>,
377  composite_key<account_authority_object,
378  member<account_authority_object,
380  &account_authority_object::account>,
381  member<account_authority_object,
383  &account_authority_object::id>>,
384  composite_key_compare<std::less<account_name_type>,
385  std::
386  less<account_authority_id_type>>>,
387  ordered_unique<tag<by_last_owner_update>,
388  composite_key<account_authority_object,
389  member<account_authority_object,
390  time_point_sec,
391  &account_authority_object::
392  last_owner_update>,
393  member<account_authority_object,
395  &account_authority_object::id>>,
396  composite_key_compare<std::greater<time_point_sec>,
397  std::
398  less<account_authority_id_type>>>>>
399  account_authority_index;
400 
401 struct by_delegation;
402 
403 typedef shared_multi_index_container<scorumpower_delegation_object,
404  indexed_by<ordered_unique<tag<by_id>,
405  member<scorumpower_delegation_object,
407  &scorumpower_delegation_object::id>>,
408  ordered_unique<tag<by_delegation>,
409  composite_key<scorumpower_delegation_object,
410  member<scorumpower_delegation_object,
412  &scorumpower_delegation_object::
413  delegator>,
414  member<scorumpower_delegation_object,
416  &scorumpower_delegation_object::
417  delegatee>>,
418  composite_key_compare<std::less<account_name_type>,
419  std::less<account_name_type>>>>>
420  scorumpower_delegation_index;
421 
422 struct by_delegatee;
423 
424 typedef shared_multi_index_container<reg_pool_sp_delegation_object,
425  indexed_by<ordered_unique<tag<by_id>,
426  member<reg_pool_sp_delegation_object,
428  &reg_pool_sp_delegation_object::id>>,
429  hashed_unique<tag<by_delegatee>,
430  member<reg_pool_sp_delegation_object,
432  &reg_pool_sp_delegation_object::delegatee>>>>
433  reg_pool_sp_delegation_index;
434 
435 struct by_expiration;
436 struct by_account_expiration;
437 
438 typedef shared_multi_index_container<scorumpower_delegation_expiration_object,
439  indexed_by<ordered_unique<tag<by_id>,
440  member<scorumpower_delegation_expiration_object,
442  &scorumpower_delegation_expiration_object::id>>,
443  ordered_unique<tag<by_expiration>,
444  composite_key<scorumpower_delegation_expiration_object,
445  member<scorumpower_delegation_expiration_object,
446  time_point_sec,
447  &scorumpower_delegation_expiration_object::
448  expiration>,
449  member<scorumpower_delegation_expiration_object,
451  &scorumpower_delegation_expiration_object::
452  id>>,
453  composite_key_compare<std::less<time_point_sec>,
454  std::
455  less<scorumpower_delegation_expiration_id_type>>>,
456  ordered_unique<tag<by_account_expiration>,
457  composite_key<scorumpower_delegation_expiration_object,
458  member<scorumpower_delegation_expiration_object,
460  &scorumpower_delegation_expiration_object::
461  delegator>,
462  member<scorumpower_delegation_expiration_object,
463  time_point_sec,
464  &scorumpower_delegation_expiration_object::
465  expiration>,
466  member<scorumpower_delegation_expiration_object,
468  &scorumpower_delegation_expiration_object::
469  id>>,
470  composite_key_compare<std::less<account_name_type>,
471  std::less<time_point_sec>,
472  std::
473  less<scorumpower_delegation_expiration_id_type>>>>>
474  scorumpower_delegation_expiration_index;
475 
476 typedef shared_multi_index_container<account_recovery_request_object,
477  indexed_by<ordered_unique<tag<by_id>,
478  member<account_recovery_request_object,
480  &account_recovery_request_object::id>>,
481  ordered_unique<tag<by_account>,
482  composite_key<account_recovery_request_object,
483  member<account_recovery_request_object,
485  &account_recovery_request_object::
486  account_to_recover>,
487  member<account_recovery_request_object,
489  &account_recovery_request_object::
490  id>>,
491  composite_key_compare<std::less<account_name_type>,
492  std::
493  less<account_recovery_request_id_type>>>,
494  ordered_unique<tag<by_expiration>,
495  composite_key<account_recovery_request_object,
496  member<account_recovery_request_object,
497  time_point_sec,
498  &account_recovery_request_object::
499  expires>,
500  member<account_recovery_request_object,
502  &account_recovery_request_object::
503  id>>,
504  composite_key_compare<std::less<time_point_sec>,
505  std::
506  less<account_recovery_request_id_type>>>>>
507  account_recovery_request_index;
508 
509 struct by_effective_date;
510 
511 typedef shared_multi_index_container<change_recovery_account_request_object,
512  indexed_by<ordered_unique<tag<by_id>,
513  member<change_recovery_account_request_object,
515  &change_recovery_account_request_object::id>>,
516  ordered_unique<tag<by_account>,
517  composite_key<change_recovery_account_request_object,
518  member<change_recovery_account_request_object,
520  &change_recovery_account_request_object::
521  account_to_recover>,
522  member<change_recovery_account_request_object,
524  &change_recovery_account_request_object::
525  id>>,
526  composite_key_compare<std::less<account_name_type>,
527  std::
528  less<change_recovery_account_request_id_type>>>,
529  ordered_unique<tag<by_effective_date>,
530  composite_key<change_recovery_account_request_object,
531  member<change_recovery_account_request_object,
532  time_point_sec,
533  &change_recovery_account_request_object::
534  effective_on>,
535  member<change_recovery_account_request_object,
537  &change_recovery_account_request_object::
538  id>>,
539  composite_key_compare<std::less<time_point_sec>,
540  std::
541  less<change_recovery_account_request_id_type>>>>>
542  change_recovery_account_request_index;
543 
544 typedef shared_multi_index_container<account_registration_bonus_object,
545  indexed_by<ordered_unique<tag<by_id>,
546  member<account_registration_bonus_object,
548  &account_registration_bonus_object::id>>,
549  ordered_unique<tag<by_account>,
550  member<account_registration_bonus_object,
552  &account_registration_bonus_object::account>>,
553  ordered_unique<tag<by_expiration>,
554  composite_key<account_registration_bonus_object,
555  member<account_registration_bonus_object,
556  time_point_sec,
557  &account_registration_bonus_object::
558  expires>,
559  member<account_registration_bonus_object,
561  &account_registration_bonus_object::
562  id>>>>>
563  account_registration_bonus_index;
564 // clang-format on
565 } // namespace chain
566 } // namespace scorum
567 
568 // clang-format off
569 FC_REFLECT( scorum::chain::account_object,
570  (id)(name)(memo_key)(json_metadata)(proxy)(last_account_update)
571  (created)(created_by_genesis)
572  (owner_challenged)(active_challenged)(last_owner_proved)(last_active_proved)(recovery_account)(last_account_recovery)
573  (can_vote)(voting_power)(last_vote_time)(voting_power_restoring_time)(vote_reward_competitive_sp)
574  (balance)
575  (scorumpower)(delegated_scorumpower)(received_scorumpower)(nft_spend_scorumpower)
576  (proxied_vsf_votes)(witnesses_voted_for)
577  (last_post)(last_root_post)
578  (active_sp_holders_cashout_time)
579  (active_sp_holders_pending_scr_reward)
580  (active_sp_holders_pending_sp_reward)
581  )
582 CHAINBASE_SET_INDEX_TYPE( scorum::chain::account_object, scorum::chain::account_index )
583 
584 FC_REFLECT( scorum::chain::account_blogging_statistic_object,
585  (id)(account)
586  (post_count)(comment_count)(vote_count)
587  (curation_rewards_scr)(curation_rewards_sp)
588  (posting_rewards_scr)(posting_rewards_sp)
589  )
590 CHAINBASE_SET_INDEX_TYPE( scorum::chain::account_blogging_statistic_object, scorum::chain::account_blogging_statistic_index )
591 
592 FC_REFLECT( scorum::chain::account_authority_object,
593  (id)(account)(owner)(active)(posting)(last_owner_update)
594 )
595 CHAINBASE_SET_INDEX_TYPE( scorum::chain::account_authority_object, scorum::chain::account_authority_index )
596 
597 FC_REFLECT( scorum::chain::scorumpower_delegation_object,
598  (id)(delegator)(delegatee)(scorumpower)(min_delegation_time) )
599 CHAINBASE_SET_INDEX_TYPE( scorum::chain::scorumpower_delegation_object, scorum::chain::scorumpower_delegation_index )
600 
601 FC_REFLECT( scorum::chain::reg_pool_sp_delegation_object,
602  (id)(delegatee)(sp) )
603 CHAINBASE_SET_INDEX_TYPE( scorum::chain::reg_pool_sp_delegation_object, scorum::chain::reg_pool_sp_delegation_index )
604 
605 FC_REFLECT( scorum::chain::scorumpower_delegation_expiration_object,
606  (id)(delegator)(scorumpower)(expiration) )
607 CHAINBASE_SET_INDEX_TYPE( scorum::chain::scorumpower_delegation_expiration_object, scorum::chain::scorumpower_delegation_expiration_index )
608 
609 FC_REFLECT( scorum::chain::owner_authority_history_object,
610  (id)(account)(previous_owner_authority)(last_valid_time)
611  )
612 CHAINBASE_SET_INDEX_TYPE( scorum::chain::owner_authority_history_object, scorum::chain::owner_authority_history_index )
613 
614 FC_REFLECT( scorum::chain::account_recovery_request_object,
615  (id)(account_to_recover)(new_owner_authority)(expires)
616  )
617 CHAINBASE_SET_INDEX_TYPE( scorum::chain::account_recovery_request_object, scorum::chain::account_recovery_request_index )
618 
619 FC_REFLECT( scorum::chain::change_recovery_account_request_object,
620  (id)(account_to_recover)(recovery_account)(effective_on)
621  )
622 CHAINBASE_SET_INDEX_TYPE( scorum::chain::change_recovery_account_request_object, scorum::chain::change_recovery_account_request_index )
623 
624 FC_REFLECT( scorum::chain::account_registration_bonus_object,
625  (id)(account)(bonus)(expires)
626  )
627 CHAINBASE_SET_INDEX_TYPE( scorum::chain::account_registration_bonus_object, scorum::chain::account_registration_bonus_index )
628 
629 // clang-format on
#define SP_SYMBOL
Definition: config.hpp:104
#define SCORUM_SYMBOL
Definition: config.hpp:102
#define SCORUM_100_PERCENT
Definition: config.hpp:200
FC_REFLECT(appender_args,(appender)(stream)) FC_REFLECT_DERIVED(file_appender_args
oid< change_recovery_account_request_object > change_recovery_account_request_id_type
oid< scorumpower_delegation_expiration_object > scorumpower_delegation_expiration_id_type
oid< account_blogging_statistic_object > account_blogging_statistic_id_type
oid< account_registration_bonus_object > account_registration_bonus_id_type
oid< reg_pool_sp_delegation_object > reg_pool_sp_delegation_id_type
oid< account_authority_object > account_authority_id_type
oid< account_recovery_request_object > account_recovery_request_id_type
oid< scorumpower_delegation_object > scorumpower_delegation_id_type
oid< account_object > account_id_type
oid< owner_authority_history_object > owner_authority_history_id_type
fc::safe< share_value_type > share_type
Definition: types.hpp:73
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
uint16_t percent_type
Definition: types.hpp:69
Definition: asset.cpp:15