BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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  {
48  public:
49  static const uint8_t space_id = implementation_ids;
50  static const uint8_t type_id = impl_account_statistics_object_type;
51 
52  account_id_type owner;
53 
54  string name;
55 
59  account_transaction_history_id_type most_recent_op;
61  uint64_t total_ops = 0;
63  uint64_t removed_ops = 0;
64 
71 
74 
77 
80 
83 
86 
90 
91  bool has_cashback_vb = false;
92 
93  bool is_voting = false;
94 
95  time_point_sec last_vote_time;
96 
98  inline bool has_some_core_voting() const
99  {
100  return is_voting && ( total_core_in_orders > 0 || core_in_balance > 0 || has_cashback_vb
101  || total_core_pol > 0 );
102  }
103 
108 
123 
125  inline bool has_pending_fees() const { return pending_fees > 0 || pending_vested_fees > 0; }
126 
128  inline bool need_maintenance() const { return has_some_core_voting() || has_pending_fees(); }
129 
131  void process_fees(const account_object& a, database& d) const;
132 
136  void pay_fee( share_type core_fee, share_type cashback_vesting_threshold );
137  };
138 
146  class account_balance_object : public abstract_object<account_balance_object>
147  {
148  public:
149  static const uint8_t space_id = implementation_ids;
150  static const uint8_t type_id = impl_account_balance_object_type;
151 
152  account_id_type owner;
153  asset_id_type asset_type;
155  bool maintenance_flag = false;
156 
157  asset get_balance()const { return asset(balance, asset_type); }
158  void adjust_balance(const asset& delta);
159  };
160 
161 
170  class account_object : public graphene::db::abstract_object<account_object>
171  {
172  public:
173  static const uint8_t space_id = protocol_ids;
174  static const uint8_t type_id = account_object_type;
175 
185 
187  account_id_type registrar;
189  account_id_type referrer;
191  account_id_type lifetime_referrer;
192 
194  uint16_t network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
196  uint16_t lifetime_referrer_fee_percentage = 0;
199  uint16_t referrer_rewards_percentage = 0;
200 
202  string name;
203 
214 
217 
220 
223  account_statistics_id_type statistics;
224 
231  flat_set<account_id_type> whitelisting_accounts;
232 
242  set<account_id_type> whitelisted_accounts;
244  set<account_id_type> blacklisted_accounts;
246 
247 
254  flat_set<account_id_type> blacklisting_accounts;
255 
259  optional<vesting_balance_id_type> cashback_vb;
260 
261  special_authority owner_special_authority = no_special_authority();
262  special_authority active_special_authority = no_special_authority();
263 
268  uint8_t top_n_control_flags = 0;
269  static const uint8_t top_n_control_owner = 1;
270  static const uint8_t top_n_control_active = 2;
271 
277  optional< flat_set<asset_id_type> > allowed_assets;
278 
280  {
281  return (!owner_special_authority.is_type< no_special_authority >())
282  || (!active_special_authority.is_type< no_special_authority >());
283  }
284 
285  template<typename DB>
286  const vesting_balance_object& cashback_balance(const DB& db)const
287  {
288  FC_ASSERT(cashback_vb);
289  return db.get(*cashback_vb);
290  }
291 
293  bool is_lifetime_member()const
294  {
295  return membership_expiration_date == time_point_sec::maximum();
296  }
299  {
300  return now > membership_expiration_date;
301  }
305  {
306  return !is_lifetime_member() && !is_basic_account(now);
307  }
309  bool is_member(time_point_sec now)const
310  {
311  return !is_basic_account(now);
312  }
313 
314  account_id_type get_id()const { return id; }
315  };
316 
322  {
323  public:
324  virtual void object_inserted( const object& obj ) override;
325  virtual void object_removed( const object& obj ) override;
326  virtual void about_to_modify( const object& before ) override;
327  virtual void object_modified( const object& after ) override;
328 
329 
331  map< account_id_type, set<account_id_type> > account_to_account_memberships;
332  map< public_key_type, set<account_id_type>, pubkey_comparator > account_to_key_memberships;
334  map< address, set<account_id_type> > account_to_address_memberships;
335 
336 
337  protected:
338  set<account_id_type> get_account_members( const account_object& a )const;
339  set<public_key_type, pubkey_comparator> get_key_members( const account_object& a )const;
340  set<address> get_address_members( const account_object& a )const;
341 
342  set<account_id_type> before_account_members;
343  set<public_key_type, pubkey_comparator> before_key_members;
345  };
346 
347 
353  {
354  public:
355  virtual void object_inserted( const object& obj ) override;
356  virtual void object_removed( const object& obj ) override;
357  virtual void about_to_modify( const object& before ) override;
358  virtual void object_modified( const object& after ) override;
359 
360  const map< asset_id_type, const account_balance_object* >& get_account_balances( const account_id_type& acct )const;
361  const account_balance_object* get_account_balance( const account_id_type& acct, const asset_id_type& asset )const;
362 
363  private:
364  static const uint8_t bits;
365  static const uint64_t mask;
366 
368  vector< vector< map< asset_id_type, const account_balance_object* > > > balances;
369  std::stack< object_id_type > ids_being_modified;
370  };
371 
372  struct by_asset_balance;
373  struct by_maintenance_flag;
377  typedef multi_index_container<
379  indexed_by<
380  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
381  ordered_non_unique< tag<by_maintenance_flag>,
382  member< account_balance_object, bool, &account_balance_object::maintenance_flag > >,
383  ordered_unique< tag<by_asset_balance>,
384  composite_key<
385  account_balance_object,
386  member<account_balance_object, asset_id_type, &account_balance_object::asset_type>,
387  member<account_balance_object, share_type, &account_balance_object::balance>,
388  member<account_balance_object, account_id_type, &account_balance_object::owner>
389  >,
390  composite_key_compare<
391  std::less< asset_id_type >,
392  std::greater< share_type >,
393  std::less< account_id_type >
394  >
395  >
396  >
398 
403 
404  struct by_name;
405 
409  typedef multi_index_container<
411  indexed_by<
412  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
413  ordered_unique< tag<by_name>, member<account_object, string, &account_object::name> >
414  >
416 
421 
422  struct by_maintenance_seq;
423 
427  typedef multi_index_container<
429  indexed_by<
430  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
431  ordered_unique< tag<by_maintenance_seq>,
432  composite_key<
433  account_statistics_object,
434  const_mem_fun<account_statistics_object, bool, &account_statistics_object::need_maintenance>,
435  member<account_statistics_object, string, &account_statistics_object::name>
436  >
437  >
438  >
440 
445 
446 }}
447 
451 
455 
bool is_type() const
share_type total_core_pol
Total amount of core token in other tickets.
Tracks the balance of a single account/asset pairThis object is indexed on owner and asset_type so th...
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
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
generic_index< account_object, account_multi_index_type > account_index
flat_set< account_id_type > blacklisting_accounts
map< public_key_type, set< account_id_type >, pubkey_comparator > account_to_key_memberships
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
set< account_id_type > before_account_members
bool is_member(time_point_sec now) const
This class represents an account on the object graphAccounts are the primary unit of authority on the...
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
bool need_maintenance() const
Whether need to process this account during the maintenance interval.
This secondary index will allow fast access to the balance objects that belonging to an account...
bool has_cashback_vb
redundantly store this for better maintenance performance
bool is_annual_member(time_point_sec now) const
#define GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE
Definition: config.hpp:83
share_type total_pol_value
Total value of tickets whose current type is not lock_forever.
const vesting_balance_object & cashback_balance(const DB &db) const
set< public_key_type, pubkey_comparator > before_key_members
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 > > > > > account_stats_multi_index_type
FC_REFLECT_TYPENAME(fc::log_message)
optional< flat_set< asset_id_type > > allowed_assets
generic_index< account_balance_object, account_balance_object_multi_index_type > account_balance_index
static time_point_sec maximum()
Definition: time.hpp:86
object_id_type id
Definition: object.hpp:73
generic_index< account_statistics_object, account_stats_multi_index_type > account_stats_index
These are the fields which can be updated by the active authority.
Definition: account.hpp:39
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
share_type total_pob_value
Total value of tickets whose current type is lock_forever.
account_id_type get_id() const
optional< vesting_balance_id_type > cashback_vb
account_id_type lifetime_referrer
The lifetime member at the top of the referral tree. Receives a percentage of referral rewards...
share_type total_core_inactive
Total amount of core token in inactive lock_forever tickets.
string name
redundantly store account name here for better maintenance performance
This secondary index will allow a reverse lookup of all accounts that a particular key or account is ...
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
string name
The account&#39;s name. This name must be unique among all account names on the graph. May not be empty.
bool has_pending_fees() const
Whether this account has pending fees, no matter vested or not.
flat_set< account_id_type > whitelisting_accounts
set< account_id_type > blacklisted_accounts
time_point_sec last_vote_time
last time voted
void pay_fee(share_type core_fee, share_type cashback_vesting_threshold)
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:90
bool is_basic_account(time_point_sec now) const
void process_fees(const account_object &a, database &d) const
Split up and pay out pending_fees and pending_vested_fees.
bool is_voting
redundately store "if this account is voting" for better maintenance performance
account_statistics_id_type statistics
bool has_some_core_voting() const
Whether this account owns some CORE asset and is voting.
account_id_type registrar
The account that paid the fee to register this account. Receives a percentage of referral rewards...
map< address, set< account_id_type > > account_to_address_memberships
uint16_t num_committee_voted
Pre-calculated for better performance on chain maintenance.
account_id_type referrer
The account credited as referring this account. Receives a percentage of referral rewards...
map< account_id_type, set< account_id_type > > account_to_account_memberships
share_type total_core_pob
Total amount of core token in active lock_forever tickets.
account_transaction_history_id_type most_recent_op