In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to configure fabric private data datasets". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Hyperledger Fabric private data is a new feature introduced in version 1.2. Fabric private data uses side-branch database (SideDB) to store private data between several channel members, thus providing a more flexible data protection mechanism on top of the channel. This article describes how to use fabric private data in chain code development.
If you want to quickly grasp the development of hyperledger fabric blockchain, Huizhi.com 's online interactive practical course is recommended:
Detailed explanation of Hyperledger Fabric Block chain Development
Detailed explanation of Hyperledger Fabric java Block chain Development
Fabric private data use case
We use the classic fabcar case in Hyperledger Fabric to show how to use a private dataset. The initLedger function will create 10 new cars in our dataset. All of these vehicles can be viewed by anyone on the network. Now let's create a private database, and this data will only be shared with another member garage we hold.
Fabric private data dataset configuration
We first need a dataset configuration file, collections_config.json, which contains the private dataset name and access policy. Access policy is similar to endorsement policy, which allows us to use existing policy logic, such as OR, AND, and so on.
[{"name": "carCollection", "policy": "OR ('Org1MSP.member','Org2MSP.member')", "requiredPeerCount": 0, "maxPeerCount": 3, "blockToLive": 1000000}] modify the chain code to support fabric private data
Here is the original createCar function:
Async createCar (stubHelper: StubHelper, args: string []) {const verifiedArgs = await Helpers.checkArgs (args [0], Yup.object () .shape ({key: Yup.string (). Required (), make: Yup.string (). Required (), model: Yup.string (). Required (), color: Yup.string (). Required () Owner: Yup.string () .required (),}) Let car = {docType: 'car', make: verifiedArgs.make, model: verifiedArgs.model, color: verifiedArgs.color, owner: verifiedArgs.owner}; await stubHelper.putState (verifiedArgs.key, car);}
To add data to the private dataset carCollection, we need to specify the target dataset:
Await stubHelper.putState (verifiedArgs.key, car, {privateCollection: 'carCollection'})
Next, to query the vehicle, we also need to specify the target private dataset:
Async queryPrivateCar (stubHelper: StubHelper, args: string []) {const verifiedArgs = await Helpers.checkArgs (args [0], Yup.object () .shape ({key: Yup.string (). Required (),})); const car = await stubHelper.getStateAsObject (verifiedArgs.key, {privateCollection: 'carCollection'}); if (! car) {throw new NotFoundError (' Car does not exist') } return car;}
Similarly, for both delete and update operations, you need to specify the target private dataset to operate on.
This is the end of "how to configure fabric private data datasets". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.