1. 前置軟體安裝:
1)go:下載壓縮包、安裝、配置環境變數,go version查看是否安裝成功
2)docker和docker-compose的安裝:
直接下載的docker桌面版,最開始下載的是最新版本,但是后面Fabric在安裝的時候報錯,后降級版本 (Docker version 18.09.0、docker-compose version 1.23.2)
需要配置鏡像加速參考檔案:https://blog.csdn.net/kozazyh/article/details/79795559 , 如果目錄下沒有daemon.json檔案,創建一個就好啦
注:之前安裝最新docker桌面版本的時候,可以直接打開docker在界面中配置,后來降級版本后,不知道為什么打不開了,就在組態檔里面直接配置了
3)fabric原始碼下載:直接從GitHub上下載,如果比較慢,可以先拉到碼云上在clone,版本切換到release-1.0
兩個工具安裝:
hyperledger/fabric/common/configtx/tool 運行 go install --tags=nopksc11
/Users/minghuili/go/src/github.com/hyperledger/fabric/common/tools/cryptogen 運行 go install --tags=nopksc11
安裝完成后,在$GOPATH/bin目錄下,出現 configtxgen和 cryptogen
4)fabric 組件docker鏡像:
cd fabric/examples/e2e_cli/
chmod +x download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
sudo ./download-dockerimages.sh
下載完成后,docker images 查看

5)fabric-samples原始碼下載:和fabric放在一個目錄即可,版本切換到release-1.0
$GOPATH/src/github.com/hyperledger/fabric-samples/first-network 目錄下,各個檔案夾的含義
localhost:first-network xx$ ll -a
total 104
drwxr-xr-x 13 xx staff 416 4 1 09:31 ./
drwxr-xr-x 15 xx staff 480 3 26 11:08 ../
-rw-r--r-- 1 xx staff 42 3 26 11:08 .env #環境變數
-rw-r--r-- 1 xx staff 335 3 26 11:08 README.md
drwxr-xr-x 4 xx staff 128 3 26 11:08 base/ #docker-compose的一些公共服務
-rwxr-xr-x 1 xx staff 15108 3 26 11:08 byfn.sh* #啟動腳本
drwxr-xr-x 3 xx staff 96 4 1 09:31 channel-artifacts/
-rw-r--r-- 1 xx staff 5013 3 26 11:08 configtx.yaml #對應channel-artifacts目錄
-rw-r--r-- 1 xx staff 3858 3 26 11:08 crypto-config.yaml #對應crypto-config目錄
-rw-r--r-- 1 xx staff 3015 3 26 11:08 docker-compose-cli.yaml #啟動網路
-rw-r--r-- 1 xx staff 4604 3 26 11:08 docker-compose-couch.yaml #啟動網路
-rw-r--r-- 1 xx staff 2883 3 26 11:08 docker-compose-e2e-template.yaml #啟動網路
drwxr-xr-x 3 xx staff 96 4 1 09:17 scripts/ #測驗腳本:創建通道、加入通道、安裝鏈碼、實體化鏈碼、和鏈碼互動
2.啟動網路
1)組態檔分析:
crypto-config.yaml:
OrdererOrgs:
- Name: Orderer #名字
Domain: example.com 域名
Specs:
- Hostname: orderer
- Name: Org1 #組織名字
Domain: org1.example.com
Template:
Count: 2 # 兩個peer結點
Users:
Count: 1 # 一個用戶
configtx.yaml:
Profiles、Organizations、Application
2)byfn.sh -h 查看 啟動網路的命令
byfn.sh -m generate -c 通道的名字 # yaml組態檔生成peer結點以及order結點相關的MSP證書,以及創世區塊等配置
流程分析:
為兩個組織org1和org2創建證書:

生成創世區塊:

生成通道的組態檔

生成兩個組織的錨節點,對外通信

對應crypto-config目錄中生成的內容
crypto-config中是order結點的配置,以及各個組織的peer結點的配置
ca:根CA的證書以及私鑰
msp:管理員的證書以及中間證書
peers:每個peer相關的證書
tlsca:
users:管理員證書以及普通用戶證書
對應channel-artifacts目錄中生成的內容:
創世區塊、通道配置、錨節點配置
3)byfn.sh -m up -c mychannel
流程:
創建通道
peer結點加入通道中
更新錨節點資訊
安裝chaincode
智能合約初始化
查詢操作
做了一次交易
再次查詢
4)生成容器 docker ps -a

docker images 生成鏈碼鏡像

5)鏈碼分析
呼叫流程:

script.sh呼叫鏈碼的位置:

鏈碼實體化

chaincode_example02.go 鏈碼內容分析:
初始化函式:func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response,判斷引數個數以及接受引數
Invoke函式:func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response,invoke、delete、query方法
invoke函式:func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response,轉賬
delete函式:func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response
query函式:func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response
【安裝問題記錄】
1../byfn.sh -m up -c imocc報錯
![]()
解決:將docker和docker-compose版本降級,降級后出現下面的問題:

解決:rm -rf ~/.docker/config.json
參考: https://blog.csdn.net/whizkidlxh/article/details/9020812
2. ./byfn.sh -m up -c imocc報錯
Error: got unexpected status: BAD_REQUEST -- error applying config update to existing channel 'imocc': error authorizing update: error validating ReadSet: proposed update requires that key [Group] /Channel/Application be at version 0, but it is currently at version 1
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========
原因:沒有關閉網路,./byfn.sh -m down -c imocc
3. ./byfn.sh -m up -c imocc報錯
!!!!!!!!!!!!!!! Query result on PEER0 is INVALID !!!!!!!!!!!!!!!!
================== ERROR !!! FAILED to execute End-2-End Scenario ==================
解決:https://blog.csdn.net/qq_20513027/article/details/83214782
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/272941.html
標籤:區塊鏈
下一篇:創建自己的區塊鏈網路 七
