其他分享
首页 > 其他分享> > EOS 源代码解读 (3)区块数据结构

EOS 源代码解读 (3)区块数据结构

作者:互联网

1.chain/types.hpp

   using block_id_type       = fc::sha256;
   using checksum_type       = fc::sha256;
   using checksum256_type    = fc::sha256;
   using checksum512_type    = fc::sha512;
   using checksum160_type    = fc::ripemd160;
   using transaction_id_type = checksum_type;
   using digest_type         = checksum_type;
   using weight_type         = uint16_t;
   using block_num_type      = uint32_t;
   using share_type          = int64_t;
   using int128_t            = __int128;
   using uint128_t           = unsigned __int128;
   using bytes               = vector<char>;
   using digests_t           = deque<digest_type>;

2. block_header

struct block_header
{
   block_timestamp_type             timestamp;
   account_name                     producer;//帐户标识符 13字节

   uint16_t                         confirmed = 1;  

   block_id_type                    previous;//前一块的HASH

   checksum256_type                 transaction_mroot; /// mroot of cycles_summary
   checksum256_type                 action_mroot; /// mroot of all delivered action receipts

   uint32_t                          schedule_version = 0;
   optional<producer_schedule_type>  new_producers;//新生产者
   extensions_type                   header_extensions;

   digest_type       digest()const;//摘要哈希
   block_id_type     id() const;   //自己的哈希
   uint32_t          block_num() const { return num_from_id(previous) + 1; }
   static uint32_t   num_from_id(const block_id_type& id);//ID是任意数字,区块号是从零长到现在的排序号 ID=HASH+n    
};

struct signed_block_header : public block_header
{
   signature_type    producer_signature;//生产者签名
};

3. block.hpp

using signed_block_ptr = std::shared_ptr<signed_block>;//重定义一个新的数据类型,方便使用

struct signed_block : public signed_block_header{ 
  vector<transaction_receipt>   transactions; /// new or generated transactions
  extensions_type               block_extensions;

  flat_multimap<uint16_t, block_extension> validate_and_extract_extensions()const;
};

标签:区块,const,EOS,header,using,源代码,type,id,block
来源: https://blog.csdn.net/thefist11cc/article/details/120398878