個人網(wǎng)站發(fā)布怎么做優(yōu)化大師官網(wǎng)入口
簡介
本文主要來自于B站視頻教學視頻,也主要參看了官方文檔中下圖這一章節(jié)。針對自己開發(fā)的代碼做出相應的總結。
1.啟動網(wǎng)絡
# 跳轉到指定的目錄
cd /root/fabric/fabric-samples/test-network# 啟動docker容器并且創(chuàng)建通道
./network.sh up createChannel
2.打包智能合約
備注:這里參考的B站視頻的go語言版本進行打包智能合約部分。
# 指定的鏈包路徑下執(zhí)行下述語句(這里參照視頻是在/root/fabric/fabric-samples/chaincode/fabcar/go)
GO111MODULE=on go mod vendorcd ../../test-network# 添加環(huán)境變量
export PATH=${PWD}/../bin:$PATH# 設置FABRIC_CFG_PATH指向存儲庫core.yaml中的文件fabric-samples
export FABRIC_CFG_PATH=$PWD/../config/# 執(zhí)行生命鏈周期代碼。代碼具體解析標識01
peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label facar_1
至此,鏈代碼包已經創(chuàng)建成功,可以在測試網(wǎng)絡的對等點上安裝連代碼。
3.安裝鏈碼包
在我們打包資產轉移(基本)智能合約后,我們可以在我們的節(jié)點上安裝鏈碼。鏈碼需要安裝在每個將背書交易的對等點上。因為我們將設置背書策略以要求 Org1 和 Org2 都背書,所以我們需要在兩個組織運營的對等節(jié)點上安裝鏈碼:
- peer0.org1.example.com
- peer0.org2.example.com
# 代碼具體解析標識02,簡述以Org1管理員身份到Org1對等方上安裝鏈碼。
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051# 安裝鏈碼
peer lifecycle chaincode install fabcar.tar.gz# 代碼具體解析與02類似,簡述為以Org2管理員身份到Org2對等方上安裝鏈碼。
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051# 安裝鏈碼
peer lifecycle chaincode install fabcar.tar.gz
批準鏈碼定義
安裝鏈碼包后,您需要批準組織的鏈碼定義。該定義包括鏈碼治理的重要參數(shù),例如名稱、版本和鏈碼背書策略。
# 查詢指定鏈包的包ID
peer lifecycle chaincode queryinstalled# 將查詢到到的id放到代碼存放的位置
export CC_PACKAGE_ID=basic_1.0:69de748301770f6ef64b42aa6bb6cb291df20aa39542c3ef94008615704007f3# 具體代碼解析03,簡述為由于安裝鏈碼時,設置的是Org2為管理員身份操作CLI,因此此時將鏈碼的定義批準為Org2。
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem# 設置環(huán)境變量以org1為管理員身份運行
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051# 批準鏈碼定義為Org1
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
將鏈碼定義提交到通道
當足夠數(shù)量的組織批準鏈碼定義后,一個組織可以將鏈碼定義提交到通道。如果大多數(shù)通道成員批準了該定義,則提交交易將成功,并且鏈碼定義中商定的參數(shù)將在通道上實現(xiàn)。
# 檢查通道成員是否批準了鏈碼定義,該命令返回出來的結果顯示頻道成員是否批準
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json# 提交鏈碼定義到通道
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt# 查詢鏈碼定義是否提交到通道
peer lifecycle chaincode querycommitted --channelID mychannel --name fabcar --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
調用鏈碼
將鏈碼定義提交到通道后,鏈碼將在加入安裝了鏈碼的通道的對等點上啟動。資產轉移(基本)鏈代碼現(xiàn)在已準備好由客戶端應用程序調用。使用以下命令在賬本上創(chuàng)建一組初始資產。請注意,invoke 命令需要針對足夠數(shù)量的對等點才能滿足鏈碼背書策略。(請注意,CLI 不會訪問 Fabric Gateway 對等點,因此必須指定每個認可對等點。)
# 創(chuàng)建一組初始化資產
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"initLedger","Args":[]}'# 調用查詢函數(shù)讀取鏈碼創(chuàng)建的汽車集
peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'
代碼具體解析標識
01:fabcar.tar.gz此命令將在當前目錄中創(chuàng)建一個名為的包。該–lang標志用于指定鏈碼語言,該–path標志提供智能合約代碼的位置。該路徑必須是完全限定路徑或相對于當前工作目錄的路徑。該–label標志用于指定鏈碼標簽,該標簽將在安裝后識別您的鏈碼。建議您的標簽包含鏈代碼名稱和版本。
02:置以下環(huán)境變量以peer以 Org1 管理員用戶身份操作 CLI。將CORE_PEER_ADDRESS設置為指向 Org1 對等點peer0.org1.example.com。
- CORE_PEER_TLS_ENABLED=true標識啟用了TLS加密來保護與peer節(jié)點的通信。
- CORE_PEER_LOCALMSPID="Org1MSP"表示本地MSP成員服務提供商的ID。被設置為Org1MSP,表示組織1的成員服務提供商ID。
- CORE_PEER_TLS_ROOTCERT_FILE環(huán)境變量,指定了peer節(jié)點TLS根證書的位置。${PWD}是一個環(huán)境變量,表示當前工作目錄。因此,這條命令使用了當前工作目錄來構建TLS根證書的文件路徑。
- CORE_PEER_MSPCONFIGPATH環(huán)境變量,指定了MSP配置文件的位置。這個配置文件包含了與peer節(jié)點通信所需的認證信息。
- 最后一個命令設置了CORE_PEER_ADDRESS環(huán)境變量,指定了peer節(jié)點的地址和端口號。在這里,peer節(jié)點被設置為在本地主機(localhost)的7051端口上監(jiān)聽
03:這個命令的目的是要在指定的通道上為您的組織批準特定鏈碼的定義,這樣就可以將其部署到該通道上。
- peer lifecycle chaincode approveformyorg - 這是一個peer命令,用于在指定通道上為您的組織批準鏈碼定義。
- -o localhost:7050 - 這個標志指定了要連接的Orderer節(jié)點的地址和端口號。
- –ordererTLSHostnameOverride orderer.example.com - 這個標志指定了用于TLS連接的Orderer的主機名。
- –channelID mychannel - 這個標志指定了要在其上批準鏈碼定義的通道ID。
- –name fabcar - 這個標志指定了您要批準的鏈碼的名稱。
- –version 1.0 - 這個標志指定了您要批準的鏈碼的版本號。
- –package-id $CC_PACKAGE_ID - 這個標志指定了您要批準的鏈碼的包ID。包ID是在安裝鏈碼時生成的唯一標識符。
- –sequence 1 - 這個標志指定了鏈碼的序列號。對于每個chaincode名稱,版本和通道需要一個唯一的序列號。
- –tls - 這個標志指示使用TLS來加密通信。
- –cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem - 這個標志指定了用于TLS連接的認證機構(CA)的根證書文件的路徑。