区块链 创建Hyperledger Fabric区块链网络

约定不等于承诺〃 2022-04-08 12:46 616阅读 0赞

fabric-samples-1.4.0 开发搭建

一、环境安装前准备:

(1)首先安装基本工具

  1. yum install git
  2. yum install curl
  3. yum -y install epel-release
  4. yum install python-pip
  5. pip install --upgrade pip

(2)安装Docker,安装好后可以确认Docker和Docker Compose的版本:

  1. docker --version
  2. docker-compose --version

(2)安装Go语言

  1. # go 环境变量
  2. export PATH=$PATH:/usr/local/go/bin
  3. export GOROOT=/usr/local/go
  4. export GOPATH=$HOME/go
  5. export PATH=$PATH:$HOME/go/bin
  6. # go 版本
  7. go version

(3)安装Node.js

  1. yum install gcc gcc-c++
  2. gcc -v

4.8.5版本过低,若已为最新版请跳过至步骤,升级gcc,前往http://ftp.gnu.org/gnu/gcc/下载你想要的版本

  1. wget http://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
  2. tar -C /usr/local -xzf gcc-8.2.0.tar.gz
  3. cd /usr/local/gcc-8.2.0
  4. ./contrib/download_prerequisites
  5. mkdir build
  6. cd build
  7. ../configure -enable-checking=release -enable-languages=c,c++ disable-multilib
  8. yum groupinstall "Development Tools"
  9. make #需要很长时间
  10. make install
  11. reboot #重启

(4)继续安装nodejs

  1. node -v

(5)安装 npm

  1. npm install npm -g
  2. npm -v

二、 下载fabric-samples源码

(1)git clone https://github.com/hyperledger/fabric-samples.git
(2)目前官网默认是 1.3 版本需要修改配置文件

注意:需要安装二进制可执行文件 和配置文件,可以提前下载好二进制文件上传到
/root/go/src/github.com/hyperledger/fabric-samples 下
下载地址:https://download.csdn.net/download/liruizi/10849641

  1. #进入 scripts 目录
  2. /root/go/src/github.com/hyperledger/fabric-samples/scripts
  3. [root@localhost scripts]# vi bootstrap.sh

在这里插入图片描述

TLS(安全传输层协议) 设置为false 为了测试SDK

  1. root@fabric3:/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/base# ls
  2. docker-compose-base.yaml peer-base.yaml
  3. 目录下的两个配置文件中TLS_ENABLEDfalse
  4. /github.com/hyperledger/fabric-samples/first-network#
  5. docker-compose-cli.yaml文件中TLS_ENABLEDfalse

三、想要现在运行吗

fabric提供一个完全注释的脚本byfn.sh,利用这些Docker镜像可以快速引导一个由4个代表2个不同组织的peer节点以及一个排序服务节点的Hyperledger fabric网络。它还将启动一个容器来运行一个将peer节点加入channel、部署实例化链码服务以及驱动已经部署的链码执行交易的脚本。

以下是该byfn.sh脚本的帮助文档:
  1. ./byfn.sh -h
  2. Usage:
  3. byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>]
  4. byfn.sh -h|--help (print this message)
  5. -m <mode> - one of 'up', 'down', 'restart' or 'generate'
  6. - 'up' - bring up the network with docker-compose up
  7. - 'down' - bring up the network with docker-compose up
  8. - 'restart' - bring up the network with docker-compose up
  9. - 'generate' - generate required certificates and genesis block
  10. -c <channel name> - config name to use (defaults to "mychannel")
  11. -t <timeout> - CLI timeout duration in microseconds (defaults to 10000)
  12. Typically, one would first generate the required certificates and
  13. genesis block, then bring up the network. e.g.:
  14. byfn.sh -m generate -c <channelname>
  15. byfn.sh -m up -c <channelname>

如果你选择不提供channel名称,则脚本将使用默认名称mychannel。CLI超时参数(用-t标志指定)是一个可选值;如果你选择不设置它,那么CLI容器将会在脚本执行完之后退出。

生成网络神器

准备好了吗?好吧!执行以下命令。你将会看到会发生什么伴随yes/no命令行提示的简要说明。输入y来执行描述的动作。

  1. ./byfn.sh -m generate
  2. Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
  3. Continue? [Y/n] y
  4. proceeding ...
  5. /root/go/src/github.com/hyperledger/fabric-samples/bin/cryptogen
  6. ##########################################################
  7. ##### Generate certificates using cryptogen tool #########
  8. ##########################################################
  9. + cryptogen generate --config=./crypto-config.yaml
  10. org1.example.com
  11. org2.example.com
  12. + res=0
  13. + set +x
  14. /root/go/src/github.com/hyperledger/fabric-samples/bin/configtxgen
  15. ##########################################################
  16. ######### Generating Orderer Genesis block ##############
  17. ##########################################################
  18. + configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  19. 2018-12-14 09:14:11.119 CST [common.tools.configtxgen] main -> WARN 001 Omitting the channel ID for configtxgen for output operations is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'.
  20. 2018-12-14 09:14:11.119 CST [common.tools.configtxgen] main -> INFO 002 Loading configuration
  21. 2018-12-14 09:14:11.131 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
  22. 2018-12-14 09:14:11.131 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  23. 2018-12-14 09:14:11.145 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 005 orderer type: solo
  24. 2018-12-14 09:14:11.145 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 006 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  25. 2018-12-14 09:14:11.149 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Generating genesis block
  26. 2018-12-14 09:14:11.151 CST [common.tools.configtxgen] doOutputBlock -> INFO 008 Writing genesis block
  27. + res=0
  28. + set +x
  29. #################################################################
  30. ### Generating channel configuration transaction 'channel.tx' ###
  31. #################################################################
  32. + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
  33. 2018-12-14 09:14:11.196 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
  34. 2018-12-14 09:14:11.215 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  35. 2018-12-14 09:14:11.230 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
  36. 2018-12-14 09:14:11.230 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  37. 2018-12-14 09:14:11.231 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
  38. 2018-12-14 09:14:11.232 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
  39. + res=0
  40. + set +x
  41. #################################################################
  42. ####### Generating anchor peer update for Org1MSP ##########
  43. #################################################################
  44. + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
  45. 2018-12-14 09:14:11.277 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
  46. 2018-12-14 09:14:11.293 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  47. 2018-12-14 09:14:11.309 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
  48. 2018-12-14 09:14:11.309 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  49. 2018-12-14 09:14:11.309 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
  50. 2018-12-14 09:14:11.309 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
  51. + res=0
  52. + set +x
  53. #################################################################
  54. ####### Generating anchor peer update for Org2MSP ##########
  55. #################################################################
  56. + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
  57. 2018-12-14 09:14:11.355 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
  58. 2018-12-14 09:14:11.371 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  59. 2018-12-14 09:14:11.387 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
  60. 2018-12-14 09:14:11.387 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/go/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
  61. 2018-12-14 09:14:11.387 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
  62. 2018-12-14 09:14:11.388 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
  63. + res=0
  64. + set +x

第一步生成我们各种网络实体的所有证书和密钥,genesis block用于引导排序服务,以及配置Channel所需要的一组交易配置集合。

启动网络

接下来,你可以使用以下命令来启动整个网络。再试提示你是否继续。回答y:

  1. ./byfn.sh -m up
  2. Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
  3. Continue? [Y/n] y
  4. proceeding ...
  5. LOCAL_VERSION=1.4.0
  6. DOCKER_IMAGE_VERSION=1.4.0-rc1
  7. =================== WARNING ===================
  8. Local fabric binaries and docker images are
  9. out of sync. This may cause problems.
  10. ===============================================
  11. Creating network "net_byfn" with the default driver
  12. Creating volume "net_peer0.org2.example.com" with default driver
  13. Creating volume "net_peer1.org2.example.com" with default driver
  14. Creating volume "net_peer1.org1.example.com" with default driver
  15. Creating volume "net_peer0.org1.example.com" with default driver
  16. Creating volume "net_orderer.example.com" with default driver
  17. Pulling orderer.example.com (hyperledger/fabric-orderer:latest)...
  18. latest: Pulling from hyperledger/fabric-orderer
  19. 3b37166ec614: Already exists
  20. 504facff238f: Already exists
  21. ebbcacd28e10: Already exists
  22. c7fb3351ecad: Already exists
  23. 2e3debadcbf7: Already exists
  24. fc435e46e32e: Already exists
  25. a4922bafdce8: Already exists
  26. 2cb4429027c1: Already exists
  27. 8c2b02bf9e47: Pull complete
  28. 7e18daca12c4: Pull complete
  29. Creating peer0.org1.example.com ... done
  30. Creating peer0.org2.example.com ... done
  31. Creating orderer.example.com ... done
  32. Creating peer1.org1.example.com ... done
  33. Creating peer1.org2.example.com ... done
  34. Creating cli ... done
  35. ____ _____ _ ____ _____
  36. / ___| |_ _| / \ | _ \ |_ _|
  37. \___ \ | | / _ \ | |_) | | |
  38. ___) | | | / ___ \ | _ < | |
  39. |____/ |_| /_/ \_\ |_| \_\ |_|
  40. Build your first network (BYFN) end-to-end test
  41. Channel name : mychannel
  42. Creating channel...
  43. + peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  44. + res=0
  45. + set +x
  46. 2018-12-14 01:14:52.493 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  47. 2018-12-14 01:14:52.513 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  48. 2018-12-14 01:14:52.516 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  49. 2018-12-14 01:14:52.547 UTC [cli.common] readBlock -> INFO 004 Received block: 0
  50. ===================== Channel 'mychannel' created =====================
  51. Having all peers join the channel...
  52. + peer channel join -b mychannel.block
  53. + res=0
  54. + set +x
  55. 2018-12-14 01:14:52.602 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  56. 2018-12-14 01:14:52.616 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  57. 2018-12-14 01:14:52.619 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  58. 2018-12-14 01:14:52.638 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
  59. ===================== peer0.org1 joined channel 'mychannel' =====================
  60. + peer channel join -b mychannel.block
  61. + res=0
  62. + set +x
  63. 2018-12-14 01:14:55.755 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  64. 2018-12-14 01:14:55.768 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  65. 2018-12-14 01:14:55.771 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  66. 2018-12-14 01:14:55.797 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
  67. ===================== peer1.org1 joined channel 'mychannel' =====================
  68. + peer channel join -b mychannel.block
  69. + res=0
  70. + set +x
  71. 2018-12-14 01:14:58.901 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  72. 2018-12-14 01:14:58.914 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  73. 2018-12-14 01:14:58.918 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  74. 2018-12-14 01:14:58.953 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
  75. ===================== peer0.org2 joined channel 'mychannel' =====================
  76. + peer channel join -b mychannel.block
  77. + res=0
  78. + set +x
  79. 2018-12-14 01:15:02.062 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  80. 2018-12-14 01:15:02.075 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  81. 2018-12-14 01:15:02.078 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  82. 2018-12-14 01:15:02.096 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
  83. ===================== peer1.org2 joined channel 'mychannel' =====================
  84. Updating anchor peers for org1...
  85. + peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  86. + res=0
  87. + set +x
  88. 2018-12-14 01:15:05.219 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  89. 2018-12-14 01:15:05.234 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  90. 2018-12-14 01:15:05.237 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  91. 2018-12-14 01:15:05.252 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update
  92. ===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================
  93. Updating anchor peers for org2...
  94. + peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  95. + res=0
  96. + set +x
  97. 2018-12-14 01:15:08.307 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  98. 2018-12-14 01:15:08.321 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  99. 2018-12-14 01:15:08.325 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
  100. 2018-12-14 01:15:08.351 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update
  101. ===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================
  102. Installing chaincode on peer0.org1...
  103. + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
  104. + res=0
  105. + set +x
  106. 2018-12-14 01:15:11.447 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  107. 2018-12-14 01:15:11.468 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  108. 2018-12-14 01:15:11.477 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
  109. 2018-12-14 01:15:11.477 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
  110. 2018-12-14 01:15:12.045 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" >
  111. ===================== Chaincode is installed on peer0.org1 =====================
  112. Install chaincode on peer0.org2...
  113. + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
  114. + res=0
  115. + set +x
  116. 2018-12-14 01:15:12.106 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  117. 2018-12-14 01:15:12.121 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  118. 2018-12-14 01:15:12.130 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
  119. 2018-12-14 01:15:12.130 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
  120. 2018-12-14 01:15:12.345 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" >
  121. ===================== Chaincode is installed on peer0.org2 =====================
  122. Instantiating chaincode on peer0.org2...
  123. + peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
  124. + res=0
  125. + set +x
  126. 2018-12-14 01:15:12.403 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  127. 2018-12-14 01:15:12.418 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  128. 2018-12-14 01:15:12.430 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
  129. 2018-12-14 01:15:12.430 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
  130. ===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================
  131. Querying chaincode on peer0.org1...
  132. ===================== Querying on peer0.org1 on channel 'mychannel'... =====================
  133. Attempting to Query peer0.org1 ...3 secs
  134. + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  135. + res=0
  136. + set +x
  137. 2018-12-14 01:15:47.996 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  138. 2018-12-14 01:15:48.010 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  139. 100
  140. ===================== Query successful on peer0.org1 on channel 'mychannel' =====================
  141. Sending invoke transaction on peer0.org1 peer0.org2...
  142. + peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
  143. + res=0
  144. + set +x
  145. 2018-12-14 01:16:14.158 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  146. 2018-12-14 01:16:14.172 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  147. 2018-12-14 01:16:14.265 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200
  148. ===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
  149. Installing chaincode on peer1.org2...
  150. + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
  151. + res=0
  152. + set +x
  153. 2018-12-14 01:16:14.306 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  154. 2018-12-14 01:16:14.321 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  155. 2018-12-14 01:16:14.332 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
  156. 2018-12-14 01:16:14.332 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
  157. 2018-12-14 01:16:14.668 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" >
  158. ===================== Chaincode is installed on peer1.org2 =====================
  159. Querying chaincode on peer1.org2...
  160. ===================== Querying on peer1.org2 on channel 'mychannel'... =====================
  161. Attempting to Query peer1.org2 ...3 secs
  162. + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  163. + res=0
  164. + set +x
  165. 2018-12-14 01:16:17.816 UTC [main] InitCmd -> WARN 001 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  166. 2018-12-14 01:16:17.829 UTC [main] SetOrdererEnv -> WARN 002 CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable
  167. 90
  168. ===================== Query successful on peer1.org2 on channel 'mychannel' =====================
  169. ========= All GOOD, BYFN execution completed ===========
  170. _____ _ _ ____
  171. | ____| | \ | | | _ \
  172. | _| | \| | | | | |
  173. | |___ | |\ | | |_| |
  174. |_____| |_| \_| |____/

你可以滚动这些日志去查看各种交易。如果你没有获得这个结果,请移步疑难解答部分,看看我们是否可以帮助你发现问题。

关闭网络

最后,让我们把它全部停下来,这样我们可以一步一步地探索网络设置。以下操作将关闭你的容器,移除加密材料和4个配置信息,并且从Docker仓库删除chaincode镜像。你将再一次被提示是否继续,回答y:

  1. ./byfn.sh -m down
  2. Stopping with channel 'mychannel' and CLI timeout of '10000'
  3. Continue (y/n)?y
  4. proceeding ...
  5. WARNING: The CHANNEL_NAME variable is not set. Defaulting to a blank string.
  6. WARNING: The TIMEOUT variable is not set. Defaulting to a blank string.
  7. Removing network net_byfn
  8. 468aaa6201ed
  9. ...
  10. Untagged: dev-peer1.org2.example.com-mycc-1.0:latest
  11. Deleted: sha256:ed3230614e64e1c83e510c0c282e982d2b06d148b1c498bbdcc429e2b2531e91
  12. ...

加入 通道

peer channel join -b mychannel.block

创建通道

peer channel create -o orderer. example. com: 7050 -c mychannel -f /etc/ hyperledger/ configtx/ channel. tx

切换 环境 到 管理员 用户 的 MSP, 进入 Peer 节点 容器 peer0. org1. example. com

docker exec -it -e “CORE_ PEER_ MSPCONFIGPATH=/ etc/ hyperledger/ msp/ users/ Admin@ org1. example. com/ msp” peer0. org1. example. com bash

退出 Peer 节点 容器

exit

进入 cli 容器 安装 链 码 和 实例 化

进入容器
docker exec -it cli bash

安装链码

peer chaincode install -n mycc -v v0 -p github.com/chaincode_example02

实例化链码

peer chaincode instantiate -o orderer. example. com: 7050 -C mychannel -n mycc -v v0 -c ‘{“Args”:[“init”,“a”,“100”,“b”,“200”]}’

链码调用和查询

peer chaincode query -C mychannel -n mycc -v v0 -c ‘{“Args”:[“query”,“a”]}’

模拟转账

从“ a” 转移 10 到“ b”: peer chaincode invoke -C mychannel -n mycc -v v0 -c ‘{“Args”:[“invoke”,“a”, “b”,” 10”]}’

在分别查询a和b的

peer chaincode query -C mychannel -n mycc -v v0 -c ‘{“Args”:[“ query”,” a”]}’ peer chaincode query -C mychannel -n mycc -v v0 -c ‘{“Args”:[“ query”,” b”]}’

执行bootstrap.sh文件

该脚本将下载并提取设置网络所需的所有特定于平台的二进制文件,并将它们放入您在上面创建的目录中。
其中bin目录它包含了以下文件:
cryptogen,
configtxgen,
configtxlator,
peer,
orderer,
idemixgen, and
fabric-ca-client

部署网络

配置环境变量

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID=“Org1MSP”
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

创建通道和创世区块

根据之前生成的通道配置文件,创建通道export CHANNEL_NAME=superchannel peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx —tls —cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

加入通道peer channel join -b mychannel.block

更新锚点

peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx —tls —cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

安装链码

所有准备完成之后,开始安装链码。
分别支持三种语言:

Golang

peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/

Node.js

peer chaincode install -n mycc -v 1.0 -l node -p /opt/gopath/src/github.com/chaincode/chaincode_example02/node/

Java

peer chaincode install -n mycc -v 1.0 -l java -p /opt/gopath/src/github.com/chaincode/chaincode_example02/java/

实例化链码

Golang

peer chaincode instantiate -o orderer.example.com:7050 --tls —cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -v 1.0 -c ‘{“Args”:[“init”,“a”, “100”, “b”,“200”]}’ -P “AND (‘Org1MSP.peer’,‘Org2MSP.peer’)”

Node.js

peer chaincode instantiate -o orderer.example.com:7050 --tls —cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -l node -v 1.0 -c ‘{“Args”:[“init”,“a”, “100”, “b”,“200”]}’ -P “AND (‘Org1MSP.peer’,‘Org2MSP.peer’)”

Java

peer chaincode instantiate -o orderer.example.com:7050 --tls —cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -l java -v 1.0 -c ‘{“Args”:[“init”,“a”, “100”, “b”,“200”]}’ -P “AND (‘Org1MSP.peer’,‘Org2MSP.peer’)”

调用链码的函数

先查询一下有多少值
peer chaincode query -C $CHANNEL_NAME -n mycc -c ‘{“Args”:[“query”,“a”]}’

调用链码的函数定义锚点

…/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
…/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP

调用链码的函数根据配置生成加密相关的材料…/bin/cryptogen generate —config=./crypto-config.yaml
进入目录cd crypto-config
生成的材料会放到crypto-config文件夹里,把当前的路径导出成全局变量export FABRIC_CFG_PATH=$PWD
进入目录cd fabric-samples/first-network
生成网络组件./byfn.sh generate
这时会创建目录crypto-config并产生一些文件, 包括公私钥和证书等
构建网络./byfn.sh up如果想用node生态使用./byfn.sh up -l node
这一步是创建链码语言对应的镜像
加密生成器
我们将使用加密工具为我们的各种网络实体生成加密材料(x509证书和签名密钥)。
这些证书代表身份,它们允许在我们的实体进行通信和交易时进行签名/验证身份验证。
生成创世区块文件…/bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
生成通道配置文件export CHANNEL_NAME=superchannel && …/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
启动网络docker-compose -f docker-compose-cli.yaml up -d
进入客户端docker exec -it cli bash

发表评论

表情:
评论列表 (有 0 条评论,616人围观)

还没有评论,来说两句吧...

相关阅读