Author Topic: BTS源代码解读(一)  (Read 3495 times)

0 Members and 1 Guest are viewing this topic.

Offline ebit

  • Committee member
  • Hero Member
  • *
  • Posts: 1905
    • View Profile
  • BitShares: ebit
telegram:ebit521
https://weibo.com/ebiter

Offline mimitie

  • Full Member
  • ***
  • Posts: 67
    • View Profile
好文,必须支持!! +5% +5%

Offline callmeluc

  • Hero Member
  • *****
  • Posts: 552
    • View Profile
BTS_自扯自淡

Offline Harvey

  • Sr. Member
  • ****
  • Posts: 244
    • View Profile
BTS       Witness:harvey-xts Seed:128.199.143.47:2015 API:wss://128.199.143.47:2016 
MUSE   Witness:harvey-xts Seed:128.199.143.47:2017 API:ws://128.199.143.47:2018

Offline Overthetop

非常好的一个主题,赞!

建议后续不断针对关于BTS特性和优势的功能部分进行代码解读,该系列可以成为社区不错的资料积累。
个人微博账号: Overthetop_万里晴空
“块链创新与创业”交流群: 330378613

Offline sudo

  • Hero Member
  • *****
  • Posts: 2255
    • View Profile
  • BitShares: ags
解读的好啊 做成一个系列吧

Offline yuxuan

  • Sr. Member
  • ****
  • Posts: 266
    • View Profile

Offline kinglaw0577

  • Full Member
  • ***
  • Posts: 95
    • View Profile
    • BitShares Richlist
BTS源代码解读(一):
1.如果用bit资产支付交易费用,费用是BTS支付的3倍。

 【Wallet.cpp 3671行】

 if( desired_fee_asset_id != 0 )
      {
         const auto asset_rec = my->_blockchain->get_asset_record( desired_fee_asset_id );
         FC_ASSERT( asset_rec.valid() );
         if( asset_rec->is_market_issued() )
         {
             const auto median_price = my->_blockchain->get_active_feed_price( desired_fee_asset_id );
             if( median_price )
             {
                xts_fee += xts_fee + xts_fee; <=看这里,费用自加了2次
                // fees paid in something other than XTS are discounted 50%
                auto alt_fees_paid = xts_fee * *median_price;
                return alt_fees_paid;
             }
         }
      }

2.burn必须用BTS支付burn费用,最少BTS_BLOCKCHAIN_MIN_BURN_FEE为1BTS。

   void burn_operation::evaluate( transaction_evaluation_state& eval_state )
   { try {
      if( message.size() )
          FC_ASSERT( amount.asset_id == 0 ); <=看这里,不是BTS,是不能burn的。

      if( amount.asset_id == 0 )
      {
          FC_ASSERT( amount.amount >= BTS_BLOCKCHAIN_MIN_BURN_FEE, "", <=看这里,少于1BTS是会出现异常的。
                     ("amount",amount)
                     ("BTS_BLOCKCHAIN_MIN_BURN_FEE",BTS_BLOCKCHAIN_MIN_BURN_FEE) );
      }

3.如何计算利息

超过1年,按帐号余额 / 比特资产总供应量  *  累积费用总数 * 持有年数百分比;
少于 1年,80%按按帐号余额 / 比特资产总供应量  *  累积费用总数 * 持有年数百分比计算,20%按 帐号余额 / 比特资产总供应量  *  累积费用总数 * 持有年数百分比* 持有年数百分比;即20%乘两次持有年数百分比,是一个鼓励长期持有的算法,持有超过1年再拿利息更划算些。


            auto yield = (amount_withdrawn * fee_fund) / current_supply;

            /**
             *  If less than 1 year, the 80% of yield are scaled linearly with time and 20% scaled by time^2,
             *  this should produce a yield curve that is "80% simple interest" and 20% simulating compound
             *  interest.
             */
            if( elapsed_time < fc::seconds( BTS_BLOCKCHAIN_BLOCKS_PER_YEAR * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC ) )
            {
               auto original_yield = yield;
               // discount the yield by 80%
               yield *= 8;
               yield /= 10; <=看这里,yield 乘8除10(80%)

               auto delta_yield = original_yield - yield;  <=看这里,delta_yield保存20%部分。

               // yield == amount withdrawn / total usd  *  fee fund * fraction_of_year
               yield *= elapsed_time.to_seconds();
               yield /= (BTS_BLOCKCHAIN_BLOCKS_PER_YEAR * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC); ,<=80%那部分除1次

               delta_yield *= elapsed_time.to_seconds();
               delta_yield /= (BTS_BLOCKCHAIN_BLOCKS_PER_YEAR * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC);

               delta_yield *= elapsed_time.to_seconds();
               delta_yield /= (BTS_BLOCKCHAIN_BLOCKS_PER_YEAR * BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC);<=20%那部分除了2次

               yield += delta_yield;
            }

4.最后是大家都很关注的一个问题:如何解锁冻结的空投股份。
空投解冻期限,开始UTC时间2014-11-06T00:00:00,期长730天,线性释放。
大家升级到0.5版本后,在1575500区块后可以释放,大概时间是2015-01-20 16:30 UTC,大家可以计算一下目前能释放出多少(应该是10%多一点)。
  "sharedrop_balances": {
    "start_time": "2014-11-06T00:00:00",
    "duration_days": 730,
还是看源代码
           case withdraw_vesting_type:
           {
               const withdraw_vesting vesting_condition = condition.as<withdraw_vesting>();

               // First calculate max that could be claimed assuming no prior withdrawals
               share_type max_claimable = 0;
               if( at_time >= vesting_condition.start_time + vesting_condition.duration )
               {
                   max_claimable = vesting_condition.original_balance;
               }
               else if( at_time > vesting_condition.start_time )
               {
                   const auto elapsed_time = (at_time - vesting_condition.start_time).to_seconds();
                   FC_ASSERT( elapsed_time > 0 && elapsed_time < vesting_condition.duration );
                   max_claimable = (vesting_condition.original_balance * elapsed_time) / vesting_condition.duration; <=关键代码,按比例释放
                   FC_ASSERT( max_claimable >= 0 && max_claimable < vesting_condition.original_balance );
               }

               const share_type claimed_so_far = vesting_condition.original_balance - balance;
               FC_ASSERT( claimed_so_far >= 0 && claimed_so_far <= vesting_condition.original_balance );

               const share_type spendable_balance = max_claimable - claimed_so_far;
               FC_ASSERT( spendable_balance >= 0 && spendable_balance <= vesting_condition.original_balance );

               return asset( spendable_balance, condition.asset_id );
           }
☆bitshares Richlist富豪榜 http://richlist.btsabc.org
☆BTSABC wallet online比特帝国在线钱包 https://bit.btsabc.org