1 Star 4 Fork 4

TrueTechLabs / fabric-trace

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

项目演示站点: http://realcool.top:9090/

与B站官方合作,本项目代码讲解与二次开发课程已发布,限时特价至4月30日,支持试看: B站:Fabric V2.5通用溯源项目讲解与二次开发课程,购买课程将赠送《Fabric项目学习笔记》中所有与本项目相关的资料。购买课程与订阅专栏均配套社群,方便交流与答疑。

Fabric V2.5通用溯源课程活动:【腾讯文档】:提交源码仓库地址/PPT/视频获得返现50-300元

如果需要远程搭建服务或商业合作请填写收集表:【腾讯文档】本项目搭建服务或商务合作意向收集

【远程搭建】淘宝搜索店铺【TrueTechLabs技术支持】或使用淘宝APP扫码直达商品页面: 淘宝APP扫码直达商品

如果项目有帮助请给项目点上Star,我们将十分感谢! 欢迎加入TrueTechLabs Fabric学习交流QQ群:776873343

群内可免费阅读此项目的区块链部分、应用后端部分的代码说明文档。

TrueTechLabs Fabric学习交流QQ群:776873343

一、项目介绍

基于区块链Hyperledger Fabric V2.5的农产品溯源/商品/通用溯源应用模板,部署简单,附压测工具tape、区块链浏览器,文档详细。可以快速使用本系统搭建自己的溯源系统,帮助想法快速落地。采用的技术栈:Fabric V2.5、Gin、Vue.js、Mysql。

项目系统架构图 多类型用户注册 农产品上链 农产品溯源 区块链浏览器可视化

项目地址:

Github: https://github.com/TrueTechLabs/fabric-trace

Gitee: https://gitee.com/real__cool/fabric-trace

搭建视频地址:

https://www.bilibili.com/video/BV1Ar421H7TK

附完整一刀未剪的搭建视频:

演示使用临时服务器,建议使按年付费价格划算一些,具体购买方式参见下方搭建步骤。 https://www.bilibili.com/video/BV1mF4m1P7Go

项目文档地址(部分内容需要订阅专栏):

https://blog.csdn.net/qq_41575489/category_12075943.html

项目代码讲解与修改前端课程:

B站:Fabric V2.5通用溯源项目讲解与二次开发课程

二、版权声明

本项目基于Apache License 2.0开源协议,在个人的科研、学习范围内可以自由使用,请附上项目链接。如有商业需求或合作需求,请填写收集表:【腾讯文档】本项目搭建服务或商务合作意向收集 。如果您不同意本声明请不要使用本项目。

三、项目特点

本项目采用Hyperledger Fabric V2.5,属于目前最新的Fabric版本,具有更好的性能和稳定性,调用链码使用fabric-gateway模式,是当前版本的推荐方式。内置了tape压测工具,可以方便的对区块链网络进行压测;内置了区块链浏览器,可以方便地查询交易信息。 项目结构清晰,代码注释详细,方便二次开发。结合了mysql实现账户注册登录功能,更符合真实业务场景。

四、项目背景

区块链技术的出现,为溯源系统的建设提供了新的思路。区块链技术的不可篡改性、去中心化、可追溯等特点,使得区块链技术成为溯源系统的理想选择。本项目基于Hyperledger Fabric V2.5,实现了一个农产品溯源系统。 在本区块链系统中,有5个内置的角色:种植户、工厂、驾驶员、商店、消费者。其中种植户、工厂、驾驶员、商店可以将信息上链,消费者有信息溯源权限。上述可以上链信息的角色各可以输入5个农产品的属性,方便二次开发。本项目的目标是作为Fabric V2.5下的一个通用溯源模板。

五、搭建步骤

如果部分内容与视频不一致请以本文档为准

强烈推荐按照步骤使用云服务器搭建本系统,虚拟机的问题较多。点击此链接直达新人活动页面:https://curl.qcloud.com/Sjy0zKjy 点击首单特惠,购买2核4G或以上的服务器,199/年(价格经常会调整),如果后续准备做程序开发可以用新用户优惠买三年的,安装Ubuntu20.04系统。

严格按照以下步骤操作,以下步骤已经经过上百人次的验证,如果遇到报错请仔细检查是否遗漏某个步骤:

  1. 安装docker

    #下载docker 
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 
    #添加当前用户到docker用户组 
    sudo usermod -aG docker $USER 
    newgrp docker 
    #配置docker镜像加速
    sudo mkdir -p /etc/docker
    
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://punulfd2.mirror.aliyuncs.com"]
    }
    EOF
    
    #重启docker 
    sudo systemctl daemon-reload
    sudo systemctl restart docker
  2. 安装开发使用的go、node、jq

    #下载二进制包
    wget https://golang.google.cn/dl/go1.19.linux-amd64.tar.gz
    #将下载的二进制包解压至 /usr/local目录
    sudo tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
    mkdir $HOME/go
    #将以下内容添加至环境变量 ~/.bashrc
    export GOPATH=$HOME/go
    export GOROOT=/usr/local/go
    export PATH=$GOROOT/bin:$PATH
    export PATH=$GOPATH/bin:$PATH
    #更新环境变量
    source  ~/.bashrc 
    #设置代理
    go env -w GO111MODULE=on
    go env -w GOPROXY=https://goproxy.cn,direct
    
    #下载nvm安装脚本
    wget https://gitee.com/real__cool/fabric_install/raw/main/nvminstall.sh
    #安装nvm;屏幕输出内容添加环境变量
    chmod +x nvminstall.sh
    ./nvminstall.sh
    # 将环境变量写入.bashrc
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    # 更新环境变量
    source  ~/.bashrc
    # 安装node16
    nvm install 16
    #换源
    npm config set registry https://registry.npmmirror.com
    
    #安装jq 
    sudo apt install jq
  3. 克隆本项目

    git clone https://gitee.com/real__cool/fabric-trace
  4. 启动区块链部分。在fabric-trace/blockchain/network目录下:

    # 仅在首次使用执行:下载Fabric Docker镜像。如果拉取速度过慢或失败请检查是否完成docker换源,或者更换一个其他的镜像源再试。
    ./install-fabric.sh -f 2.5.6 d 
    # 启动区块链网络
    ./start.sh

    如果在启动区块链网络时遇到报错可以尝试:

    # 执行清理所有的容器指令:
    docker rm -f $(docker ps -aq)

    然后再重新启动区块链网络

  5. 启动后端 在fabric-trace/application/backend目录下: 执行: go run main.go

  6. 修改后端IP,将以下文件中的IP:119.45.247.29,换成自己云服务的IP。

    fabric-trace/application/web/.env.development
    fabric-trace/application/web/src/router/index.js
  7. 新开一个窗口,启动前端 在fabric-trace/application/web目录下: 执行:

    # 仅在首次运行执行:安装依赖
    npm install 
    # 启动前端
    npm run dev
  8. 在腾讯云轻量应用服务器防火墙页面,放行TCP端口8080,9090,9528 防火墙配置

  9. 在浏览器中打开:http://云服务器IP:9528 即可看到前端页面。

  10. 使用tape对项目进行压力测试 根据blockchain/chaincode/chaincode/smartcontract.go中的合约函数的签名,编写压测的参数,需要修改的内容是tape目录下的yaml文件中的args。args第一个参数是函数名,后面的参数是函数的参数。例如:

    args:
    # 函数名
    - RegisterUser
    # userID string
    - 1
    #userType string
    - randomString8
    # realInfoHash string
    - randomString8

执行./tape --config config_register.yaml -n 1即可完成用户1的注册,然后可以对农产品上链操作与获取用户信息函数进行压测。更多的压测案例可以根据合约函数的签名进行修改。 附农产品上链操作与获取用户信息函数进行压测操作指令:

./tape --config config_invoke.yaml -n 100
./tape --config config_query.yaml -n 100

六、关闭项目与重新运行步骤

关闭项目:
  1. 前端(npm run dev界面)与后端(go run main.go界面:

    使用键盘组合键:ctrl+c

  2. 区块链部分:

    fabric-trace/blockchain/network目录./stop.sh

启动项目:
  1. fabric-trace/blockchain/network目录 ./start.sh 如果遇到报错可以执行以下命令后再试: 执行清理所有的容器指令: docker rm -f $(docker ps -aq)
  2. fabric-trace/application/backend目录下: 执行: go run main.go
  3. fabric-trace/application/web目录下: 执行: npm run dev
生产模式启动项目(后台运行,访问速度更快)
  1. fabric-trace/blockchain/network目录 ./start.sh 如果遇到报错可以执行以下命令后再试: 执行清理所有的容器指令: docker rm -f $(docker ps -aq)

  2. fabric-trace/application目录下: 执行: ./start.sh

    注意:此方式部署项目会在后台运行,如果后续遇到端口号占用可以尝试关闭占用9090端口号的进程,可以参考: 解决端口占用 bind:address already in use

七、本项目相关的后续计划:

  1. 本项目目前不够完美,将持续维护,欢迎给项目点亮Star与B站三连,非常感谢!本项目的区块链部分、前后端的说明文档以及简易的二次开发流程已在《Fabric项目学习笔记 》专栏发布,欢迎订阅支持!
  2. 支持Docker方式部署,简化部署步骤
  3. 改善农产品信息上链过程,需要按照角色顺序上链

八、目前已知存在的问题:

  1. 区块链浏览器有时候会出现无法访问的情况,可以尝试重启浏览器容器。

如果不能按照步骤运行项目

上述部署步骤已经上百人次验证并顺利完成,如果您通过上述步骤未能运行项目,请检查环境是否与本项目要求的一致,任何修改或遗漏步骤都可能引起项目不能正常运行,请严格按照视频与文章步骤再次尝试,常见问题与解决方案列表参考。若还是有问题请在B站项目搭建视频评论区查看其他人的留言是否有相同的问题,如果还是没有解决请在视频下评论问题并附上第一个遇到的报错,如果问题不够明确,我们也很难帮助到您。购买B站:Fabric V2.5通用溯源项目讲解与二次开发课程或订阅《Fabric项目学习笔记》可以加入配套社群,方便本项目交流与答疑。

Star History

Star History Chart

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

基于区块链Hyperledger Fabric V2.5 的农产品/商品等的通用溯源系统,部署简单,附压测工具、区块链浏览器,文档详细。 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/real__cool/fabric-trace.git
git@gitee.com:real__cool/fabric-trace.git
real__cool
fabric-trace
fabric-trace
main

搜索帮助