返回

基于hyperledger Fabric的学历征信系统(六)

写在前面

基于Hyperledger Fabric 使用fabric-sdk-go实现的一个征信应用

原项目使用的fabric版本为1.x,重新构建原项目的fabric网络基础架构和sdk配置为2.x版本,项目地址:GitHub

结构

  • chaincode
    • vendor:依赖包
    • edu.go:链码(智能合约)
  • fixturesfabric网络的所有基础配置文件
  • img:存放前端的图片
  • sdkInitsdk核心代码
  • service:服务端代码,封装了合约接口的调用
    • eduService.go:调用链码的关键所在
      • SaveEdu函数:将入参edu序列化后调用官方提供的用于调用链码(智能合约)的API:channel.Request,调用合约中的addEdu方法,将序列化后的edu作为入参传入addEdu函数
  • web:后端经典MVC结构
    • controller:前端传入信息后封装到edu结构体中,将其作为入参,调用上面提到的SaveEdu函数上链
    • webServer:路由信息

启动

  1. 设置GOPATH/root/go,拉取项目:
1
export GOPATH=/root/go && cd $GOPATH/src && git clone https://github.com/sxguan/education.git
  1. 添加依赖:
1
cd education && go mod tidy
  1. 通过脚本文件启动项目:
1
./clean_docker.sh

  1. 打开浏览器,访问127.0.0.1:9000

BUG1

1
2
>> 开始创建通道......
>> Create channel and join error: Create channel error: error should be nil for SaveChannel of orgchannel: create channel failed: create channel failed: SendEnvelope failed: calling orderer 'orderer.example.com:7050' failed: Orderer Client Status Code: (2) CONNECTION_FAILED. Description: dialing connection on target [orderer.example.com:7050]: connection is in TRANSIENT_FAILURE

解决:Clash切换为Direct

BUG2

1
2
>> 调用智能合约初始化方法......
>> create chaincode lifecycle error: %v initCC error: Failed to init: Transaction processing for endorser [peer0.org1.example.com:7051]: Chaincode status Code: (500) UNKNOWN. Description: error in simulation: failed to execute transaction 8ac60af2d106f3e126274b0275633f747115b6d53010658c3a76bd35aff9e197: could not launch chaincode simplecc_1.0.0:7e4ccb72350a42e53e668f71c8973a73f90b08b1c642e7ed1287971569cf0abd: chaincode registration failed: container exited with 0

解决:修改docker-compose.yamlCORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=fixtures_test

BUG3

1
Web服务启动失败: listen tcp :9000: bind: address already in use

解决:Linux 中 lsof 命令的使用 (wangyi.one)

Built with Hugo
Theme Stack designed by Jimmy