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