contracts/arisen.system/src/com.cpp
/**
    * @brief Updates owner COM balance upon buying COM tokens
    *
    * @param owner - account name of COM owner
    * @param payment - amount core tokens paid to buy COM
    * @param com_received - amount of purchased COM tokens
    *
    * @return asset - change in owner COM vote stake
    */
@brief Updates owner COM balance upon buying COM tokens
@param owner - account name of COM owner
@param payment - amount core tokens paid to buy COM
@param com_received - amount of purchased COM tokens

@return asset - change in owner COM vote stake
@brief Updates owner COM balance upon buying COM tokens @param owner - account name of COM owner @param payment - amount core tokens paid to buy COM @param com_received - amount of purchased COM tokens @return asset - change in owner COM vote stake
asset system_contract::add_to_com_balance( const name& owner, const asset& payment, const asset& com_received )
   {
      asset init_com_stake( 0, core_symbol() );
      asset current_com_stake( 0, core_symbol() );
      auto bitr = _combalance.find( owner.value );
      if ( bitr == _combalance.end() ) {
         bitr = _combalance.emplace( owner, [&]( auto& rb ) {
            rb.owner       = owner;
            rb.vote_stake  = payment;
            rb.com_balance = com_received;
         });
         current_com_stake.amount = payment.amount;
      } else {
         init_com_stake.amount = bitr->vote_stake.amount;
         _combalance.modify( bitr, same_payer, [&]( auto& rb ) {
            rb.com_balance.amount += com_received.amount;
            rb.vote_stake.amount   = ( uint128_t(rb.com_balance.amount) * _compool.begin()->total_lendable.amount )
                                     / _compool.begin()->total_com.amount;
         });
         current_com_stake.amount = bitr->vote_stake.amount;
      }
      const int64_t com_in_savings = read_com_savings( bitr );
      process_com_maturities( bitr );
      _combalance.modify( bitr, same_payer, [&]( auto& rb ) {
         const time_point_sec maturity = get_com_maturity();
         if ( !rb.com_maturities.empty() && rb.com_maturities.back().first == maturity ) {
            rb.com_maturities.back().second += com_received.amount;
         } else {
            rb.com_maturities.emplace_back( maturity, com_received.amount );
         }
      });
      put_com_savings( bitr, com_in_savings );
      return current_com_stake - init_com_stake;
   }
asset system_contract :: add_to_com_balance ( const name & owner , const asset & payment , const asset & com_received ) { asset init_com_stake ( 0 , core_symbol ( ) ) ; asset current_com_stake ( 0 , core_symbol ( ) ) ; auto bitr = _combalance . find ( owner . value ) ; if ( bitr == _combalance . end ( ) ) { bitr = _combalance . emplace ( owner , [ & ] ( auto & rb ) { rb . owner = owner ; rb . vote_stake = payment ; rb . com_balance = com_received ; } ) ; current_com_stake . amount = payment . amount ; } else { init_com_stake . amount = bitr -> vote_stake . amount ; _combalance . modify ( bitr , same_payer , [ & ] ( auto & rb ) { rb . com_balance . amount += com_received . amount ; rb . vote_stake . amount = ( uint128_t ( rb . com_balance . amount ) * _compool . begin ( ) -> total_lendable . amount ) / _compool . begin ( ) -> total_com . amount ; } ) ; current_com_stake . amount = bitr -> vote_stake . amount ; } const int64_t com_in_savings = read_com_savings ( bitr ) ; process_com_maturities ( bitr ) ; _combalance . modify ( bitr , same_payer , [ & ] ( auto & rb ) { const time_point_sec maturity = get_com_maturity ( ) ; if ( ! rb . com_maturities . empty ( ) && rb . com_maturities . back ( ) . first == maturity ) { rb . com_maturities . back ( ) . second += com_received . amount ; } else { rb . com_maturities . emplace_back ( maturity , com_received . amount ) ; } } ) ; put_com_savings ( bitr , com_in_savings ) ; return current_com_stake - init_com_stake ; }
@brief Updates owner COM balance upon buying COM tokens
 @param owner - account name of COM owner
 @param payment - amount core tokens paid to buy COM
 @param com_received - amount of purchased COM tokens
@brief Updates owner COM balance upon buying COM tokens @param owner - account name of COM owner @param payment - amount core tokens paid to buy COM @param com_received - amount of purchased COM tokens