建议和反馈

请填写你的反馈内容

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

2019-08-28 ·1838次阅读 ·读完需要6分钟

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

1

2

(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

1

2

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 

1

2

3



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_ENABLED为false


/github.com/hyperledger/fabric-samples/first-network# 

docker-compose-cli.yaml文件中TLS_ENABLED为false



三、想要现在运行吗

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 ] [-t ]

  byfn.sh -h|--help (print this message)

    -m - 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 - config name to use (defaults to "mychannel")

    -t - 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

  byfn.sh -m up -c


如果你选择不提供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: 

===================== 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: 

===================== 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: 

===================== 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


评论(0)问答(0)
请先登录或注册

请先登陆或注册

相关推荐

Hyperledger是什么意思呢

在我告诉你什么是Hyperledger之前,让我告诉你什么不是Hyperledger。因为当今IT行业拥有如此众多的区块链平台,所以很容易混淆。因此,首先,Hyperledger不是:加密货币区块链一......
比特币 · 2020-02-06
936阅读 · 0赞赏 · 0问答

在AWS上安装HYPERLEDGER FABRIC

如果您想使用Hyperledger工具开发小型到企业级的区块链应用程序,则第一步是了解什么是Hyperledger及其工作方式。特别是,“ 面向区块链开发人员的Hyperledger架构和组件 ”是一......
区块链技术 · 2020-01-27
1279阅读 · 0赞赏 · 0问答

企业区块链应用搭建,业务数据上链服务联盟链系统开发

企业区块链应用搭建,业务数据上链服务联盟链系统开发区块链是一种由多方共同维护,使用密码学保证传输和访问安全,能够实现数据一致存储、难以篡改、防止抵赖的记账技术,也称为分布式账本技术。了解更多区块链应用......
wx13823151761 · 2020-01-22
1498阅读 · 0赞赏 · 0问答

Hyperledger项目:如何使区块链变得灵活!

Hyperledger项目由Linux基金会于2015年发起,Linux基金会由来自不同行业的成员和开发人员社区组成,以满足应用程序的需求。IBM是最早的成员之一。该项目现在有200多个成员,一个活动......
比特币 · 2020-01-20
1004阅读 · 0赞赏 · 0问答

区块链合同存证数据上链,联盟链智能合约系统开发搭建

区块链合同存证数据上链,联盟链智能合约系统开发搭建区块链存证应用系统,区块链智能合约应用开发,企业合同上链存储联盟用应用开发,企业数据上链,企业联盟链搭建,智能合约撰写相关服务找源中瑞科技!您的企业还......
wx13823151761 · 2020-01-15
894阅读 · 0赞赏 · 0问答

联盟链走向何方

联盟链技术哪家强?开源架构Fabric、FISCO BCOS(以下简称“BCOS”)、CITA 技术对比。出品:碳链价值研究院 01 摘要第 46 届世界经济论坛达沃斯年会将区块链与人工智能、自动驾驶......
溪塔科技 · 2020-01-10
1203阅读 · 0赞赏 · 0问答

链客

2758

LK币

3

粉丝

390

笔记

感谢"链客"

这篇精彩的笔记,目前已经帮助

  • 0
  • 1
  • 8
  • 3
  • 8
喜欢0
链客社群 加入

微博进入

商务合作>

广告投放>

公司名称:北京链客行科技有限公司

联系方式:010-67707199

ICP备案号:京ICP备18032136号

Copyright:链客区块链技术问答社区 版权所有

感谢您的提问,问题被社区永久收入以便新人查看。一定要记得采纳最佳答案哦!加油!

感谢您的善举,每一次解答会成为新人的灯塔,回答被采纳后获得20算力和相应的LK币奖励

您将赞赏给对方2LK币的奖励哦!感谢您的赞赏!

您将赞赏给对方2LK币的奖励哦!感谢您的赞赏!