In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Go language how to use fabric to achieve blockchain development, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Set up the 1.go language environment, install go, and configure gopath and goroot after installation
The directory under gopath should have three layers:
Include your own projects and introduced dependency packages under src
two。 Install mingw-w64, download address: https://sourceforge.net/projects/mingw-w64/
Resolve exec: "gcc": executable file not found in% PATH% exception
Adapt your computer configuration during installation
After installation, configure the system path. After a successful installation, enter gcc-v for cmd as follows, indicating success:
3. Introduce fabric package, download address: https://github.com/hyperledger/fabric
Just put it in the src\ github.com\ hyperledger\ fabric directory of gopath.
Download https://github.com/miekg/pkcs11
4. Open the development of smart contracts:
..\..\ vendor\ github.com\ miekg\ pkcs11\ pkcs11.go:26:10: fatal error: ltdl.h: No such file or directory
# include
^ ~
Compilation terminated.
Just execute go get-u-- tags nopkcs11
Pay attention to the problem of git project permissions. You should have pull & push permissions at the same time
5. Fabric-based msp (permissions):
The implementation of msp is CA,fabric, and the implementation is fabric-ca.
Premise go version 1.10 or above, gopath configured, libtool and libtdhl-dev toolkits installed
Install number fabric-ca first, install command: go get-u github.com/hyperledger/fabric-ca/cmd/...
Then start the server of facric-ca-server, and command: fabric-ca-server start-b admin:adminpw-- cacount 2
Generated certificates for ca1 and ca2
The generated certificate is ca-cert.pem in the ca1 and ca2 directories
Check the contents of the certificate and enter the ca1 directory:
Command: openssl x509-in ca-cert.pem-inform pem-noout-text
The certificate contains applicant public key information, signature algorithm information, applicant basic information and so on.
Enter the sqlite database to view the information: install the number sqlite first and configure the number path first.
Command: sqlite3 fabric-ca-server.db
You can see these tables, where users currently has only the nodes that are booted at startup:
Certificates has no record of issuing any certificates.
View the user information as follows:
Boot node at login startup:
Client:
The server shows:
After logging in successfully, check the certificate information under ca-server, which has been recorded in the sqlite database, as shown below:
Then use ca-client to register a node, which is the process of registering and registering the peer,user role in facric
Registration command: fabric-ca-client register-- id.name admin2-- id.type user-- id.affiliation org1.department1-- id.attrs' hf.Revoker=true,foo=bar'
It should be noted that:
1.-- the id.type parameter must be one of the hf.Registrar.Roles attribute values in the server configuration file
Open the configuration file of fabric-ca-server: the types that can be registered are client,user,peer,validator and auditor
2.-- the attribute id.affiliation indicates that the dependency parameter of the registered object must belong to the preconfigured organization attribute.
After adding, execute the following command: fabric-ca-client register-- id.name admin2-- id.type user-- id.affiliation org1.department1-- id.attrs' hf.Revoker=true,foo=bar'
Note that you need to remember the generated password, which you need to use when you log in later.
Then you can log in to the following admin2 node and view the certificate content on the server side:
Login command: fabric-ca-client enroll-u http://admin2:ItpaeebVWAuY@localhost:7054-M $FABRIC_CA_CLIENT_HOME/msp
Note that the information is registered, and then open the user of the ca-server sqlite, and you can see that there is one more client certificate information:
You can see the admin of a client node and the admin2 of a user node, where admin is intermediateCA. Open the certificates table to view the certificate information of admin2:
When the node is about to expire, you need to re-register the node. Register command: fabric-ca-client reenroll
Enrollment is to re-send a signed certificate request to obtain a new digital certificate.
If you look at the server, you can see that the time at which the certificate was issued is different, as follows:
Logout certificate command: fabric-ca-client revoke-e-r
The parameters for reason can be as follows:
1. Keycompromise
2. Cacompromise
3. Affiliationchange
4. Superseded
5. Cessationofoperation
6. Certificatehold
7. Removefromcrl
8. Privilegewithdrawn
9. Aacompromise
10. Unspecified
Let's log out the node admin2 that we just registered and execute the command: fabric-ca-client revoke-e admin2
Then look at the certificate information of the server of sqlite, and you can see that it has become revoked and has been logged out.
-similarly, you can create an intermediate CA. Command: fabric-ca-server start-b admin1:adminpw1-u http://admin:adminpw@localhost:7054
Restart a CA server as the intermediate CA under the boot node CA server
Ca-chain.pem can view the intermediate CA that you just registered
If you agree to add nodes, you can register first and then enroll
When a user has permissions on two chains, cross-authentication is required (in essence, certificate information on another CA chain is obtained through the restful interface)
Cross-authentication command: fabric-ca-client getcacert-u http://localhost:7055-M $FABRIC_CA_CLIENT_HOME/msp
With regard to the chain code, fabric provides a permission-based extension, that is, the msp module, which essentially generates certificates for the server and the client, and the certificate serves as the identity of the permission. In the chain code, we can obtain this identity through the following ways:
Id, err: = cid.GetID (stub)
The results are as follows:
EDUwOTo6Q049YWRtaW4sT1U9RmFicmljLE89S7777777777777777779Tm9ydGggQ2Fyb2xpbmEsQz1VUzo6Q049ZXhhbXBsZS5jb20sT1U9V88888888850ZXJuZXQgV2lkZ2V0cyxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVAA
Of course, it can also be passed.
Creator,err: = stub.GetCreator ()
The certificate obtained is as follows:
SampleOrg customers-BEGIN CERTIFICATE-
MIICXTCCAgSgAwIBAgIUeLy6uQnq8wwyElU/jCKRYz3tJiQwCgYIKoZIzj0EAwIw
ETELssssssVkZ2VyMQ8wDQYDVQQLEwZGYWJyaWMxDjAMBgNV
BAMs's's's'sFkwyyyyyyQcDQgAEFq/90YMuH4tWugHa
OyZtt4MbxxxxxxW5pbHMtTWFjQm9vay1Qcm8ubG9jYWwwCgYI
KoZIzj0EAwIDRwAwRAIgCoXaCdU8ZiRKkai0QiXJM/GL5fysLnmG2oZ6XOIdwtsC
IEmCsI8Mhrvx1doTbEOm7kmIrhQwUVDBNXCWX1t3kJVN
-END CERTIFICATE-
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.