Example #1
0
void account_statistics_object::process_fees(const account_object& a, database& d) const
{
   if( pending_fees > 0 || pending_vested_fees > 0 )
   {
      const auto& props = d.get_global_properties();

      auto pay_out_fees = [&](const account_object& account, share_type core_fee_total, bool require_vesting)
      {
         // Check the referrer -- if he's no longer a member, pay to the lifetime referrer instead.
         // No need to check the registrar; registrars are required to be lifetime members.
         if( account.referrer(d).is_basic_account(d.head_block_time()) )
            d.modify(account, [](account_object& a) {
               a.referrer = a.lifetime_referrer;
            });

         share_type network_cut = cut_fee(core_fee_total, account.network_fee_percentage);
         assert( network_cut <= core_fee_total );

#ifndef NDEBUG
         share_type reserveed = cut_fee(network_cut, props.parameters.reserve_percent_of_fee);
         share_type accumulated = network_cut - reserveed;
         assert( accumulated + reserveed == network_cut );
#endif
         share_type lifetime_cut = cut_fee(core_fee_total, account.lifetime_referrer_fee_percentage);
         share_type referral = core_fee_total - network_cut - lifetime_cut;

         d.modify(asset_dynamic_data_id_type()(d), [network_cut](asset_dynamic_data_object& d) {
            d.accumulated_fees += network_cut;
         });

         // Potential optimization: Skip some of this math and object lookups by special casing on the account type.
         // For example, if the account is a lifetime member, we can skip all this and just deposit the referral to
         // it directly.
         share_type referrer_cut = cut_fee(referral, account.referrer_rewards_percentage);
         share_type registrar_cut = referral - referrer_cut;

         d.deposit_cashback(d.get(account.lifetime_referrer), lifetime_cut, require_vesting);
         d.deposit_cashback(d.get(account.referrer), referrer_cut, require_vesting);
         d.deposit_cashback(d.get(account.registrar), registrar_cut, require_vesting);

         assert( referrer_cut + registrar_cut + accumulated + reserveed + lifetime_cut == core_fee_total );
      };

      share_type vesting_fee_subtotal(pending_fees);
      share_type vested_fee_subtotal(pending_vested_fees);
      share_type vesting_cashback, vested_cashback;

      pay_out_fees(a, vesting_fee_subtotal, true);
      d.deposit_cashback(a, vesting_cashback, true);
      pay_out_fees(a, vested_fee_subtotal, false);
      d.deposit_cashback(a, vested_cashback, false);

      d.modify(*this, [vested_fee_subtotal, vesting_fee_subtotal](account_statistics_object& s) {
         s.lifetime_fees_paid += vested_fee_subtotal + vesting_fee_subtotal;
         s.pending_fees = 0;
         s.pending_vested_fees = 0;
      });
   }
}
Example #2
0
void refund_worker_type::pay_worker(share_type pay, database& db)
{
   total_burned += pay;
   db.modify(db.get(asset_id_type()).dynamic_data(db), [pay](asset_dynamic_data_object& d) {
      d.current_supply -= pay;
   });
}
Example #3
0
void find_all_janitors(database My_DB){
//In this function all janitors are retreived.
//This is done by first finding the department
//object with "Janitors" as value in to the
//Name attribute
ODB_QSTREAM q_stream;
ODB_SSTREAM s_stream;
ODB_REF o,jo;
char typenm[16]="Department";
char propnm[8]="Name";
char val[16]="Janitors";

	//Open a stream over the department type with the condition that
	//the Name attribute must have Janitors as value
	q_stream=My_DB.open_stream(typenm,propnm,val);

	//The stream may not be opened if so it is best to check before use.
	if (q_stream==NULL) {
		cout<<"\nError when opening stream bla bla bla...\n";
		return;
		};

	//The stream was opened allright. In the remaining we only consider the
	//first found department named Janitors, thus we do not assume the name
	//to be a key to departments

	o=My_DB.get(q_stream);

	//If o==NULL yhen there were no such department in the database
	if (o==NULL) {
		cout<<"No department named "<<val<<" exist in the database\n";
		return;
		}

	//No longer req'd
	My_DB.close_stream(q_stream);

	//reuse q_stream to open the stream to select all employees at
	//the department bound to object reference o

	q_stream=My_DB.open_stream("Employee","EmployedAt",o);
  if (q_stream==NULL) {
		cout<<"\nError when opening stream over employee\n";
		return;
		};
	cout<<"\nThese are the Janitors\n-------------------------\n";
	obuf.reset_buffer();			//reset the buffer
	//Now, we can start browsing the janitors
	jo=My_DB.get(q_stream);
	while (jo!=NULL){
		jo->display(obuf);
		cout<<obuf.get_buffer()<<'\n';
		obuf.reset_buffer();
		jo=My_DB.get(q_stream);
		};

	//Now, Lets select those janitors who earn more than 10000.
	//This is accomplished by opening a select stream over the
	//query stream which selects all janitors.

	//First, reset the stream
	My_DB.reset_stream(q_stream);

	//secondly, open a select stream over q_stream with the
	//condition that the salary should be greater than 10000
	s_stream=My_DB.select(q_stream,"Salary",">",(ODB_INT)10000);

	cout<<"\n Theese are all the rich janitors\n";
	obuf.reset_buffer();			//reset the buffer
	//Now, we can start browsing the rich janitors
	jo=My_DB.get(s_stream);
	while (jo!=NULL){
		jo->display(obuf);
		cout<<obuf.get_buffer()<<'\n';
		obuf.reset_buffer();
		jo=My_DB.get(s_stream);
		};

	My_DB.close_stream(s_stream);
	}