基于Hyperledger Fabric
本项目实现茶叶生产、加工、运输全流程溯源
chaincode 由@DevilExileSu所编写
在此之前请确保已安装Hyperledger Fabric(本项目基于Hyperledger Fabric v1.0)
库版本:
npm 5.6.0 (建议大于或等于此版本)
node.js v8.11.3 (建议大于或等于此版本)
angularjs 1.4.3
如有Bug,欢迎提出
Step 1:
git clone git://github.com/KissFire-MT/fabric-tea.git
进入source-app目录下 cd fabric-tea/source-app
Step 2:
npm install
//安装时速度经常自杀,建议使用cnpm
cnpm install
Step 3:
./startFabric.sh
若遇到权限问题执行chmod a+x startFabric.sh
若仍有问题进入basic-network文件夹下执行 chmod a+x start.sh
解决ERROR: network net_basic has active endpoints
service docker restart
Step 4:
在 fabcar/registerUser.js 文件修改第56行:
return fabric_ca_client.register({enrollmentID: 'user1', affiliation: 'org1.department1',role: 'client'}, admin_user);
node registerAdmin.js
node registerUser.js
node server.js
访问http://localhost:8000
由于没有初始化信息,因此需要先提交表单信息才可以查询出信息
在填写表单信息时,没有做过多的处理,因此每个选项都要尽量填写(配料的表单可以不填写完)
配料及食品信息对于同一个Id只能添加一次,中转信息可以添加多次
获取茶叶信息
http://localhost:8000/source/:id
{"FoodName":"Apple","FoodSpec":"123456","FoodMFGDate":"2018-8-24","FoodEXPDate":"10day","FoodLOT":"123","FoodQSID":"456","FoodMFRSName":"lalala","FoodProPrice":"2","FoodProPlace":"zhengzhou"}
获取茶叶配料信息
http://localhost:8000/part/:id
[{"IngID":"1","IngName":"a"},{"IngID":"2","IngName":"b"},{"IngID":"3","IngName":"c"},{"IngID":"4","IngName":"d"},{"IngID":"5","IngName":"e"}]
获取茶叶(运输)信息
http://localhost:8000/transit/:id
[{"LogDepartureTm":"14:20","LogArrivalTm":"16:40","LogMission":"Store","LogDeparturePl":"zhengzhou","LogDest":"wuhan","LogToSeller":"lalala","LogStorageTm":"1day","LogMOT":"truck","LogCopName":"shunfeng","LogCost":"10"},{"LogDepartureTm":"16:50","LogArrivalTm":"18:50","LogMission":"Store","LogDeparturePl":"wuhan","LogDest":"guangzhou","LogToSeller":"lalala","LogStorageTm":"1day","LogMOT":"truck","LogCopName":"shunfeng","LogCost":"10"}]
仅需修改server.js文件最后几行代码
var port = process.env.PORT || 3389; //端口修改为服务器的安全组端口
app.listen(port, '0.0.0.0', function(){
console.log("Live on port: " + port);
});
source-app
server.js 启动
routes.js 定义路由
controller.js 路由
chaincode
source-app
source-app.go chaincode
一般来说,路由会在routes.js文件中定义,但是这样不方便路由复用,因此分为两个脚本
Writing Your First Application
除了chaincode,其余大部分.js文件都是参照以上参考链接所写,因此注释为英文