美文网首页
EOS源码学习(二):DPOS投票模块

EOS源码学习(二):DPOS投票模块

作者: Gavin_Lau | 来源:发表于2018-08-28 14:47 被阅读0次



    需要首先理解的名词

    1. state

    2. band width

    3. bid

    首先看下 contracts\eosio.system.hpp :system_contract

    这个文件是关于 投票和唱票的过程代码

    class system_contract : public native {
             //投票人
             voters_table           _voters;
             //生产者,类似ethereum中的validator
             producers_table        _producers;
             //世界状态机
             global_state_singleton _global;
              //和band_width相关,暂时还不知道做什么用
             rammarket              _rammarket;
            
             void onblock( block_timestamp timestamp, account_name producer );
    /*delegate_bandwidth.cpp*/                
             //记录from账户和receiver账户之间因为这次delegate而发生的状态机的转换,
             //如果transfer为true,receiver可以回滚状态机,否则from可以回滚,在任何时候    
             //bw : band width
             void delegatebw( account_name from, account_name receiver,
                              asset stake_net_quantity, asset stake_cpu_quantity, bool transfer );
    
             //撤销 delegate操作,并释放资源
             //如果delegate操作已经执行,那么会执行一个 send the tokens back to 'from'
             //from账户调用该接口之后,就丧失了投票权,所有生产者的记录都会更新
             void undelegatebw( account_name from, account_name receiver,
                                asset unstake_net_quantity, asset unstake_cpu_quantity );
         
    /*voting.cpp*/ 
            ...
       };
    
    

    以上这些接口都是通过main函数中 action的方式创建
    example: eos\programs\cleos\main.cpp

    auto undelegate_bandwidth = actionRoot->add_subcommand("undelegatebw", localized("Undelegate bandwidth"));
    undelegate_bandwidth->add_option("from", from_str, localized("The account undelegating bandwidth"))->required();
    undelegate_bandwidth->add_option("receiver", receiver_str, localized("The account to undelegate bandwidth from"))->required();
    undelegate_bandwidth->add_option("unstake_net_quantity", unstake_net_amount, localized("The amount of EOS to undelegate for network bandwidth"))->required();
    undelegate_bandwidth->add_option("unstake_cpu_quantity", unstake_cpu_amount, localized("The amount of EOS to undelegate for CPU bandwidth"))->required();
    add_standard_transaction_options(undelegate_bandwidth);
    

    相关文章

      网友评论

          本文标题:EOS源码学习(二):DPOS投票模块

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