1、块链(Blockchain)
表现形式为块文件,名称如blockfile_000000,由块(Block)按照顺序排列组成,每一个块的头部(Header)都包含了当前块的data_hash和前一个块的hash值previous_hash,官网blockchain结构图如下:
块链B包含了块B0,B1,B2,B3,其中B0是创世块(genesis block)
2、块(Block)
包含3部分内容:块头,块数据,块的元数据。具体描述如下:
2.1块头(Block Header)
块头结构形式如下:
"header": {
"data_hash": "xXLEx+MSmIh3XiYCOOzgqgbncCWv/CerQmr4pv5htIw=",
"number": "4",
"previous_hash": "EItAeMfX54G8vIsMmWnkMPtVTDKVgfR1aKcgP/tbN8I="
}
此部分包含3个字段:
data_hash为当前块中所有交易事务的hash值。
number为从0开始的整数(创世块),并且对于附加到区块链的每个新块增加1。
previous_hash为块链中前一个区块的hash副本。
官网block header结构图如下:
2.2块数据(Block Data)
块数据由排好序的交易组成,一个块中包含多个交易(Transaction ),官网block data结构图如下:
一个交易(Transaction )包含以下几个属性:
Header
包含了一些交易事务的元数据,比如channel的一些名称,版本,以及创建者的签名等,格式如下:
"header": {
"channel_header": {
"channel_id": "mychannel",
"epoch": "0",
"extension": "EgYSBG15Y2M=",
"timestamp": "2019-06-13T02:16:46.816Z",
"tls_cert_hash": null,
"tx_id": "224c43035991e9c82f50e6d0fe53f0ef121e2f9f17a7d8303b40ee600f13b639",
"type": 3,
"version": 1
},
"signature_header": {
"creator": {
"id_bytes": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNpekNDQWpHZ0F3SUJBZ0lVVGtGemhLU1BRTkExYmZSYUFpbmxkRmd6QVVzd0NnWUlLb1pJemowRUF3SXcKY3pFTE1Ba0dBMVVFQmhNQ1ZWTXhFekFSQmdOVkJBZ1RDa05oYkdsbWIzSnVhV0V4RmpBVUJnTlZCQWNURFZOaApiaUJHY21GdVkybHpZMjh4R1RBWEJnTlZCQW9URUc5eVp6RXVaWGhoYlhCc1pTNWpiMjB4SERBYUJnTlZCQU1UCkUyTmhMbTl5WnpFdVpYaGhiWEJzWlM1amIyMHdIaGNOTVRrd05qRXpNREl4TVRBd1doY05NakF3TmpFeU1ESXgKTmpBd1dqQkFNVEF3RFFZRFZRUUxFd1pqYkdsbGJuUXdDd1lEVlFRTEV3UnZjbWN4TUJJR0ExVUVDeE1MWkdWdwpZWEowYldWdWRERXhEREFLQmdOVkJBTVRBMHBwYlRCWk1CTUdCeXFHU000OUFnRUdDQ3FHU000OUF3RUhBMElBCkJNcDJ6eEJhMzdIdnFSNDJoMC9qNlNZYXd4KzltdkNyeEhjakgxTmVDVURibkhUTDRCVVk3NUEza2tPMXpaTkkKYkU1cFRpcFNOM0h1eWprakVuL3QvK3lqZ2RVd2dkSXdEZ1lEVlIwUEFRSC9CQVFEQWdlQU1Bd0dBMVVkRXdFQgovd1FDTUFBd0hRWURWUjBPQkJZRUZPMHpCNWRRMTBpZXR0RWQ4OGViaGU1OWtxWHBNQ3NHQTFVZEl3UWtNQ0tBCklBNXlraVRvcy9NWGhNaXBQRnVPOXZUQnlSMmVibGQ4UmNNeFkyQ2Y1QUFSTUdZR0NDb0RCQVVHQndnQkJGcDcKSW1GMGRISnpJanA3SW1obUxrRm1abWxzYVdGMGFXOXVJam9pYjNKbk1TNWtaWEJoY25SdFpXNTBNU0lzSW1obQpMa1Z1Y205c2JHMWxiblJKUkNJNklrcHBiU0lzSW1obUxsUjVjR1VpT2lKamJHbGxiblFpZlgwd0NnWUlLb1pJCnpqMEVBd0lEU0FBd1JRSWhBTURIYUt4cnNoL04waWxNcVUvZXJXbEl3VUVTdEpXSUs1b1hWamE1UUR6UkFpQjcKQ3pIQ253Z1NPTjZIdGttSUdXK1pJZ29OVFdtOFFmWit4Qlg0aUY3blJ3PT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=",
"mspid": "Org1MSP"
},
"nonce": "SlpXTH6uBi4iyNi+2dQ21bRQ4vVtG8vT"
}
}
Signature
包含由客户端应用程序创建的加密签名。此字段用于检查事务详细信息是否未被篡改,因为它需要应用程序的私钥来生成它。格式如下:
"signature": "MEQCICcPzlrVQR/0CMVWJHXLk1kMFVpr9MmuJZhRyUn4X1hKAiA0Ezciz6N5RVqH/ux8dxF9ggDNaIZp4vf67da3CgZVjw=="
Proposal
智能合约输入的参数,这些参数与当前世界状态一起确定新的世界状态。格式如下:
"chaincode_proposal_payload": {
"TransientMap": {},
"input": {
"chaincode_spec": {
"chaincode_id": {
"name": "mycc",
"path": "",
"version": ""
},
"input": {
"args": [
"bW92ZQ==",
"YQ==",
"Yg==",
"MTA="
],
"decorations": {}
},
"timeout": 0,
"type": "GOLANG"
}
}
}
Response
捕获世界状态的前后值,作为读写集(RW-set),它是智能合约的输出,如果交易成功验证,将用于账本来更新世界状态。格式如下:
"proposal_response_payload": {
"extension": {
"chaincode_id": {
"name": "mycc",
"path": "",
"version": "v0"
},
"events": null,
"response": {
"message": "",
"payload": null,
"status": 200
},
"results": {
"data_model": "KV",
"ns_rwset": [
{
"collection_hashed_rwset": [],
"namespace": "lscc",
"rwset": {
"metadata_writes": [],
"range_queries_info": [],
"reads": [
{
"key": "mycc",
"version": {
"block_num": "3",
"tx_num": "0"
}
}
],
"writes": []
}
},
{
"collection_hashed_rwset": [],
"namespace": "mycc",
"rwset": {
"metadata_writes": [],
"range_queries_info": [],
"reads": [
{
"key": "a",
"version": {
"block_num": "3",
"tx_num": "0"
}
},
{
"key": "b",
"version": {
"block_num": "3",
"tx_num": "0"
}
}
],
"writes": [
{
"is_delete": false,
"key": "a",
"value": "OTA="
},
{
"is_delete": false,
"key": "b",
"value": "MjEw"
}
]
}
}
]
},
"token_expectation": null
},
"proposal_hash": "SD+6jiDm7JhbqUYEWFp8CHv63IKWeu0KxQ1WgoiMYGU="
}
Endorsements
存放组织的背书策略,验证交易的响应消息,格式如下:
"endorsements": [
{
"endorser": "CgdPcmcxTVNQEpIGLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNHRENDQWIrZ0F3SUJBZ0lRUGNNRkZFQi92cTZtRUw2dlhWN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3块的元数据(Block Metadata)
块的元数据包含写入块的时间,证书,公钥,签名。这些信息都包含在hash值中,展现形式如下:
"metadata": {
"metadata": [
"Ev0GCrIGCpUGCgpPcmRlcmVyTVNQEoYGLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNEVENDQWJPZ0F3SUJBZ0lSQUxGYWZKaVRGTi80N0F2QUdmdmoxWkV3Q2dZSUtvWkl6ajBFQXdJd2FURUwKTUFrR0ExVUVCaE1DVlZNeEV6QVJCZ05WQkFnVENrTmhiR2xtYjNKdWFXRXhGakFVQmdOVkJBY1REVk5oYmlCRwpjbUZ1WTJselkyOHhGREFTQmdOVkJBb1RDMlY0WVcxd2JHVXVZMjl0TVJjd0ZRWURWUVFERXc1allTNWxlR0Z0CmNHeGxMbU52YlRBZUZ3MHhOekEyTWpNeE1qTXpNVGxhRncweU56QTJNakV4TWpNek1UbGFNRmd4Q3pBSkJnTlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZBWURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVJ3d0dnWURWUVFERXhOdmNtUmxjbVZ5TG1WNFlXMXdiR1V1WTI5dE1Ga3dFd1lIS29aSXpqMENBUVlJCktvWkl6ajBEQVFjRFFnQUVZdGd1TEtGQkxMYzBWU3d5UEhISE5lNzZISDcxb09YSzZ3dW44WS81dnRNYXdQWi8KV1RtL3ZCVlVXZGZObHpjOWVBMjhhWHg2ekJBQjhpUm0xNkVlVTZOTk1Fc3dEZ1lEVlIwUEFRSC9CQVFEQWdlQQpNQXdHQTFVZEV3RUIvd1FDTUFBd0t3WURWUjBqQkNRd0lvQWdEVWJNOE9sRGJCdkR0dUsvZ00yeUFzU1VOZ1Q1ClhITHVEL2c1MCt3d0J4a3dDZ1lJS29aSXpqMEVBd0lEU0FBd1JRSWhBTkp1RUdIQmZ0cnRsV2dpZTl6Z2M2MEoKL1hWeXRQTi9EMHJQbGtNVjE3bjdBaUJCYlN0Z2dHQmZGWWNRMkxoRGhjS3V0OG5TY0oyT0ZydCtkSlNkSmJvZAo3QT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0KEhgMl8pnRgyz0NEiuuiRY1+GkpjgcxBd+6ESRjBEAiBDtkBc8aT5MtlqJIotkZz2L92YYFAUOKbAz2iqIf+nlwIgDa+PwfPqyip2sLJPr9GZ9XNanICpANmQGRdfYgoD9/s=",
""
]
}
以上解释参考官网文档:https://hyperledger-fabric.readthedocs.io/en/release-1.4/ledger/ledger.html#blocks
有疑问加站长微信联系(非本文作者)