BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
account_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/chain/types.hpp>
29 
30 #include <boost/multi_index/composite_key.hpp>
31 
32 namespace graphene { namespace chain {
33  class database;
34  class account_object;
35  class vesting_balance_object;
36 
46  class account_statistics_object : public graphene::db::abstract_object<account_statistics_object,
47  implementation_ids, impl_account_statistics_object_type>
48  {
49  public:
50  account_id_type owner;
51 
52  string name;
53 
57  account_history_id_type most_recent_op;
59  uint64_t total_ops = 0;
61  uint64_t removed_ops = 0;
62 
69 
72 
75 
78 
81 
84 
88 
89  bool has_cashback_vb = false;
90 
91  bool is_voting = false;
92 
93  time_point_sec last_vote_time;
94 
97  uint64_t vp_all = 0;
98  uint64_t vp_active = 0;
99  uint64_t vp_committee = 0;
100  uint64_t vp_witness = 0;
101  uint64_t vp_worker = 0;
102  time_point_sec vote_tally_time;
107 
109  inline bool has_some_core_voting() const
110  {
112  || total_core_pol > 0 );
113  }
114 
119 
134 
136  inline bool has_pending_fees() const { return pending_fees > 0 || pending_vested_fees > 0; }
137 
139  inline bool need_maintenance() const { return has_some_core_voting() || has_pending_fees(); }
140 
142  void process_fees(const account_object& a, database& d) const;
143 
147  void pay_fee( share_type core_fee, share_type cashback_vesting_threshold );
148  };
149 
157  class account_balance_object : public abstract_object<account_balance_object,
158  implementation_ids, impl_account_balance_object_type>
159  {
160  public:
161  account_id_type owner;
162  asset_id_type asset_type;
165  bool maintenance_flag = false;
166 
167  asset get_balance()const { return asset(balance, asset_type); }
168  void adjust_balance(const asset& delta);
169  };
170 
171 
180  class account_object : public graphene::db::abstract_object<account_object, protocol_ids, account_object_type>
181  {
182  public:
192 
194  account_id_type registrar;
196  account_id_type referrer;
198  account_id_type lifetime_referrer;
199 
207 
209  string name;
210 
221 
223 
226 
229  account_statistics_id_type statistics;
230 
237  flat_set<account_id_type> whitelisting_accounts;
238 
248  set<account_id_type> whitelisted_accounts;
250  set<account_id_type> blacklisted_accounts;
252 
253 
260  flat_set<account_id_type> blacklisting_accounts;
261 
266 
269 
274  uint8_t top_n_control_flags = 0;
275  static const uint8_t top_n_control_owner = 1;
276  static const uint8_t top_n_control_active = 2;
277 
284 
286  uint32_t creation_block_num = 0;
289 
291  {
294  }
295 
296  template<typename DB>
297  const vesting_balance_object& cashback_balance(const DB& db)const
298  {
300  return db.get(*cashback_vb);
301  }
302 
304  bool is_lifetime_member()const
305  {
307  }
310  {
311  return now > membership_expiration_date;
312  }
316  {
317  return !is_lifetime_member() && !is_basic_account(now);
318  }
320  bool is_member(time_point_sec now)const
321  {
322  return !is_basic_account(now);
323  }
324  };
325 
331  {
332  public:
333  virtual void object_inserted( const object& obj ) override;
334  virtual void object_removed( const object& obj ) override;
335  virtual void about_to_modify( const object& before ) override;
336  virtual void object_modified( const object& after ) override;
337 
338 
340  map< account_id_type, set<account_id_type> > account_to_account_memberships;
341  map< public_key_type, set<account_id_type>, pubkey_comparator > account_to_key_memberships;
343  map< address, set<account_id_type> > account_to_address_memberships;
344 
345 
346  protected:
347  set<account_id_type> get_account_members( const account_object& a )const;
348  set<public_key_type, pubkey_comparator> get_key_members( const account_object& a )const;
349  set<address> get_address_members( const account_object& a )const;
350 
351  set<account_id_type> before_account_members;
352  set<public_key_type, pubkey_comparator> before_key_members;
354  };
355 
356 
362  {
363  public:
364  virtual void object_inserted( const object& obj ) override;
365  virtual void object_removed( const object& obj ) override;
366  virtual void about_to_modify( const object& before ) override;
367  virtual void object_modified( const object& after ) override;
368 
369  const map< asset_id_type, const account_balance_object* >& get_account_balances(
370  const account_id_type& acct )const;
371  const account_balance_object* get_account_balance( const account_id_type& acct,
372  const asset_id_type& asset )const;
373 
374  private:
375  static const uint8_t bits;
376  static const uint64_t mask;
377 
379  vector< vector< map< asset_id_type, const account_balance_object* > > > balances;
380  std::stack< object_id_type > ids_being_modified;
381  };
382 
383  struct by_asset_balance;
384  struct by_maintenance_flag;
388  typedef multi_index_container<
390  indexed_by<
391  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
392  ordered_non_unique< tag<by_maintenance_flag>,
393  member< account_balance_object, bool, &account_balance_object::maintenance_flag > >,
394  ordered_unique< tag<by_asset_balance>,
395  composite_key<
397  member<account_balance_object, asset_id_type, &account_balance_object::asset_type>,
398  member<account_balance_object, share_type, &account_balance_object::balance>,
399  member<account_balance_object, account_id_type, &account_balance_object::owner>
400  >,
401  composite_key_compare<
402  std::less< asset_id_type >,
403  std::greater< share_type >,
404  std::less< account_id_type >
405  >
406  >
407  >
409 
414 
415  struct by_name;
416 
420  typedef multi_index_container<
422  indexed_by<
423  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
424  ordered_unique< tag<by_name>, member<account_object, string, &account_object::name> >
425  >
427 
432 
433  struct by_maintenance_seq;
434  struct by_voting_power_active;
435 
439  typedef multi_index_container<
441  indexed_by<
442  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
443  ordered_unique< tag<by_maintenance_seq>,
444  composite_key<
446  const_mem_fun<account_statistics_object, bool, &account_statistics_object::need_maintenance>,
447  member<account_statistics_object, string, &account_statistics_object::name>
448  >
449  >,
450  ordered_non_unique< tag<by_voting_power_active>,
451  composite_key<
453  member<account_statistics_object, time_point_sec, &account_statistics_object::vote_tally_time>,
454  member<account_statistics_object, uint64_t, &account_statistics_object::vp_active>
455  >,
456  composite_key_compare<
457  std::greater< time_point_sec >,
458  std::greater< uint64_t >
459  >
460  >
461  >
463 
468 
469 }}
470 
474 
478 
graphene::chain::account_object::is_annual_member
bool is_annual_member(time_point_sec now) const
Definition: account_object.hpp:315
graphene::chain::account_balance_object::owner
account_id_type owner
Definition: account_object.hpp:161
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::chain::account_statistics_object::vp_all
uint64_t vp_all
all voting power.
Definition: account_object.hpp:97
graphene::chain::account_statistics_object::most_recent_op
account_history_id_type most_recent_op
Definition: account_object.hpp:57
graphene::chain::account_statistics_object::process_fees
void process_fees(const account_object &a, database &d) const
Split up and pay out pending_fees and pending_vested_fees.
Definition: account_object.cpp:53
graphene::chain::balances_by_account_index::get_account_balance
const account_balance_object * get_account_balance(const account_id_type &acct, const asset_id_type &asset) const
Definition: account_object.cpp:301
graphene::chain::account_member_index::get_account_members
set< account_id_type > get_account_members(const account_object &a) const
Definition: account_object.cpp:108
graphene::chain::account_object::lifetime_referrer
account_id_type lifetime_referrer
The lifetime member at the top of the referral tree. Receives a percentage of referral rewards.
Definition: account_object.hpp:198
graphene::chain::account_statistics_object::total_pol_value
share_type total_pol_value
Total value of tickets whose current type is not lock_forever.
Definition: account_object.hpp:83
graphene::chain::account_object::blacklisting_accounts
flat_set< account_id_type > blacklisting_accounts
Definition: account_object.hpp:260
graphene::chain::account_object::has_special_authority
bool has_special_authority() const
Definition: account_object.hpp:290
fc::static_variant
Definition: raw_fwd.hpp:27
graphene::chain::account_statistics_object::has_cashback_vb
bool has_cashback_vb
redundantly store this for better maintenance performance
Definition: account_object.hpp:89
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::chain::account_member_index::object_inserted
virtual void object_inserted(const object &obj) override
Definition: account_object.cpp:137
graphene::chain::account_object::blacklisted_accounts
set< account_id_type > blacklisted_accounts
Definition: account_object.hpp:250
graphene::chain::account_object::active
authority active
Definition: account_object.hpp:220
graphene::chain::account_statistics_object::removed_ops
uint64_t removed_ops
Definition: account_object.hpp:61
graphene::chain::account_balance_object::adjust_balance
void adjust_balance(const asset &delta)
Definition: account_object.cpp:45
graphene::chain::account_member_index::get_address_members
set< address > get_address_members(const account_object &a) const
Definition: account_object.cpp:127
graphene::chain::account_object::top_n_control_flags
uint8_t top_n_control_flags
Definition: account_object.hpp:274
graphene::chain::balances_by_account_index::get_account_balances
const map< asset_id_type, const account_balance_object * > & get_account_balances(const account_id_type &acct) const
Definition: account_object.cpp:293
graphene::chain::account_statistics_object::vp_active
uint64_t vp_active
active voting power, if there is no attenuation, it is equal to vp_all.
Definition: account_object.hpp:98
graphene::chain::balances_by_account_index::object_inserted
virtual void object_inserted(const object &obj) override
Definition: account_object.cpp:263
graphene::chain::balances_by_account_index::object_modified
virtual void object_modified(const object &after) override
Definition: account_object.cpp:287
generic_index.hpp
graphene::chain::account_stats_multi_index_type
multi_index_container< account_statistics_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_maintenance_seq >, composite_key< account_statistics_object, const_mem_fun< account_statistics_object, bool, &account_statistics_object::need_maintenance >, member< account_statistics_object, string, &account_statistics_object::name > > >, ordered_non_unique< tag< by_voting_power_active >, composite_key< account_statistics_object, member< account_statistics_object, time_point_sec, &account_statistics_object::vote_tally_time >, member< account_statistics_object, uint64_t, &account_statistics_object::vp_active > >, composite_key_compare< std::greater< time_point_sec >, std::greater< uint64_t > > > > > account_stats_multi_index_type
Definition: account_object.hpp:434
graphene::chain::account_object::registrar
account_id_type registrar
The account that paid the fee to register this account. Receives a percentage of referral rewards.
Definition: account_object.hpp:194
graphene::chain::account_object::num_committee_voted
uint16_t num_committee_voted
Pre-calculated for better performance on chain maintenance.
Definition: account_object.hpp:225
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::account_statistics_object::has_pending_fees
bool has_pending_fees() const
Whether this account has pending fees, no matter vested or not.
Definition: account_object.hpp:136
graphene::chain::account_statistics_object::owner
account_id_type owner
Definition: account_object.hpp:50
graphene::chain::account_balance_object_multi_index_type
multi_index_container< account_balance_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_non_unique< tag< by_maintenance_flag >, member< account_balance_object, bool, &account_balance_object::maintenance_flag > >, ordered_unique< tag< by_asset_balance >, composite_key< account_balance_object, member< account_balance_object, asset_id_type, &account_balance_object::asset_type >, member< account_balance_object, share_type, &account_balance_object::balance >, member< account_balance_object, account_id_type, &account_balance_object::owner > >, composite_key_compare< std::less< asset_id_type >, std::greater< share_type >, std::less< account_id_type > > > > > account_balance_object_multi_index_type
Definition: account_object.hpp:384
graphene::protocol::account_options
These are the fields which can be updated by the active authority.
Definition: account.hpp:39
graphene::chain::account_balance_index
generic_index< account_balance_object, account_balance_object_multi_index_type > account_balance_index
Definition: account_object.hpp:413
graphene::chain::account_balance_object
Tracks the balance of a single account/asset pair.
Definition: account_object.hpp:157
fc::time_point_sec::maximum
static time_point_sec maximum()
Definition: time.hpp:86
graphene::chain::balances_by_account_index
This secondary index will allow fast access to the balance objects that belonging to an account.
Definition: account_object.hpp:361
graphene::chain::account_object::network_fee_percentage
uint16_t network_fee_percentage
Percentage of fee which should go to network.
Definition: account_object.hpp:201
graphene::chain::account_statistics_object::lifetime_fees_paid
share_type lifetime_fees_paid
Definition: account_object.hpp:118
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::account_object::is_lifetime_member
bool is_lifetime_member() const
Definition: account_object.hpp:304
graphene::chain::account_statistics_object::last_vote_time
time_point_sec last_vote_time
last time voted
Definition: account_object.hpp:93
graphene::chain::account_object::is_member
bool is_member(time_point_sec now) const
Definition: account_object.hpp:320
graphene::chain::account_member_index
This secondary index will allow a reverse lookup of all accounts that a particular key or account is ...
Definition: account_object.hpp:330
graphene::chain::account_statistics_object::need_maintenance
bool need_maintenance() const
Whether need to process this account during the maintenance interval.
Definition: account_object.hpp:139
graphene::chain::account_index
generic_index< account_object, account_multi_index_type > account_index
Definition: account_object.hpp:431
graphene::chain::vesting_balance_object
Definition: vesting_balance_object.hpp:151
graphene::chain::account_statistics_object::vp_witness
uint64_t vp_witness
the final voting power for the witnesses.
Definition: account_object.hpp:100
graphene::chain::account_object::creation_block_num
uint32_t creation_block_num
The block number when the account was created.
Definition: account_object.hpp:286
graphene::chain::account_statistics_object
Definition: account_object.hpp:46
graphene::chain::account_balance_object::balance
share_type balance
Definition: account_object.hpp:163
graphene::chain::account_object::options
account_options options
Definition: account_object.hpp:222
graphene::chain::account_statistics_object::total_ops
uint64_t total_ops
Definition: account_object.hpp:59
graphene::chain::account_statistics_object::core_in_balance
share_type core_in_balance
Definition: account_object.hpp:87
graphene::chain::account_balance_object::get_balance
asset get_balance() const
Definition: account_object.hpp:167
graphene::chain::account_statistics_object::total_core_inactive
share_type total_core_inactive
Total amount of core token in inactive lock_forever tickets.
Definition: account_object.hpp:71
graphene::chain::account_statistics_object::vp_worker
uint64_t vp_worker
Definition: account_object.hpp:101
graphene::chain::account_object
This class represents an account on the object graph.
Definition: account_object.hpp:180
graphene::chain::account_statistics_object::vp_committee
uint64_t vp_committee
the final voting power for the committees.
Definition: account_object.hpp:99
graphene::chain::account_member_index::object_modified
virtual void object_modified(const object &after) override
Definition: account_object.cpp:186
graphene::chain::account_object::active_special_authority
special_authority active_special_authority
Definition: account_object.hpp:268
fc::time_point_sec
Definition: time.hpp:74
graphene::chain::account_object::cashback_vb
optional< vesting_balance_id_type > cashback_vb
Definition: account_object.hpp:265
graphene::protocol::no_special_authority
Definition: special_authority.hpp:30
graphene::chain::account_statistics_object::pending_fees
share_type pending_fees
Definition: account_object.hpp:128
graphene::chain::account_member_index::account_to_address_memberships
map< address, set< account_id_type > > account_to_address_memberships
Definition: account_object.hpp:343
graphene::chain::account_member_index::about_to_modify
virtual void about_to_modify(const object &before) override
Definition: account_object.cpp:175
graphene::chain::account_object::owner
authority owner
Definition: account_object.hpp:217
graphene::chain::account_object::top_n_control_owner
static const uint8_t top_n_control_owner
Definition: account_object.hpp:275
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::account_object::creation_time
time_point_sec creation_time
The time when the account was created.
Definition: account_object.hpp:288
graphene::chain::account_object::whitelisted_accounts
set< account_id_type > whitelisted_accounts
Definition: account_object.hpp:249
graphene::chain::account_statistics_object::total_core_pob
share_type total_core_pob
Total amount of core token in active lock_forever tickets.
Definition: account_object.hpp:74
graphene::chain::balances_by_account_index::object_removed
virtual void object_removed(const object &obj) override
Definition: account_object.cpp:275
graphene::chain::account_object::lifetime_referrer_fee_percentage
uint16_t lifetime_referrer_fee_percentage
Percentage of fee which should go to lifetime referrer.
Definition: account_object.hpp:203
graphene::chain::account_member_index::before_key_members
set< public_key_type, pubkey_comparator > before_key_members
Definition: account_object.hpp:352
graphene::chain::account_object::referrer_rewards_percentage
uint16_t referrer_rewards_percentage
Definition: account_object.hpp:206
graphene::chain::account_object::membership_expiration_date
time_point_sec membership_expiration_date
Definition: account_object.hpp:191
graphene::chain::account_stats_index
generic_index< account_statistics_object, account_stats_multi_index_type > account_stats_index
Definition: account_object.hpp:467
graphene::chain::account_statistics_object::has_some_core_voting
bool has_some_core_voting() const
Whether this account owns some CORE asset and is voting.
Definition: account_object.hpp:109
graphene::chain::account_statistics_object::is_voting
bool is_voting
redundately store "if this account is voting" for better maintenance performance
Definition: account_object.hpp:91
graphene::chain::account_object::whitelisting_accounts
flat_set< account_id_type > whitelisting_accounts
Definition: account_object.hpp:237
graphene::chain::account_statistics_object::name
string name
redundantly store account name here for better maintenance performance
Definition: account_object.hpp:52
graphene::chain::account_member_index::get_key_members
set< public_key_type, pubkey_comparator > get_key_members(const account_object &a) const
Definition: account_object.cpp:117
graphene::protocol::pubkey_comparator
Definition: types.hpp:332
graphene::chain::account_object::owner_special_authority
special_authority owner_special_authority
Definition: account_object.hpp:267
graphene::chain::account_statistics_object::total_pob_value
share_type total_pob_value
Total value of tickets whose current type is lock_forever.
Definition: account_object.hpp:80
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::chain::account_object::name
string name
The account's name. This name must be unique among all account names on the graph....
Definition: account_object.hpp:209
fc::static_variant::is_type
bool is_type() const
Definition: static_variant.hpp:332
graphene::chain::account_multi_index_type
multi_index_container< account_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_name >, member< account_object, string, &account_object::name > > > > account_multi_index_type
Definition: account_object.hpp:415
account.hpp
graphene::chain::account_balance_object::maintenance_flag
bool maintenance_flag
Whether need to process this balance object in maintenance interval.
Definition: account_object.hpp:165
graphene::chain::account_statistics_object::total_core_in_orders
share_type total_core_in_orders
Definition: account_object.hpp:68
types.hpp
graphene::chain::account_object::statistics
account_statistics_id_type statistics
Definition: account_object.hpp:229
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::chain::account_statistics_object::vote_tally_time
time_point_sec vote_tally_time
Definition: account_object.hpp:105
GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE
#define GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE
Definition: config.hpp:83
graphene::chain::account_member_index::account_to_key_memberships
map< public_key_type, set< account_id_type >, pubkey_comparator > account_to_key_memberships
Definition: account_object.hpp:341
graphene::chain::account_member_index::account_to_account_memberships
map< account_id_type, set< account_id_type > > account_to_account_memberships
Definition: account_object.hpp:340
graphene::protocol::authority
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::chain::account_statistics_object::pending_vested_fees
share_type pending_vested_fees
Definition: account_object.hpp:133
graphene::chain::account_member_index::object_removed
virtual void object_removed(const object &obj) override
Definition: account_object.cpp:156
graphene::chain::account_object::referrer
account_id_type referrer
The account credited as referring this account. Receives a percentage of referral rewards.
Definition: account_object.hpp:196
graphene::chain::balances_by_account_index::about_to_modify
virtual void about_to_modify(const object &before) override
Definition: account_object.cpp:282
graphene::chain::account_object::allowed_assets
optional< flat_set< asset_id_type > > allowed_assets
Definition: account_object.hpp:283
graphene::protocol::asset
Definition: asset.hpp:31
graphene::db::secondary_index
Definition: index.hpp:139
graphene::chain::account_object::top_n_control_active
static const uint8_t top_n_control_active
Definition: account_object.hpp:276
graphene::chain::account_member_index::before_account_members
set< account_id_type > before_account_members
Definition: account_object.hpp:351
graphene::chain::account_object::is_basic_account
bool is_basic_account(time_point_sec now) const
Definition: account_object.hpp:309
graphene::chain::account_member_index::before_address_members
set< address > before_address_members
Definition: account_object.hpp:353
graphene::chain::account_statistics_object::pay_fee
void pay_fee(share_type core_fee, share_type cashback_vesting_threshold)
Definition: account_object.cpp:100
graphene
Definition: api.cpp:48
graphene::chain::account_object::cashback_balance
const vesting_balance_object & cashback_balance(const DB &db) const
Definition: account_object.hpp:297
graphene::chain::account_statistics_object::total_core_pol
share_type total_core_pol
Total amount of core token in other tickets.
Definition: account_object.hpp:77
graphene::chain::account_balance_object::asset_type
asset_id_type asset_type
Definition: account_object.hpp:162
fc::safe
Definition: safe.hpp:26