BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
db_init.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 
27 
53 
72 
73 #include <fc/crypto/digest.hpp>
74 
75 #include <boost/algorithm/string.hpp>
76 
77 namespace graphene { namespace chain {
78 
80 {
81  _operation_evaluators.resize(255);
82  register_evaluator<account_create_evaluator>();
83  register_evaluator<account_update_evaluator>();
84  register_evaluator<account_upgrade_evaluator>();
85  register_evaluator<account_whitelist_evaluator>();
86  register_evaluator<committee_member_create_evaluator>();
87  register_evaluator<committee_member_update_evaluator>();
88  register_evaluator<committee_member_update_global_parameters_evaluator>();
89  register_evaluator<custom_evaluator>();
90  register_evaluator<asset_create_evaluator>();
91  register_evaluator<asset_issue_evaluator>();
92  register_evaluator<asset_reserve_evaluator>();
93  register_evaluator<asset_update_evaluator>();
94  register_evaluator<asset_update_bitasset_evaluator>();
95  register_evaluator<asset_update_feed_producers_evaluator>();
96  register_evaluator<asset_settle_evaluator>();
97  register_evaluator<asset_global_settle_evaluator>();
98  register_evaluator<assert_evaluator>();
99  register_evaluator<limit_order_create_evaluator>();
100  register_evaluator<limit_order_cancel_evaluator>();
101  register_evaluator<call_order_update_evaluator>();
102  register_evaluator<bid_collateral_evaluator>();
103  register_evaluator<transfer_evaluator>();
104  register_evaluator<override_transfer_evaluator>();
105  register_evaluator<asset_fund_fee_pool_evaluator>();
106  register_evaluator<asset_publish_feeds_evaluator>();
107  register_evaluator<proposal_create_evaluator>();
108  register_evaluator<proposal_update_evaluator>();
109  register_evaluator<proposal_delete_evaluator>();
110  register_evaluator<vesting_balance_create_evaluator>();
111  register_evaluator<vesting_balance_withdraw_evaluator>();
112  register_evaluator<witness_create_evaluator>();
113  register_evaluator<witness_update_evaluator>();
114  register_evaluator<withdraw_permission_create_evaluator>();
115  register_evaluator<withdraw_permission_claim_evaluator>();
116  register_evaluator<withdraw_permission_update_evaluator>();
117  register_evaluator<withdraw_permission_delete_evaluator>();
118  register_evaluator<worker_create_evaluator>();
119  register_evaluator<balance_claim_evaluator>();
120  register_evaluator<transfer_to_blind_evaluator>();
121  register_evaluator<transfer_from_blind_evaluator>();
122  register_evaluator<blind_transfer_evaluator>();
123  register_evaluator<asset_claim_fees_evaluator>();
124  register_evaluator<asset_update_issuer_evaluator>();
125  register_evaluator<asset_claim_pool_evaluator>();
126  register_evaluator<htlc_create_evaluator>();
127  register_evaluator<htlc_redeem_evaluator>();
128  register_evaluator<htlc_extend_evaluator>();
129  register_evaluator<custom_authority_create_evaluator>();
130  register_evaluator<custom_authority_update_evaluator>();
131  register_evaluator<custom_authority_delete_evaluator>();
132  register_evaluator<ticket_create_evaluator>();
133  register_evaluator<ticket_update_evaluator>();
134  register_evaluator<liquidity_pool_create_evaluator>();
135  register_evaluator<liquidity_pool_delete_evaluator>();
136  register_evaluator<liquidity_pool_deposit_evaluator>();
137  register_evaluator<liquidity_pool_withdraw_evaluator>();
138  register_evaluator<liquidity_pool_exchange_evaluator>();
139 }
140 
142 {
143  reset_indexes();
145 
146  //Protocol object indexes
147  add_index< primary_index<asset_index, 13> >(); // 8192 assets per chunk
148  add_index< primary_index<force_settlement_index> >();
149 
150  add_index< primary_index<account_index, 20> >(); // ~1 million accounts per chunk
151  add_index< primary_index<committee_member_index, 8> >(); // 256 members per chunk
152  add_index< primary_index<witness_index, 10> >(); // 1024 witnesses per chunk
153  add_index< primary_index<limit_order_index > >();
154  add_index< primary_index<call_order_index > >();
155  add_index< primary_index<proposal_index > >();
156  add_index< primary_index<withdraw_permission_index > >();
157  add_index< primary_index<vesting_balance_index> >();
158  add_index< primary_index<worker_index> >();
159  add_index< primary_index<balance_index> >();
160  add_index< primary_index<blinded_balance_index> >();
161  add_index< primary_index< htlc_index> >();
162  add_index< primary_index< custom_authority_index> >();
163  add_index< primary_index<ticket_index> >();
164  add_index< primary_index<liquidity_pool_index> >();
165 
166  //Implementation object indexes
167  add_index< primary_index<transaction_index > >();
168 
169  auto bal_idx = add_index< primary_index<account_balance_index > >();
170  bal_idx->add_secondary_index<balances_by_account_index>();
171 
172  add_index< primary_index<asset_bitasset_data_index, 13 > >(); // 8192
173  add_index< primary_index<simple_index<global_property_object >> >();
174  add_index< primary_index<simple_index<dynamic_global_property_object >> >();
175  add_index< primary_index<account_stats_index, 20 > >(); // 1 Mi
176  add_index< primary_index<simple_index<asset_dynamic_data_object >> >();
177  add_index< primary_index<simple_index<block_summary_object >> >();
178  add_index< primary_index<simple_index<chain_property_object > > >();
179  add_index< primary_index<simple_index<witness_schedule_object > > >();
180  add_index< primary_index<simple_index<budget_record_object > > >();
181  add_index< primary_index< special_authority_index > >();
182  add_index< primary_index< buyback_index > >();
183  add_index< primary_index<collateral_bid_index > >();
184  add_index< primary_index< simple_index< fba_accumulator_object > > >();
185 }
186 
187 void database::init_genesis(const genesis_state_type& genesis_state)
188 { try {
189  FC_ASSERT( genesis_state.initial_timestamp != time_point_sec(), "Must initialize genesis timestamp." );
191  "Genesis timestamp must be divisible by GRAPHENE_DEFAULT_BLOCK_INTERVAL." );
192  FC_ASSERT(genesis_state.initial_witness_candidates.size() > 0,
193  "Cannot start a chain with zero witnesses.");
194  FC_ASSERT(genesis_state.initial_active_witnesses <= genesis_state.initial_witness_candidates.size(),
195  "initial_active_witnesses is larger than the number of candidate witnesses.");
196 
197  _undo_db.disable();
198  struct auth_inhibitor {
199  auth_inhibitor(database& db) : db(db), old_flags(db.node_properties().skip_flags)
201  ~auth_inhibitor()
202  { db.node_properties().skip_flags = old_flags; }
203  private:
204  database& db;
205  uint32_t old_flags;
206  } inhibitor(*this);
207 
208  transaction_evaluation_state genesis_eval_state(this);
209 
210  // Create blockchain accounts
211  fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));
212  create<account_balance_object>([](account_balance_object& b) {
213  b.balance = GRAPHENE_MAX_SHARE_SUPPLY;
214  });
215  const account_object& committee_account =
216  create<account_object>( [&](account_object& n) {
217  n.membership_expiration_date = time_point_sec::maximum();
218  n.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
219  n.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
220  n.owner.weight_threshold = 1;
221  n.active.weight_threshold = 1;
222  n.name = "committee-account";
223  n.statistics = create<account_statistics_object>( [&n](account_statistics_object& s){
224  s.owner = n.id;
225  s.name = n.name;
226  s.core_in_balance = GRAPHENE_MAX_SHARE_SUPPLY;
227  }).id;
228  });
229  FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT);
230  FC_ASSERT(create<account_object>([this](account_object& a) {
231  a.name = "witness-account";
232  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
233  s.owner = a.id;
234  s.name = a.name;
235  }).id;
236  a.owner.weight_threshold = 1;
237  a.active.weight_threshold = 1;
242  }).get_id() == GRAPHENE_WITNESS_ACCOUNT);
243  FC_ASSERT(create<account_object>([this](account_object& a) {
244  a.name = "relaxed-committee-account";
245  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
246  s.owner = a.id;
247  s.name = a.name;
248  }).id;
249  a.owner.weight_threshold = 1;
250  a.active.weight_threshold = 1;
255  }).get_id() == GRAPHENE_RELAXED_COMMITTEE_ACCOUNT);
256  FC_ASSERT(create<account_object>([this](account_object& a) {
257  a.name = "null-account";
258  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
259  s.owner = a.id;
260  s.name = a.name;
261  }).id;
262  a.owner.weight_threshold = 1;
263  a.active.weight_threshold = 1;
268  }).get_id() == GRAPHENE_NULL_ACCOUNT);
269  FC_ASSERT(create<account_object>([this](account_object& a) {
270  a.name = "temp-account";
271  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
272  s.owner = a.id;
273  s.name = a.name;
274  }).id;
275  a.owner.weight_threshold = 0;
276  a.active.weight_threshold = 0;
281  }).get_id() == GRAPHENE_TEMP_ACCOUNT);
282  FC_ASSERT(create<account_object>([this](account_object& a) {
283  a.name = "proxy-to-self";
284  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
285  s.owner = a.id;
286  s.name = a.name;
287  }).id;
288  a.owner.weight_threshold = 1;
289  a.active.weight_threshold = 1;
294  }).get_id() == GRAPHENE_PROXY_TO_SELF_ACCOUNT);
295 
296  // Create more special accounts
297  while( true )
298  {
299  uint64_t id = get_index<account_object>().get_next_id().instance();
300  if( id >= genesis_state.immutable_parameters.num_special_accounts )
301  break;
302  const account_object& acct = create<account_object>([this,id](account_object& a) {
303  a.name = "special-account-" + std::to_string(id);
304  a.statistics = create<account_statistics_object>([&a](account_statistics_object& s){
305  s.owner = a.id;
306  s.name = a.name;
307  }).id;
308  a.owner.weight_threshold = 1;
309  a.active.weight_threshold = 1;
310  a.registrar = a.lifetime_referrer = a.referrer = account_id_type(id);
314  });
315  FC_ASSERT( acct.get_id() == account_id_type(id) );
316  remove( acct );
317  }
318 
319  // Create core asset
320  const asset_dynamic_data_object& dyn_asset =
321  create<asset_dynamic_data_object>([](asset_dynamic_data_object& a) {
322  a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY;
323  });
324  const asset_object& core_asset =
325  create<asset_object>( [&genesis_state,&dyn_asset]( asset_object& a ) {
326  a.symbol = GRAPHENE_SYMBOL;
327  a.options.max_supply = genesis_state.max_core_supply;
329  a.options.flags = 0;
330  a.options.issuer_permissions = 0;
331  a.issuer = GRAPHENE_NULL_ACCOUNT;
332  a.options.core_exchange_rate.base.amount = 1;
333  a.options.core_exchange_rate.base.asset_id = asset_id_type(0);
334  a.options.core_exchange_rate.quote.amount = 1;
335  a.options.core_exchange_rate.quote.asset_id = asset_id_type(0);
336  a.dynamic_asset_data_id = dyn_asset.id;
337  });
338  FC_ASSERT( dyn_asset.id == asset_dynamic_data_id_type() );
339  FC_ASSERT( asset_id_type(core_asset.id) == asset().asset_id );
340  FC_ASSERT( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) );
341  _p_core_asset_obj = &core_asset;
342  _p_core_dynamic_data_obj = &dyn_asset;
343  // Create more special assets
344  while( true )
345  {
346  uint64_t id = get_index<asset_object>().get_next_id().instance();
347  if( id >= genesis_state.immutable_parameters.num_special_assets )
348  break;
349  const asset_dynamic_data_object& dyn_asset =
350  create<asset_dynamic_data_object>([](asset_dynamic_data_object& a) {
351  a.current_supply = 0;
352  });
353  const asset_object& asset_obj = create<asset_object>( [id,&dyn_asset]( asset_object& a ) {
354  a.symbol = "SPECIAL" + std::to_string( id );
355  a.options.max_supply = 0;
357  a.options.flags = 0;
358  a.options.issuer_permissions = 0;
359  a.issuer = GRAPHENE_NULL_ACCOUNT;
360  a.options.core_exchange_rate.base.amount = 1;
361  a.options.core_exchange_rate.base.asset_id = asset_id_type(0);
362  a.options.core_exchange_rate.quote.amount = 1;
363  a.options.core_exchange_rate.quote.asset_id = asset_id_type(0);
364  a.dynamic_asset_data_id = dyn_asset.id;
365  });
366  FC_ASSERT( asset_obj.get_id() == asset_id_type(id) );
367  remove( asset_obj );
368  }
369 
370  chain_id_type chain_id = genesis_state.compute_chain_id();
371 
372  // Create global properties
373  _p_global_prop_obj = & create<global_property_object>([&genesis_state](global_property_object& p) {
374  p.parameters = genesis_state.initial_parameters;
375  // Set fees to zero initially, so that genesis initialization needs not pay them
376  // We'll fix it at the end of the function
377  p.parameters.get_mutable_fees().zero_all_fees();
378 
379  });
380  _p_dyn_global_prop_obj = & create<dynamic_global_property_object>([&genesis_state](dynamic_global_property_object& p) {
381  p.time = genesis_state.initial_timestamp;
382  p.dynamic_flags = 0;
383  p.witness_budget = 0;
384  p.recent_slots_filled = std::numeric_limits<fc::uint128_t>::max();
385  });
386 
387  FC_ASSERT( (genesis_state.immutable_parameters.min_witness_count & 1) == 1, "min_witness_count must be odd" );
388  FC_ASSERT( (genesis_state.immutable_parameters.min_committee_member_count & 1) == 1, "min_committee_member_count must be odd" );
389 
390  _p_chain_property_obj = & create<chain_property_object>([chain_id,&genesis_state](chain_property_object& p)
391  {
392  p.chain_id = chain_id;
393  p.immutable_parameters = genesis_state.immutable_parameters;
394  } );
395  for (uint32_t i = 0; i <= 0x10000; i++)
396  create<block_summary_object>( [&]( block_summary_object&) {});
397 
398  // Create initial accounts
399  for( const auto& account : genesis_state.initial_accounts )
400  {
402  cop.name = account.name;
404  cop.owner = authority(1, account.owner_key, 1);
405  if( account.active_key == public_key_type() )
406  {
407  cop.active = cop.owner;
408  cop.options.memo_key = account.owner_key;
409  }
410  else
411  {
412  cop.active = authority(1, account.active_key, 1);
413  cop.options.memo_key = account.active_key;
414  }
415  account_id_type account_id(apply_operation(genesis_eval_state, cop).get<object_id_type>());
416 
417  if( account.is_lifetime_member )
418  {
420  op.account_to_upgrade = account_id;
421  op.upgrade_to_lifetime_member = true;
422  apply_operation(genesis_eval_state, op);
423  }
424  }
425 
426  // Helper function to get account ID by name
427  const auto& accounts_by_name = get_index_type<account_index>().indices().get<by_name>();
428  auto get_account_id = [&accounts_by_name](const string& name) {
429  auto itr = accounts_by_name.find(name);
430  FC_ASSERT(itr != accounts_by_name.end(),
431  "Unable to find account '${acct}'. Did you forget to add a record for it to initial_accounts?",
432  ("acct", name));
433  return itr->get_id();
434  };
435 
436  // Helper function to get asset ID by symbol
437  const auto& assets_by_symbol = get_index_type<asset_index>().indices().get<by_symbol>();
438  const auto get_asset_id = [&assets_by_symbol](const string& symbol) {
439  auto itr = assets_by_symbol.find(symbol);
440  FC_ASSERT(itr != assets_by_symbol.end(),
441  "Unable to find asset '${sym}'. Did you forget to add a record for it to initial_assets?",
442  ("sym", symbol));
443  return itr->get_id();
444  };
445 
446  map<asset_id_type, share_type> total_supplies;
447  map<asset_id_type, share_type> total_debts;
448 
449  // Create initial assets
450  for( const genesis_state_type::initial_asset_type& asset : genesis_state.initial_assets )
451  {
452  asset_id_type new_asset_id = get_index_type<asset_index>().get_next_id();
453  total_supplies[ new_asset_id ] = 0;
454 
455  asset_dynamic_data_id_type dynamic_data_id;
456  optional<asset_bitasset_data_id_type> bitasset_data_id;
457  if( asset.is_bitasset )
458  {
459  int collateral_holder_number = 0;
460  total_debts[ new_asset_id ] = 0;
461  for( const auto& collateral_rec : asset.collateral_records )
462  {
464  cop.name = asset.symbol + "-collateral-holder-" + std::to_string(collateral_holder_number);
467  cop.owner = authority(1, collateral_rec.owner, 1);
468  cop.active = cop.owner;
469  account_id_type owner_account_id = apply_operation(genesis_eval_state, cop).get<object_id_type>();
470 
471  modify( owner_account_id(*this).statistics(*this), [&collateral_rec]( account_statistics_object& o ) {
472  o.total_core_in_orders = collateral_rec.collateral;
473  });
474 
475  create<call_order_object>([&](call_order_object& c) {
476  c.borrower = owner_account_id;
477  c.collateral = collateral_rec.collateral;
478  c.debt = collateral_rec.debt;
479  c.call_price = price::call_price(chain::asset(c.debt, new_asset_id),
480  chain::asset(c.collateral, core_asset.id),
482  });
483 
484  total_supplies[ asset_id_type(0) ] += collateral_rec.collateral;
485  total_debts[ new_asset_id ] += collateral_rec.debt;
486  ++collateral_holder_number;
487  }
488 
489  bitasset_data_id = create<asset_bitasset_data_object>([&core_asset,new_asset_id](asset_bitasset_data_object& b) {
490  b.options.short_backing_asset = core_asset.id;
491  b.options.minimum_feeds = GRAPHENE_DEFAULT_MINIMUM_FEEDS;
492  b.asset_id = new_asset_id;
493  }).id;
494  }
495 
496  dynamic_data_id = create<asset_dynamic_data_object>([&asset](asset_dynamic_data_object& d) {
497  d.accumulated_fees = asset.accumulated_fees;
498  }).id;
499 
500  total_supplies[ new_asset_id ] += asset.accumulated_fees;
501 
502  create<asset_object>([&](asset_object& a) {
503  a.symbol = asset.symbol;
504  a.options.description = asset.description;
505  a.precision = asset.precision;
506  string issuer_name = asset.issuer_name;
507  a.issuer = get_account_id(issuer_name);
508  a.options.max_supply = asset.max_supply;
509  a.options.flags = witness_fed_asset;
512  a.dynamic_asset_data_id = dynamic_data_id;
513  a.bitasset_data_id = bitasset_data_id;
514  });
515  }
516 
517  // Create initial balances
518  share_type total_allocation;
519  for( const auto& handout : genesis_state.initial_balances )
520  {
521  const auto asset_id = get_asset_id(handout.asset_symbol);
522  create<balance_object>([&handout,total_allocation,asset_id](balance_object& b) {
523  b.balance = asset(handout.amount, asset_id);
524  b.owner = handout.owner;
525  });
526 
527  total_supplies[ asset_id ] += handout.amount;
528  }
529 
530  // Create initial vesting balances
531  for( const genesis_state_type::initial_vesting_balance_type& vest : genesis_state.initial_vesting_balances )
532  {
533  const auto asset_id = get_asset_id(vest.asset_symbol);
534  create<balance_object>([&](balance_object& b) {
535  b.owner = vest.owner;
536  b.balance = asset(vest.amount, asset_id);
537 
538  linear_vesting_policy policy;
539  policy.begin_timestamp = vest.begin_timestamp;
540  policy.vesting_cliff_seconds = 0;
542  policy.begin_balance = vest.begin_balance;
543 
544  b.vesting_policy = std::move(policy);
545  });
546 
547  total_supplies[ asset_id ] += vest.amount;
548  }
549 
550  if( total_supplies[ asset_id_type(0) ] > 0 )
551  {
553  }
554  else
555  {
556  total_supplies[ asset_id_type(0) ] = GRAPHENE_MAX_SHARE_SUPPLY;
557  }
558 
559  const auto& idx = get_index_type<asset_index>().indices().get<by_symbol>();
560  auto it = idx.begin();
561  bool has_imbalanced_assets = false;
562 
563  while( it != idx.end() )
564  {
565  if( it->bitasset_data_id.valid() )
566  {
567  auto supply_itr = total_supplies.find( it->id );
568  auto debt_itr = total_debts.find( it->id );
569  FC_ASSERT( supply_itr != total_supplies.end() );
570  FC_ASSERT( debt_itr != total_debts.end() );
571  if( supply_itr->second != debt_itr->second )
572  {
573  has_imbalanced_assets = true;
574  elog( "Genesis for asset ${aname} is not balanced\n"
575  " Debt is ${debt}\n"
576  " Supply is ${supply}\n",
577  ("aname", it->symbol)
578  ("debt", debt_itr->second)
579  ("supply", supply_itr->second)
580  );
581  }
582  }
583  ++it;
584  }
585  FC_ASSERT( !has_imbalanced_assets );
586 
587  // Save tallied supplies
588  for( const auto& item : total_supplies )
589  {
590  const auto asset_id = item.first;
591  const auto total_supply = item.second;
592 
593  modify( get( asset_id ), [ & ]( asset_object& asset ) {
594  modify( get( asset.dynamic_asset_data_id ), [ & ]( asset_dynamic_data_object& asset_data ) {
595  asset_data.current_supply = total_supply;
596  } );
597  } );
598  }
599 
600  // Create special witness account
601  const witness_object& wit = create<witness_object>([&](witness_object& w) {});
602  FC_ASSERT( wit.id == GRAPHENE_NULL_WITNESS );
603  remove(wit);
604 
605  // Create initial witnesses
606  std::for_each(genesis_state.initial_witness_candidates.begin(), genesis_state.initial_witness_candidates.end(),
609  op.witness_account = get_account_id(witness.owner_name);
610  op.block_signing_key = witness.block_signing_key;
611  apply_operation(genesis_eval_state, op);
612  });
613 
614  // Create initial committee members
615  std::for_each(genesis_state.initial_committee_candidates.begin(), genesis_state.initial_committee_candidates.end(),
618  op.committee_member_account = get_account_id(member.owner_name);
619  apply_operation(genesis_eval_state, op);
620  });
621 
622  // Create initial workers
623  std::for_each(genesis_state.initial_worker_candidates.begin(), genesis_state.initial_worker_candidates.end(),
625  {
627  op.owner = get_account_id(worker.owner_name);
628  op.work_begin_date = genesis_state.initial_timestamp;
630  op.daily_pay = worker.daily_pay;
631  op.name = "Genesis-Worker-" + worker.owner_name;
633 
634  apply_operation(genesis_eval_state, std::move(op));
635  });
636 
637  // Set active witnesses
638  modify(get_global_properties(), [&genesis_state](global_property_object& p) {
639  for( uint32_t i = 1; i <= genesis_state.initial_active_witnesses; ++i )
640  {
641  p.active_witnesses.insert(witness_id_type(i));
642  }
643  });
644 
645  // Enable fees
646  modify(get_global_properties(), [&genesis_state](global_property_object& p) {
647  p.parameters.get_mutable_fees() = genesis_state.initial_parameters.get_current_fees();
648  });
649 
650  // Create witness scheduler
651  _p_witness_schedule_obj = & create<witness_schedule_object>([this]( witness_schedule_object& wso )
652  {
653  for( const witness_id_type& wid : get_global_properties().active_witnesses )
654  wso.current_shuffled_witnesses.push_back( wid );
655  });
656 
657  // Create FBA counters
658  create<fba_accumulator_object>([&]( fba_accumulator_object& acc )
659  {
660  FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_transfer_to_blind ) );
661  acc.accumulated_fba_fees = 0;
662 #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET
663  acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET;
664 #endif
665  });
666 
667  create<fba_accumulator_object>([&]( fba_accumulator_object& acc )
668  {
669  FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_blind_transfer ) );
670  acc.accumulated_fba_fees = 0;
671 #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET
672  acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET;
673 #endif
674  });
675 
676  create<fba_accumulator_object>([&]( fba_accumulator_object& acc )
677  {
678  FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_transfer_from_blind ) );
679  acc.accumulated_fba_fees = 0;
680 #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET
681  acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET;
682 #endif
683  });
684 
685  FC_ASSERT( get_index<fba_accumulator_object>().get_next_id() == fba_accumulator_id_type( fba_accumulator_id_count ) );
686 
687  //debug_dump();
688 
689  _undo_db.enable();
691 
692 } }
Tracks the balance of a single account/asset pairThis object is indexed on owner and asset_type so th...
Create a committee_member object, as a bid to hold a committee_member seat on the network...
account_id_type registrar
This account pays the fee. Must be a lifetime member.
Definition: account.hpp:100
fc::time_point_sec begin_timestamp
This is the time at which funds begin vesting.
#define GRAPHENE_TEMP_ACCOUNT
Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) ...
Definition: config.hpp:133
void modify(const T &obj, const Lambda &m)
uint32_t vesting_duration_seconds
Duration of the vesting period, in seconds. Must be greater than 0 and greater than vesting_cliff_sec...
bool upgrade_to_lifetime_member
If true, the account will be upgraded to a lifetime member; otherwise, it will add a year to the subs...
Definition: account.hpp:245
#define GRAPHENE_MIN_UNDO_HISTORY
Definition: config.hpp:28
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account&#39;s balance in a given asset by a delta.
Definition: db_balance.cpp:54
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
require the issuer to be one party to every transfer
Definition: types.hpp:143
std::string to_lower(const std::string &)
Definition: string.cpp:98
immutable_chain_parameters immutable_parameters
Manage an account&#39;s membership statusThis operation is used to upgrade an account to a member...
Definition: account.hpp:234
uint32_t vesting_cliff_seconds
No amount may be withdrawn before this many seconds of the vesting period have elapsed.
contains properties that only apply to bitassets (market issued assets)
void init_genesis(const genesis_state_type &genesis_state=genesis_state_type())
Definition: db_init.cpp:187
uint32_t sec_since_epoch() const
Definition: time.hpp:90
This class represents an account on the object graphAccounts are the primary unit of authority on the...
Maintains global state information (committee_member list, current fees)This is an implementation det...
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
#define elog(FORMAT,...)
Definition: logger.hpp:129
#define GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET
Definition: config.hpp:140
Create a witness object, as a bid to hold a witness position on the network.Accounts which wish to be...
Definition: witness.hpp:37
account_id_type account_to_upgrade
The account to upgrade; must not already be a lifetime member.
Definition: account.hpp:243
#define GRAPHENE_PROXY_TO_SELF_ACCOUNT
Represents the canonical account for specifying you will vote directly (as opposed to a proxy) ...
Definition: config.hpp:135
tracks debt and call price information
asset get_balance(account_id_type owner, asset_id_type asset_id) const
Retrieve a particular account&#39;s balance in a given asset.
Definition: db_balance.cpp:35
This secondary index will allow fast access to the balance objects that belonging to an account...
#define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO
Call when collateral only pays off 175% the debt.
Definition: config.hpp:116
uint16_t network_fee_percentage
Percentage of fee which should go to network.
#define GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE
Definition: config.hpp:83
vector< initial_witness_type > initial_witness_candidates
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:44
#define GRAPHENE_MAX_SHARE_SUPPLY
Definition: config.hpp:38
static sha256 hash(const char *d, uint32_t dlen)
Definition: sha256.cpp:41
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
void set_max_size(size_t new_max_size)
account_id_type committee_member_account
The account which owns the committee_member. This account pays the fee for this operation.
operation_result apply_operation(transaction_evaluation_state &eval_state, const operation &op)
Definition: db_block.cpp:754
static time_point_sec maximum()
Definition: time.hpp:86
object_id_type id
Definition: object.hpp:69
uint16_t lifetime_referrer_fee_percentage
Percentage of fee which should go to lifetime referrer.
account_id_type get_id() const
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
#define GRAPHENE_COMMITTEE_ACCOUNT
Definition: config.hpp:125
#define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS
Definition: config.hpp:30
account_id_type lifetime_referrer
The lifetime member at the top of the referral tree. Receives a percentage of referral rewards...
asset_dynamic_data_id_type dynamic_asset_data_id
Current supply, fee pool, and collected fees are stored in a separate object as they change frequentl...
share_type begin_balance
The total amount of asset to vest.
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
worker_initializer initializer
This should be set to the initializer appropriate for the type of worker to be created.
Definition: worker.hpp:90
#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.
tracks the asset information that changes frequentlyBecause the asset_object is very large it doesn&#39;t...
static private_key regenerate(const fc::sha256 &secret)
#define GRAPHENE_NULL_ACCOUNT
Represents the canonical account with NO authority (nobody can access funds in null account) ...
Definition: config.hpp:131
market trades in this asset may be charged
Definition: types.hpp:140
accounts must be whitelisted in order to hold or transact this asset
Definition: types.hpp:141
account_id_type witness_account
The account which owns the witness. This account pays the fee for this operation. ...
Definition: witness.hpp:43
#define GRAPHENE_RELAXED_COMMITTEE_ACCOUNT
Represents the current committee members.
Definition: config.hpp:129
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
#define GRAPHENE_NULL_WITNESS
Sentinel value used in the scheduler.
Definition: config.hpp:137
std::string to_string(double)
Definition: string.cpp:73
void initialize_indexes()
Reset the object graph in-memory.
Definition: db_init.cpp:141
the bitasset is to be fed by witnesses
Definition: types.hpp:147
allow the bitasset owner to force a global settling, permission only
Definition: types.hpp:145
vector< initial_collateral_position > collateral_records
node_property_object & node_properties()
Definition: db_getter.cpp:94
account_statistics_id_type statistics
tracks minimal information about past blocks to implement TaPOSWhen attempting to calculate the valid...
issuer may transfer asset back to himself
Definition: types.hpp:142
Maintains global state information (committee_member list, current fees)This is an implementation det...
account_id_type registrar
The account that paid the fee to register this account. Receives a percentage of referral rewards...
#define GRAPHENE_SYMBOL
Definition: config.hpp:26
an elliptic curve private key.
Definition: elliptic.hpp:89
#define GRAPHENE_DEFAULT_BLOCK_INTERVAL
Definition: config.hpp:62
void for_each(T &&t, const account_object &a, seq< Is... >)
Definition: database.hpp:701
static price call_price(const asset &debt, const asset &collateral, uint16_t collateral_ratio)
Definition: asset.cpp:212
account_id_type referrer
The account credited as referring this account. Receives a percentage of referral rewards...
Create a new worker object.
Definition: worker.hpp:78
Linear vesting balance with cliff.
disallow the asset to be used with confidential transactions
Definition: types.hpp:146
#define GRAPHENE_DEFAULT_MINIMUM_FEEDS
Definition: config.hpp:97
#define GRAPHENE_WITNESS_ACCOUNT
Represents the current witnesses.
Definition: config.hpp:127