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

fabric-samples-1.4.0 开发搭建

一、环境安装前准备:

(1)首先安装基本工具

yum install git
yum install curl
yum -y install epel-release
yum install python-pip
pip install --upgrade pip

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

docker --version
docker-compose --version

(2)安装Go语言

# go 环境变量
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
# go 版本
go version

(3)安装Node.js

yum install gcc gcc-c++
gcc -v

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

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

(4)继续安装nodejs

node -v

(5)安装 npm

npm install npm -g
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

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

在这里插入图片描述

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

root@fabric3:/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/base# ls
docker-compose-base.yaml  peer-base.yaml

目录下的两个配置文件中TLS_ENABLEDfalse

/github.com/hyperledger/fabric-samples/first-network# 
docker-compose-cli.yaml文件中TLS_ENABLEDfalse

三、想要现在运行吗

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

以下是该byfn.sh脚本的帮助文档:
./byfn.sh -h
Usage:
  byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>]
  byfn.sh -h|--help (print this message)
    -m <mode> - one of 'up', 'down', 'restart' or 'generate'
      - 'up' - bring up the network with docker-compose up
      - 'down' - bring up the network with docker-compose up
      - 'restart' - bring up the network with docker-compose up
      - 'generate' - generate required certificates and genesis block
    -c <channel name> - config name to use (defaults to "mychannel")
    -t <timeout> - CLI timeout duration in microseconds (defaults to 10000)

Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:

  byfn.sh -m generate -c <channelname>
  byfn.sh -m up -c <channelname>

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

生成网络神器

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

./byfn.sh -m generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/root/go/src/github.com/hyperledger/fabric-samples/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x

/root/go/src/github.com/hyperledger/fabric-samples/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
+ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
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'.
2018-12-14 09:14:11.119 CST [common.tools.configtxgen] main -> INFO 002 Loading configuration
2018-12-14 09:14:11.131 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
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
2018-12-14 09:14:11.145 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 005 orderer type: solo
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
2018-12-14 09:14:11.149 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Generating genesis block
2018-12-14 09:14:11.151 CST [common.tools.configtxgen] doOutputBlock -> INFO 008 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2018-12-14 09:14:11.196 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
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
2018-12-14 09:14:11.230 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
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
2018-12-14 09:14:11.231 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2018-12-14 09:14:11.232 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2018-12-14 09:14:11.277 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
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
2018-12-14 09:14:11.309 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
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
2018-12-14 09:14:11.309 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2018-12-14 09:14:11.309 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2018-12-14 09:14:11.355 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
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
2018-12-14 09:14:11.387 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
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
2018-12-14 09:14:11.387 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2018-12-14 09:14:11.388 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

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

启动网络

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

./byfn.sh -m up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.4.0
DOCKER_IMAGE_VERSION=1.4.0-rc1
=================== WARNING ===================
  Local fabric binaries and docker images are  
  out of  sync. This may cause problems.       
===============================================
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Pulling orderer.example.com (hyperledger/fabric-orderer:latest)...
latest: Pulling from hyperledger/fabric-orderer
3b37166ec614: Already exists
504facff238f: Already exists
ebbcacd28e10: Already exists
c7fb3351ecad: Already exists
2e3debadcbf7: Already exists
fc435e46e32e: Already exists
a4922bafdce8: Already exists
2cb4429027c1: Already exists
8c2b02bf9e47: Pull complete
7e18daca12c4: Pull complete
Creating peer0.org1.example.com ... done
Creating peer0.org2.example.com ... done
Creating orderer.example.com    ... done
Creating peer1.org1.example.com ... done
Creating peer1.org2.example.com ... done
Creating cli                    ... done

 ____    _____      _      ____    _____ 
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |  
 ___) |   | |    / ___ \  |  _ <    | |  
|____/    |_|   /_/   \_\ |_| \_\   |_|  

Build your first network (BYFN) end-to-end test

Channel name : mychannel
Creating channel...
+ 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
+ res=0
+ set +x
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
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
2018-12-14 01:14:52.516 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:14:52.547 UTC [cli.common] readBlock -> INFO 004 Received block: 0
===================== Channel 'mychannel' created ===================== 

Having all peers join the channel...
+ peer channel join -b mychannel.block
+ res=0
+ set +x
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
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
2018-12-14 01:14:52.619 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:14:52.638 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
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
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
2018-12-14 01:14:55.771 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:14:55.797 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
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
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
2018-12-14 01:14:58.918 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:14:58.953 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
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
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
2018-12-14 01:15:02.078 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:15:02.096 UTC [channelCmd] executeJoin -> INFO 004 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' ===================== 

Updating anchor peers for org1...
+ 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
+ res=0
+ set +x
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
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
2018-12-14 01:15:05.237 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:15:05.252 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' ===================== 

Updating anchor peers for org2...
+ 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
+ res=0
+ set +x
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
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
2018-12-14 01:15:08.325 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-12-14 01:15:08.351 UTC [channelCmd] update -> INFO 004 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' ===================== 

Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
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
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
2018-12-14 01:15:11.477 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-12-14 01:15:11.477 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-12-14 01:15:12.045 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" > 
===================== Chaincode is installed on peer0.org1 ===================== 

Install chaincode on peer0.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
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
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
2018-12-14 01:15:12.130 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-12-14 01:15:12.130 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-12-14 01:15:12.345 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" > 
===================== Chaincode is installed on peer0.org2 ===================== 

Instantiating chaincode on peer0.org2...
+ 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'\'')'
+ res=0
+ set +x
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
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
2018-12-14 01:15:12.430 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-12-14 01:15:12.430 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' ===================== 

Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... ===================== 
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

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
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
100
===================== Query successful on peer0.org1 on channel 'mychannel' ===================== 
Sending invoke transaction on peer0.org1 peer0.org2...
+ 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"]}'
+ res=0
+ set +x
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
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
2018-12-14 01:16:14.265 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200 
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== 

Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
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
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
2018-12-14 01:16:14.332 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-12-14 01:16:14.332 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-12-14 01:16:14.668 UTC [chaincodeCmd] install -> INFO 005 Installed remotely response:<status:200 payload:"OK" > 
===================== Chaincode is installed on peer1.org2 ===================== 

Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... ===================== 
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

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
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
90
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 

========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

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

关闭网络

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

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

加入 通道

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

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试