Article directory
Summary
The chain code writing and back-end interface writing of breeding organizations, farmers organizations, government functions, and ordinary users have been completed. The first three organizations can add data and query data, and support rich query, and can also perform login and registration operations. Ordinary users can only perform query and trace operations. The overall Api routing group is as shown in the figure below:
But there are still problems. When opening 7 blockchain node containers, after initializing the chain code, two blockchain node containers will be randomly down specific container), so I removed two containers and only opened 5 blockchain node containers. At this time, no container was down anymore, but occasionally the node container disconnected from the client created by go sdk Reconnected again, and when sending transactions, the speed was slow and sometimes failed. According to speculation, it may be caused by insufficient performance of the virtual machine. In the second chapter, I will introduce and test the interfaces of each organization, and only take two organizations as examples, because the others are the same specification.
1. Introduction to the functions of each module of the program
1.1 goSdk0_1
- Middleware to solve Cors cross-domain problems
- go sdk creates a configuration file for the client to operate the blockchain
- Fabric Info, the file that stores the model structure
- main function file
- The file of the routing group execution function mainly calls the function in the start.go file to realize the operation logic.
- Documentation for the underlying functions. Because the functions here can be reused, they are called bottom functions.
1.2 org_chaincode
chaincode file
- The core of main.go
is the Invoke function, which executes a specific chaincode function according to fun and passes in the parameter args.
All chaincode functions of controller.go are here
The structure that modle.go saves data.
2. Detailed introduction of each interface function
2.1 Generate (breeding organization)
2.1.1 Add data
Request address: 127.0.0.1:6060/generate/addData
Request method: POST
Function: Add data. If the addition is successful, the err returned will be empty (as shown in the figure below), otherwise an error type will be returned.
2.1.2 Query data (the latest world status of a certain chicken)
Request address: 127.0.0.1:6060/generate/queryData
Request method: GET
Function: Specify the ID and Batch to query the latest status of the specified chicken.
2.1.3 Traceability query
Request address: 127.0.0.1:6060/generate/queryHistoryData
Request method: GET
Function: Traceability function, query all changes of the specified chicken.
2.1.4 Summary query
Request address: 127.0.0.1:6060/generate/queryDataByStateBatch
Request method: GET
Function: Query all live chickens in the batch specified by the current organization.
2.1.5 Registration
Request address: 127.0.0.1:6060/generate/registry
Request method: POST
Function: The current organization user registers, and if the registration is successful, the information of the registered user will be returned.
2.1.6 Login
Request address: 127.0.0.1:6060/generate/login
Request method: GET
Function: Enter the user and password to log in. If the login is successful, the identity information of the account will be returned, otherwise an error will be returned.
2.2 Breed (farmer organization)
2.2.1 Add data
Request address: 127.0.0.1:6060/breed/addData
Request method: POST
Function: Add data. If the addition is successful, the err returned will be empty (as shown in the figure below), otherwise an error type will be returned.
2.2.2 Query data (the latest world status of a certain chicken)
Request address: 127.0.0.1:6060/breed/queryData
Request method: GET
Function: Specify the ID and Batch to query the latest status of the specified chicken.
2.2.3 Traceability query
Request address: 127.0.0.1:6060/breed/queryHistoryData
Request method: GET
Function: Traceability function, query all changes of the specified chicken.
2.2.4 Summary query
Request address: 127.0.0.1:6060/breed/queryDataByStateBatch
Request method: GET
Function: Query all live chickens in the batch specified by the current organization.
2.2.5 Registration
Request address: 127.0.0.1:6060/breed/registry
Request method: POST
Function: The current organization user registers, and if the registration is successful, the information of the registered user will be returned.
2.2.6 Login
Request address: 127.0.0.1:6060/breed/login
Request method: GET
Function: Enter the user and password to log in. If the login is successful, the identity information of the account will be returned, otherwise an error will be returned.