美文网首页
EOS源码阅读-producers(添加区块生产者)

EOS源码阅读-producers(添加区块生产者)

作者: 坠叶飘香 | 来源:发表于2018-09-13 18:59 被阅读0次

1. producers_table

eos/contracts/eosio.system/eosio.system.hpp

//TableName: producers
//typename: producer_info 数据结构
//索引名为prototalvote,获得索引的方法为by_votes
typedef eosio::multi_index< N(producers), 
                                producer_info, 
                               indexed_by<N(prototalvote), const_mem_fun<producer_info, double, &producer_info::by_votes> > //设置索引
                               >  producers_table; 

2.producer_info

eos/contracts/eosio.system/eosio.system.hpp

struct producer_info {
      account_name          owner; //The account to register as a producer (required) 生产区块的账户名
      double                total_votes = 0;
      eosio::public_key     producer_key; // a packed public key object. The producer's public key (required) //公钥
      bool                  is_active = true;
      std::string           url; //url where info about producer can be found
      uint32_t              unpaid_blocks = 0;
      uint64_t              last_claim_time = 0;
      uint16_t              location = 0; //relative location for purpose of nearest neighbor(邻居) scheduling

      //主键
      uint64_t primary_key()const { return owner;                                   } //const修饰的成员函数不能修改任何的成员变量
      
      //索引
      double   by_votes()const    { return is_active ? -total_votes : total_votes;  }
     
      bool     active()const      { return is_active;                               }
     
       void     deactivate()       { producer_key = public_key(); is_active = false; }
      //序列化
      // explicit serialization macro is not necessary, used here only to improve compilation time
      EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key)(is_active)(url)
                        (unpaid_blocks)(last_claim_time)(location) )
   };

3.regproducer

注册一个区块生产者
命令:$ ./cleos system regproducer producerA producerA_PublicKey
命令参数解释:
cleos system regproducer [OPTIONS] account producer_key [url] [location]
Positionals:
account TEXT The account to register as a producer (required)
producer_key TEXT The producer's public key (required)
url TEXT url where info about producer can be found
location UINT=0 relative location for purpose of nearest neighbor(邻居) scheduling
源码:
eos/contracts/eosio.system/voting.cpp


regproducer

相关文章

网友评论

      本文标题:EOS源码阅读-producers(添加区块生产者)

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