美文网首页比特股教程实时更细
bitshares基本概念详解【vesting balance】

bitshares基本概念详解【vesting balance】

作者: 聂怀远 | 来源:发表于2018-06-23 20:34 被阅读0次

    接触Bitshares一段时间后,就经常看到vesting balance这个词,来看看这个是干嘛的。

    什么是Vesting Balances?

    在Bitshares钱包菜单中有一项是"Vesting balances",打开看看它的说明,如下:

    Vesting balances contain any fees earned through the referral program or from worker pay, for example. They have a certain vesting period and are continually unlocked during that vesting period until all of the balances are available

    看起来与公司授予股份类似,这个是授予的资金(可能是worker付费、引荐费用、燃料费用等),但这些资金需要满足一定的条件(到达一定时间等)才能真正提取出来。

    都有哪些Vesting Balances?

    因为自己帐户没有这项数据,我们直接找个见证人看一下,通过cli_wallet可以取到帐户的vesting balances数据,如下:

    unlocked >>> get_vesting_balances fox

    get_vesting_balances fox

    [{

        "id": "1.13.16",

        "owner": "1.2.167",

        "balance": {

          "amount": 5117015,

          "asset_id": "1.3.0"

        },

        "policy": [

          1,{

            "vesting_seconds": 7776000,

            "start_claim": "1970-01-01T00:00:00",

            "coin_seconds_earned": "39789908640000",

            "coin_seconds_earned_last_update": "2018-06-22T06:00:00"

          }

        ],

        "allowed_withdraw": {

          "amount": 5117015,

          "asset_id": "1.3.0"

        },

        "allowed_withdraw_time": "2018-06-22T06:57:00"

      },{

        "id": "1.13.32",

        "owner": "1.2.167",

        "balance": {

          "amount": "8049800000",

          "asset_id": "1.3.0"

        },

        "policy": [

          1,{

            "vesting_seconds": 86400,

            "start_claim": "1970-01-01T00:00:00",

            "coin_seconds_earned": "695494080000000",

            "coin_seconds_earned_last_update": "2018-06-22T06:57:00"

          }

        ],

        "allowed_withdraw": {

          "amount": "8049700000",

          "asset_id": "1.3.0"

        },

        "allowed_withdraw_time": "2018-06-22T06:57:00"

      }

    ]

    allowed_withdraw就是可以提取的资金,让我先感叹一下好有钱!

    相应的数据结构定义为vesting_balance_object,在vesting_balance_object.hpp中可以查看,不再列出。但可以通过代码查一下都有哪些对象使用了vesting_balance,很简单查到有以下几个地方:

    account_object

    witness_object

    worker_object

    基本上确定就是帐户的现金返还、见证人工资、工人工资这几项了。

    看看"fox"的vesting balances都是哪来的?用get_account fox可以看到,其中一个是cashback,如下:

      "cashback_vb": "1.13.16",

    用get_witness fox查看,另一项是见证人工资了,如下:

      "pay_vb": "1.13.32",

    怎么获得Vesting Balances

    从上面可知有这几种Vesting Balances,那都有哪些你怎么获得呢?

    帐户的cashback

    account_object.cpp -> process_fees

            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);

    在这个函数中有以上几处存取现金返还,终身会员引荐人、引荐人、注册人都有现金返还。

    见证人的pay_vb

    db_update.cpp

    void database::update_signing_witness(const witness_object& signing_witness, const signed_block& new_block)

    {

      const global_property_object& gpo = get_global_properties();

      const dynamic_global_property_object& dpo = get_dynamic_global_properties();

      uint64_t new_block_aslot = dpo.current_aslot + get_slot_at_time( new_block.timestamp );

      share_type witness_pay = std::min( gpo.parameters.witness_pay_per_block, dpo.witness_budget );

      modify( dpo, [&]( dynamic_global_property_object& _dpo )

      {

          _dpo.witness_budget -= witness_pay;

      } );

      deposit_witness_pay( signing_witness, witness_pay );

      modify( signing_witness, [&]( witness_object& _wit )

      {

          _wit.last_aslot = new_block_aslot;

          _wit.last_confirmed_block_num = new_block.block_num();

      } );

    }

    打包见证人会得到vesting balances

    worker balance

    db_main.cpp

    struct worker_pay_visitor

    {

      private:

          share_type pay;

          database& db;

      public:

          worker_pay_visitor(share_type pay, database& db)

            : pay(pay), db(db) {}

          typedef void result_type;

          template

          void operator()(W& worker)const

          {

            worker.pay_worker(pay, db);

          }

    };

    每个worker类型都有balance对象,通过pay_worker()可以给工人付费。

    从以上分析看来,要获得Vesting balances,可以成为其他帐户的推荐人、引荐人、终身引荐人,或者做打包见证人,或者做工人(worker)完成一定工作任务,暂时看大概就这几种途径了。

    Vesting Balances相关操作

    有两个相关的operation可以操作Vesting Balances,如下:

    1、vesting_balance_create_operation

    一般情况下会自动创建vesting balance对象,但是也可以手动创建一个vesting balance对象。翻译不好,直接看英文注释...

    Manual creation of vesting balances can be used by a stakeholder

    to publicly demonstrate that they are committed to the chain.

    It can also be used as a building block to create transactions

    that function like public debt. Finally, it is useful for

    testing vesting balance functionality.

    2、vesting_balance_withdraw_operation

    提取vesting balance,当然需要满足一定的条件,如下:

    void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balance_withdraw_operation& op )

    { try {

      const database& d = db();

      const time_point_sec now = d.head_block_time();

      const vesting_balance_object& vbo = op.vesting_balance( d );

      FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) );

      FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "", ("now", now)("op", op)("vbo", vbo) );

      assert( op.amount <= vbo.balance );      // is_withdraw_allowed should fail before this check is reached

      /* const account_object& owner_account = */ op.owner( d );

      // TODO: Check asset authorizations and withdrawals

      return void_result();

    } FC_CAPTURE_AND_RETHROW( (op) ) }

    这个条件在is_withdraw_allowed()中进行判断,是否到达时间、币数量是否够等。

    文章名字都叫基本概念详解,不再细化了,各种费用的具体分配等再研究。

    感谢您阅读 @chaimyu 的帖子,期待您能留言交流!

    https://steemit.com/bitshares/@chaimyu/bitshares-vesting-balance

    相关文章

      网友评论

        本文标题:bitshares基本概念详解【vesting balance】

        本文链接:https://www.haomeiwen.com/subject/loydyftx.html