Bitshares区块及transaction

in #bitshares6 years ago

本文的目的是深入解析bitshares区块链的每一个区块具体数据结构是什么样的,每个区块下面包括一个或多个transaction,这些transaction的具体数据结构又是什么样的,当对区块结构及transaction结构有了清晰认识后,就可以从整体上认识链的操作原理。
【区块结构】

块结构 变量定义(类型&变量名) 类型

下面详解一下各个变量:
Block_id_type:这里的fc::ripemd160本质上是一个长度为5的uint32_t数组,存储了一个160位的哈希值,这个哈希值是链上前一个区块的哈希,当前区块根据这个哈希和前一个区块进行关联。
fc::time_point_sec:这个变量存储的是出块时间,具体定义见fc库相关代码,time_point_sec是对时间戳的封装。
witness_id_type:graphene区块链上每一个区块都是由21个见证人节点轮流生成的,这个witness_id_type存储的是生成这个区块的那个见证人id。
checksum_type:该区块中所有transaction生成的默克尔树。
extensions_type:用于将来扩展的数据结构,当将来对区块进行扩展时,此处可以存储一个或多个static_variant类型的变量,static_variant在fc库中,是一个模板类,支持将二进制数据流序列化对应的模板类对象,具体实现本文档不作详细说明。
signature_type:见证人签名,当区块被见证人产生出来后,该见证人对此区块进行签名操作,相关签名存在此处。
vector<processed_transaction>:这是一个容器,可以存储多个processed_transaction,processed_transaction是执行过的transaction,只有执行成功的transaction,才能被写入到区块之中。

【transaction结构】

一个transaction包括如下两个部分:基础部分和签名部分。基础部分,即transaction,存储了一个transaction的基本信息。签名部分,即signed_transaction,包含了见证人对这个transaction的签名,最终生成部分,包括了这个transaction的执行结果。
ref_block_num:一个transaction包含在一个区块中,这里存了该transaction所在区块的编号信息。
ref_block_prefix:这个变量存储了transaction所在区块的基本信息。
expiration:transaction的超时时间
operations:一个transaction所包含的操作,operation的具体定义在operations.hpp中,是一个fc::static_variant模板类,static_variant可以根据模板类的类型,将二进制数据进行还原操作,序列化为对象实体,如下图所示:

在bitshares里面有如上多种类型的operation,用户相关的operation例如acount_create_operation、account_update_operation,转账操作的operation是transfer_operation,而每一种operation的数据和长度不一样,因此需要一个static_variant类进行统一转化操作。operation中存储了一个transaction的关键业务数据,例如transfer_operation中存储了转账操作的来源账户、目标账户、转账金额、转账备注等。见证人结点接收到这个transaction后,根据其中的operation类型,执行相应的操作,并从operation中提取出关键数据,进行处理。
extensions:扩展部分。
signatures:见证人节点对transaction的签名。
operation_results:operation的操作结果,也是static_variant类型的数据。

【总结】

bitshares的一个区块包含多个processed_transaction,processed_transaction是执行成功的操作,包括创建账户、创建资产、转账、发布限价单等。

Sort:  

Congratulations @lpbottle! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!