参照
https://hyperledger-fabric-cn.readthedocs.io/zh/1.2.0_zh-cn/private_data_tutorial.html
https://hyperledger-fabric.readthedocs.io/en/release-1.3/private-data-arch.html#using-indexes-with-collections
项目 | Value |
---|---|
name | 集合名称 |
policy | 定义允许持久保存集合数据的组织peer,还有背书策略 |
requiredPeerCount | 作为背书的一个条件,私有数据被分发后,得到私有数据的peer数量。通常不建议设置为0,如果设置为0,当前节点不好用的话,数据没有在其他节点存储,会导致数据丢失。达不到规定的数量时,会向客户端返回错误。 |
maxPeerCount | 一种冗余的做法,允许有多少节点保存私有数据。 |
blockToLive | 以块为单位,存储这些私有数据的时间 |
读取存储私有数据
chaincode 方法 | chaincode api | 用处 |
---|---|---|
readMarble | GetPrivateData | 用来查询[name, color, size and owner]这几个值 |
readMarblePrivateDetails | GetPrivateData | 用来查询[price] |
initMarble | PutPrivateData | 写私有数据 |
transferMarble | PutPrivateData | 写私有数据 |
delete | DelPrivateData | 删除私有数据 |
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n marblesp -v 1.0 -c '{"Args":["init"]}' -P "OR('Org1MSP.member','Org2MSP.member')" --collections-config $GOPATH/src/github.com/chaincode/marbles02_private/collections_config.json
peer chaincode invoke -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n marblesp -c '{"Args":["initMarble","marble1","blue","35","tom","99"]}'
命令
peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarble","marble1"]}'
结果
{"color":"blue","docType":"marble","name":"marble1","owner":"tom","size":35}
命令
peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}'
结果
{"docType":"marblePrivateDetails","name":"marble1","price":99}
命令
peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarble","marble1"]}'
结果
{"docType":"marble","name":"marble1","color":"blue","size":35,"owner":"tom"}
命令
peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}'
{"Error":"Failed to get private details for marble1: GET_STATE failed:
transaction ID: b04adebbf165ddc90b4ab897171e1daa7d360079ac18e65fa15d84ddfebfae90:
Private data matching public hash version is not available. Public hash
version = &version.Height{BlockNum:0x6, TxNum:0x0}, Private data version =
(*version.Height)(nil)"}"
Error: endorsement failure during query. response: status:500
message:"{\"Error\":\"Marble private details does not exist: marble1\"}"