hyperledger-fabricにブロックチェーンを学ぶ(1/9)ブロックチェーンとは
hyperledger-fabricにブロックチェーンを学ぶ(2/9)サンプルを動かす
⇒ hyperledger-fabricにブロックチェーンを学ぶ(3/9)ブロックを見る
hyperledger-fabricにブロックチェーンを学ぶ(4/9)kafkaを入れる
hyperledger-fabricにブロックチェーンを学ぶ(5/9)可視化する
ブロックには何が書きこまれているのか、サンプルで表示したブロック にて確認する。
サンプル実行後のフォルダ構成を頭の片隅に入れておこう。
app
└create-channel.js
└helper.js
└install-chaincode.js
└instantiate-chaincode.js
└invoke-transaction.js
└join-channel.js
└query.js
└update-anchor-peers.js
app.js
artifacts
base.yaml
└channel
└docker-compose.yaml
└network-config.yaml
└org1.yaml
└org2.yaml
└src
config.js
config.json
fabric-client-kv-org1
└Jim
└admin
fabric-client-kv-org2
└Barry
└admin
node_modules
package.json
runApp.sh
testAPIs.sh
typescript
testAPIs.sh で最後に表示したブロック
{
"header": {
"number": "4",
"previous_hash": "8b0cbe2c5571022378ac28a49041265bff43dd7c78c4b9b982a8dc64f40d91e4",
"data_hash": "6cb23e7c52ea5c63c620c8bca3d1102e9bdc007eb96f0cfad9003b519ca21034"
},
"data": {
"data": [
{
"signature": {
"type": "Buffer",
"data": [48,68,2,32,102,207,159,4,244,152,162,253,223,85,51,148,41,209,251,232,240,224,193,137,165,125,22,92,225,222,88,149,149,22,220,31,2,32,18,31,81,75,43,232,220,223,204,193,4,250,131,174,234,162,174,132,252,103,55,170,88,63,87,98,73,171,2,137,215,157]
},
"payload": {
"header": {
"channel_header": {
"type": 3,
"version": 1,
"timestamp": "2019-03-28T14:21:19.412Z",
"channel_id": "mychannel",
"tx_id": "2dad951eaee76f886d8faa41fb1cac827890e7a3bab5e047794f5627539593f6",
"epoch": "0",
"extension": {
"type": "Buffer",
"data": [18,6,18,4,109,121,99,99] ⇒ 制御文字4つ mycc
},
"typeString": "ENDORSER_TRANSACTION"
},
"signature_header": {
"creator": {
"Mspid": "Org1MSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICijCCAjGgAwIBAgIUIoa9iSZnRWRLRRvei9y5TFlTOLMwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTkwMzI5MDYxNjAwWhcNMjAwMzI4MDYy\nMTAwWjBAMTAwDQYDVQQLEwZjbGllbnQwCwYDVQQLEwRvcmcxMBIGA1UECxMLZGVw\nYXJ0bWVudDExDDAKBgNVBAMTA0ppbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBBdaqfd7iq050YsuLtD/QHZIcUG0iAAlUjllKwS9FlFDaYm6xLV8YRlCeds+61Fh\naKgO1Gj9PSlWclLBLkSzkmyjgdUwgdIwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB\n/wQCMAAwHQYDVR0OBBYEFFO2uAXE02W+M34U0gGksA/EyEtdMCsGA1UdIwQkMCKA\nIA5ykiTos/MXhMipPFuO9vTByR2ebld8RcMxY2Cf5AARMGYGCCoDBAUGBwgBBFp7\nImF0dHJzIjp7ImhmLkFmZmlsaWF0aW9uIjoib3JnMS5kZXBhcnRtZW50MSIsImhm\nLkVucm9sbG1lbnRJRCI6IkppbSIsImhmLlR5cGUiOiJjbGllbnQifX0wCgYIKoZI\nzj0EAwIDRwAwRAIgMBhpyAqPtlDybflvgCud74rN0zksOxRpL63u+vnPmeECIERx\nCoaRpoyBUG1WwZUHRuZBPwhuXPKjLG5ydtmQpkCM\n-----END CERTIFICATE-----\n"
},
"nonce": {
"type": "Buffer",
"data": [124,14,33,239,250,75,17,172,1,180,23,163,27,135,243,75,177,46,151,159,184,52,98,98]
}
}
},
"data": {
"actions": [
{
"header": {
"creator": {
"Mspid": "Org1MSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICijCCAjGgAwIBAgIUIoa9iSZnRWRLRRvei9y5TFlTOLMwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTkwMzI5MDYxNjAwWhcNMjAwMzI4MDYy\nMTAwWjBAMTAwDQYDVQQLEwZjbGllbnQwCwYDVQQLEwRvcmcxMBIGA1UECxMLZGVw\nYXJ0bWVudDExDDAKBgNVBAMTA0ppbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBBdaqfd7iq050YsuLtD/QHZIcUG0iAAlUjllKwS9FlFDaYm6xLV8YRlCeds+61Fh\naKgO1Gj9PSlWclLBLkSzkmyjgdUwgdIwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB\n/wQCMAAwHQYDVR0OBBYEFFO2uAXE02W+M34U0gGksA/EyEtdMCsGA1UdIwQkMCKA\nIA5ykiTos/MXhMipPFuO9vTByR2ebld8RcMxY2Cf5AARMGYGCCoDBAUGBwgBBFp7\nImF0dHJzIjp7ImhmLkFmZmlsaWF0aW9uIjoib3JnMS5kZXBhcnRtZW50MSIsImhm\nLkVucm9sbG1lbnRJRCI6IkppbSIsImhmLlR5cGUiOiJjbGllbnQifX0wCgYIKoZI\nzj0EAwIDRwAwRAIgMBhpyAqPtlDybflvgCud74rN0zksOxRpL63u+vnPmeECIERx\nCoaRpoyBUG1WwZUHRuZBPwhuXPKjLG5ydtmQpkCM\n-----END CERTIFICATE-----\n"
},
"nonce": {
"type": "Buffer",
"data": [124,14,33,239,250,75,17,172,1,180,23,163,27,135,243,75,177,46,151,159,184,52,98,98]
}
},
"payload": {
"chaincode_proposal_payload": {
"input": {
"chaincode_spec": {
"type": 1,
"typeString": "GOLANG",
"input": {
"args": [
{
"type": "Buffer",
"data": [109,111,118,101] ⇒ move
},
{
"type": "Buffer",
"data": [97] ⇒ a
},
{
"type": "Buffer",
"data": [98] ⇒ b
},
{
"type": "Buffer",
"data": [49,48] ⇒ 10
}
],
"decorations": {}
},
"chaincode_id": {
"path": "",
"name": "mycc",
"version": ""
},
"timeout": 0
}
}
},
"action": {
"proposal_response_payload": {
"proposal_hash": "ac2e84772c33707fb4f4bf63411b9aecea2d5a8913e2fbbe84a6ddbca5e5f92f",
"extension": {
"results": {
"data_model": 0,
"ns_rwset": [
{
"namespace": "lscc",
"rwset": {
"reads": [
{
"key": "mycc",
"version": {
"block_num": "3",
"tx_num": "0"
}
}
],
"range_queries_info": [],
"writes": [],
"metadata_writes": []
},
"collection_hashed_rwset": []
},
{
"namespace": "mycc",
"rwset": {
"reads": [
{
"key": "a",
"version": {
"block_num": "3",
"tx_num": "0"
}
},
{
"key": "b",
"version": {
"block_num": "3",
"tx_num": "0"
}
}
],
"range_queries_info": [],
"writes": [
{
"key": "a",
"is_delete": false,
"value": "90"
},
{
"key": "b",
"is_delete": false,
"value": "210"
}
],
"metadata_writes": []
},
"collection_hashed_rwset": []
}
]
},
"events": {
"chaincode_id": "",
"tx_id": "",
"event_name": "",
"payload": {
"type": "Buffer",
"data": []
}
},
"response": {
"status": 200,
"message": "",
"payload": ""
},
"chaincode_id": {
"path": "",
"name": "mycc",
"version": "v0"
}
}
},
"endorsements": [
{
"endorser": {
"Mspid": "Org1MSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um\nxdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE\nyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG\nrFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber\nHE6DFYvvBCUnicUh\n-----END CERTIFICATE-----\n"
},
"signature": {
"type": "Buffer",
"data": [48,69,2,33,0,184,85,5,216,126,149,17,232,146,86,186,209,61,99,216,73,184,250,211,127,188,94,239,176,173,53,184,147,225,230,32,224,2,32,27,125,245,235,251,240,224,44,209,39,245,75,10,77,137,128,124,122,204,41,25,17,129,179,230,172,20,114,169,97,57,30]
}
},
{
"endorser": {
"Mspid": "Org2MSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICGjCCAcCgAwIBAgIRANDlqX1daKI2aN0Qm7vrfKAwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzIuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzIuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5\nWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjAub3JnMi5leGFtcGxlLmNvbTBZ\nMBMGByqGSM49AgEGCCqGSM49AwEHA0IABP8N39LBcB0qJyb3v9Y9WIPfYHOfWPna\nT8WyWzGisrYvHVF+GLfDLFrjQs0uN8QPsTsqYlnXDs/Mjv7tZaE9NuqjTTBLMA4G\nA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIKfUfvpGproH\ncwyFD+0sE3XfJzYNcif0jNwvgOUFZ4AFMAoGCCqGSM49BAMCA0gAMEUCIQDa1gKe\nPRVRN/i8hUptACw02V7V9Yeo7kKlbQ6vWU5fqAIgXg2xAQ4TjwXOHlKbIyYZ7fox\ncekBJ+E8yAFm8XQrfy0=\n-----END CERTIFICATE-----\n"
},
"signature": {
"type": "Buffer",
"data": [48,68,2,32,69,227,244,109,146,87,73,72,202,19,93,217,59,83,32,3,58,184,191,47,43,145,84,150,48,222,122,177,217,25,224,86,2,32,31,144,96,135,151,216,87,187,41,240,46,68,163,222,6,169,180,84,77,108,167,204,173,196,149,75,62,240,131,59,242,21]
}
}
]
}
}
}
]
}
}
}
]
},
"metadata": {
"metadata": [
{
"value": "",
"signatures": [
{
"signature_header": {
"creator": {
"Mspid": "OrdererMSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt\ncGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp\nc2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI\nKoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/\nWTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA\nMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5\nXHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J\n/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod\n7A==\n-----END CERTIFICATE-----\n"
},
"nonce": {
"type": "Buffer",
"data": [86,126,13,155,235,154,181,64,34,95,108,8,139,17,57,105,198,197,134,29,247,47,179,50]
}
},
"signature": {
"type": "Buffer",
"data": [48,68,2,32,20,11,129,219,145,183,215,232,128,197,219,39,23,11,100,140,137,110,46,171,56,206,162,137,178,106,60,13,43,37,103,59,2,32,94,144,199,55,126,6,246,128,143,0,175,54,21,247,102,233,21,176,248,182,116,156,239,250,135,2,36,154,31,149,135,146]
}
}
]
},
{
"value": {
"index": "2"
},
"signatures": [
{
"signature_header": {
"creator": {
"Mspid": "OrdererMSP",
"IdBytes": "-----BEGIN CERTIFICATE-----\nMIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt\ncGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp\nc2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI\nKoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/\nWTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA\nMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5\nXHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J\n/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod\n7A==\n-----END CERTIFICATE-----\n"
},
"nonce": {
"type": "Buffer",
"data": [118,153,113,159,176,68,110,219,177,240,88,179,175,201,99,230,148,55,241,246,216,4,6,108]
}
},
"signature": {
"type": "Buffer",
"data": [48,68,2,32,84,58,223,153,69,212,154,75,199,40,36,19,90,220,119,249,167,59,229,148,28,211,122,127,82,154,60,51,229,133,138,174,2,32,3,0,51,204,231,145,26,171,14,103,131,98,236,122,182,211,66,15,122,93,136,184,199,71,22,57,231,91,248,162,17,183]
}
}
]
},
[
0
]
]
}
}
主な要素の値
header.number: 4
header.previous_hash: 8b0cbe2c5571022378ac28a49041265bff43dd7c78c4b9b982a8dc64f40d91e4
data.data[n].payload.header.channel_header.timestamp: 2019-03-28T14:36:48.137Z
data.data[n].payload.header.channel_header.tx_id: 2dad951eaee76f886d8faa41fb1cac827890e7a3bab5e047794f5627539593f6
data.data[n].payload.header.channel_header.typeString: ENDORSER_TRANSACTION
data.data[n].payload.header.signature_header.creator.Mspid: Org1MSP
data.data[n].payload.header.signature_header.creator.IdBytes: ./fabric-client-kv-org1/Jim の identity
data.data[n].payload.data.actions[0].header.creator.Mspid: Org1MSP
data.data[n].payload.data.actions[0].header.creator.IdBytes: ./fabric-client-kv-org1/Jim の identity
data.data[n].payload.data.actions[0].payload.chaincode_proposal_payload.input.chaincode_spec.input.args
data.data[n].payload.data.actions[0].payload.action.proposal_response_payload.extension.results.ns_rwset[1].namespace: mycc
data.data[n].payload.data.actions[0].payload.action.proposal_response_payload.extension.results.ns_rwset[1].rwset.reads: [{"key": "a", "version": {"block_num": "3","tx_num": "0"}}, {"key": "b", "version": {"block_num": "3","tx_num": "0"}}],
data.data[n].payload.data.actions[0].payload.action.proposal_response_payload.extension.results.ns_rwset[1].rwset.range_queries_info: []
data.data[n].payload.data.actions[0].payload.action.proposal_response_payload.extension.results.ns_rwset[1].rwset.writes: [{"key": "a","is_delete": false,"value": "90"},{"key": "b","is_delete": false,"value": "210"}],
data.data[n].payload.data.actions[0].payload.action.endorsements[0].endorser.Mspid: Org1MSP
data.data[n].payload.data.actions[0].payload.action.endorsements[0].endorser.IdBytes: ./artifacts/channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/signcerts/peer0.org1.example.com-cert.pem を参照
data.data[n].payload.data.actions[0].payload.action.endorsements[1].endorser.Mspid: Org2MSP
data.data[n].payload.data.actions[0].payload.action.endorsements[1].endorser.IdBytes: ./artifacts/channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/signcerts/peer0.org2.example.com-cert.pem を参照
metadata.metadata[0].signatures[0].signature_header.creator.Mspid: OrdererMSP
metadata.metadata[0].signatures[0].signature_header.creator.IdBytes: ./artifacts/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/signcerts/orderer.example.com-cert.pem を参照
metadata.metadata[1] は metadata.metadata[0]とほぼ同じ。用途不明
metadata.metadata[2]: 0(処理結果) を参照
ポチったのは誰だ?
data.data[n].payload.data.actions[0].header.creator.IdBytes は、証明書の記載になっている。
この証明書は fabric-client-kv-org1/Jim に記載されている。 つまり、
####『記憶にございません』と言っても通用しない
※1 コメント参照
何をしたんだ?
data.data[n].payload.data.actions[0].payload.chaincode_proposal_payload.input.chaincode_spec.input.args は、呼び出した関数の引数になっている。
(byte配列は、new Buffer(byte_array, 'base64').toString('utf8')
で文字列に変換できる)
この例では、move,a,b,10 を引数にinvokeしたことが分かる。つまり、
####『参照しただけですぅ』と言っても通用しない
誰が何を実行したかを記録し、改竄できない。それが
【ブロックチェーン】
previous_hash で前のブロックの情報を持っているので、間にブロックを挿入することもできない。
hyperledgerはコンセンサス方式なので51%ルールも通用しない。
改竄は不可能といってよいが、DBは改竄可能だ。
といっても次に書き込みされたとき上書きされる。
トランザクションを管理するデータなど、重要な要素はいくつかあるが、今回はここまで。