使用 Visual Studio 程式碼部署您的鏈碼
建立鏈碼專案之後,您可以在本機將其部署到自動產生的 Hyperledger Fabric 網路,或者從遠端部署到您的 Oracle Blockchain Platform Cloud 或 Enterprise Edition。您也可以封裝鏈碼專案,以便手動部署至 Oracle Blockchain Platform。
將鏈碼部署至本機 Hyperledger Fabric 網路
建立鏈碼專案之後,您可以在本機 Hyperledger Fabric 基本網路中測試它。
當您安裝 VS Code 的 Blockchain App Builder 擴充功能時,系統會自動建立具有單一通道的 Hyperledger Fabric 網路。這會在環境窗格中列為 Local Environment
。您無法刪除或修改此環境;您只要在其上部署鏈碼,然後在其停止運作時重新建立。
Blockchain App Builder 鏈碼部署會啟動 Hyperledger Fabric 基本網路、其他服務,並為您安裝和部署鏈碼。
- 在鏈碼詳細資訊窗格中,選取部署。
- 在部署精靈中:
- 請確定已選取正確的鏈碼名稱。
- 選取您的目標環境 - 若為本機部署,請選擇本機環境。
- 選取要建置的通道。系統預設會建立名為 "
mychannel
" 的通道,並安裝擴充功能,可用於測試。 - 選擇性地輸入任何可能需要的初始參數。
- 對於權杖專案,您第一次部署時必須輸入權杖管理員清單作為參數。此清單是指定記號管理員的
{user_id, org_id}
資訊陣列。若為本機 Hyperledger Fabric 網路,請在org_id
欄位使用值Org1MSP
。若為 NFT 鏈碼,adminList
參數的索引鍵為userId
,orgId
代表 TypeScript,UserId
代表 Go,而OrgId
代表 Go。第一次部署之後,您可以為adminList
參數提供空白陣列,也可以使用adminList
參數新增記號管理員。其他不是第一次建置者的建置程式,必須為adminList
參數提供空白陣列。若要這麼做,請在建置窗格中開啟Init
參數清單,然後按一下adminList
參數旁邊的減號 (-) 按鈕,即可選取空白陣列。
- 按一下建置。
鏈碼完成部署後,輸出主控台會聲明該鏈碼已順利安裝並在指定的通道上部署。
疑難排解
在區域網路上執行鏈碼專案時,可能會發生下列問題。
- 遺漏 Go 權限
- 在本機網路中安裝 Go chaincode 專案時,您可能會看到類似輸出主控台中以下的錯誤:
INFO (Runtime): 2020/06/22 22:57:09 build started INFO (Runtime): Building .... INFO (Runtime): go build runtime/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtine/ cgo.a: permission denied ERROR (Runtime): go build runtine/cgo: copying /Users/myname/Library/Caches/go-build/f8/.….….d: open /usr/local/go/pkg/darwin_amd64/runtime/ cgo.a: permission denied INFO (Runtime): An error occurred while building: exit status 1
- 建置失敗
- 由於部署失敗、部署損毀、Docker 對等容器已滿,或在區域網路中終止的 Docker 對等體,您可能會看到類似以下的錯誤:
============ Started instantiate Chaincode ============ [2028-19-01T19:25:lO.372] [ERROR] default - Error instantiating Chaincode GollGl on channel mychannel, detailed error: Error: error starting container: error starting container: Failed to generate platform-specific docker build: Failed to pull hyperledger/fabric-ccenv:latest : API error (404): manifest for hyperledger/ fabric-ccenv:latest not found: manifest unknown: manifest unknown [2020-19-01T19:25:10.372] (INFO) default - ============ Finished instantiate Chaincode ============ [2020-19-01119:25:10.372] [ERROR] default - Error: Error instantiating Chaincode Goll01 on channel mychannel, detailed error: Error: error starting container: error starting container: Failed to generate platfom-specific docker build: Failed to pull hyperledger/fabric-ccenv: latest : API error (404): manifest for hyperledger/ fabric-ccenv:lalest not found: manifest unknown: manifest unknown exited: signal: terminated INFO: exited: signal: terminated ERROR: Error in Chaincode deployment
- 需要重新建立環境
- 您可能會看到類似以下的錯誤:
Starting ca.example.com ... Starting orderer.example.com ... Starting orderer.example.com ... error ERROR: for orderer.example.com Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted Starting ca.example.com... error ERROR: for ca.example.com Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted ERROR: for orderer.example.com Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted ERROR: for ca.example.com Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted Encountered errors while bringing up the project. ERROR: Starting ca.example.com ... Starting orderer.example.com ... Starting orderer.example.com ... error ERROR: for orderer.example.com Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted Starting ca.example.com ... error ERROR: for ca.example.com Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted ERROR: for orderer.example.com Cannot start service orderer.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/config': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted ERROR: for ca.example.com Cannot start service ca.example.com: error while creating mount source path '/host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0/node_modules/@oracle/ochain-cli/runtime/network/basic-network/crypto-config/peerOrganizations/org1.example.com/ca': mkdir /host_mnt/c/Users/opc/.vscode/extensions/oracle.oracle-blockchain-1.4.0: operation not permitted Encountered errors while bringing up the project. ERROR: Error in Chaincode deployment
將您的鏈碼部署至遠端 Oracle Blockchain Platform 網路
在本機網路上部署並測試鏈碼專案以確保其如設計般運作之後,就可以將其部署到 Oracle Blockchain Platform。
建立 Oracle Blockchain Platform 執行處理的連線組態
您必須啟動並執行 Blockchain Platform 執行處理,才能完成此步驟。
- 在 Visual Studio 程式碼的環境窗格中,按一下建立環境圖示。
- 在環境詳細資訊精靈上:
- 輸入遠端環境的名稱。
- 輸入描述。
- 在遠端 URL 中,輸入遠端 Oracle Blockchain Platform 執行處理的 URL。
- 輸入具備
ADMIN
或REST_CLIENT
角色之 Oracle Blockchain Platform 使用者的 Oracle Identity Cloud Service 使用者名稱和密碼。若要呼叫鏈碼,只需要REST_CLIENT
角色。若要部署或升級鏈碼,也必須將 IDCS 使用者指派為ADMIN
角色。如需有關使用者和角色的詳細資訊,請參閱設定使用者和應用程式角色。
- 按一下建立即可儲存環境。使用者名稱和密碼會暫時儲存在本機 Visual Studio Code 階段作業中。如果您關閉 Visual Studio 程式碼,然後啟動新的 Visual Studio 程式碼階段作業,就必須再次輸入使用者名稱和密碼。
部署您的鏈碼
- 在鏈碼窗格中選取您要部署的鏈碼專案。
- 在鏈碼詳細資訊窗格中,選取部署。
- 在部署精靈中,應該預先填入鏈碼專案的名稱。
- 選取您的目標環境 - 針對遠端部署,請選擇您先前設定的 Oracle Blockchain Platform 環境。
- 輸入您要部署的通道名稱。
- 選擇性地設定任何必要的初始參數。
- 按一下建置。
- 已順利擷取 Oracle Blockchain Platform 詳細資訊。
- 端點列表已成功抓取 。
- 已順利安裝鏈碼專案。
- 已順利核准並確認鏈碼專案。
- 已順利在各個對等和通道上部署鏈碼。
在具有多個組織的環境中,若要透過參與者執行處理在相同通道上重新部署鏈碼,請使用主控台來部署鏈碼。
升級鏈碼專案
升級鏈碼是由 Blockchain App Builder 自動處理。變更鏈碼後,只需重新部署即可自動為您升級專案。當您執行升級程序時,可以傳送空白陣列給 adminList
參數,或使用 adminList
參數新增記號管理員。如果您不是第一次建置程式,則必須為 adminList
參數提供空白陣列。若要傳送空白陣列給 adminList
參數,請在建置窗格中開啟 Init
參數清單,然後按一下 adminList
參數旁邊的減號 (-) 按鈕,即可選取空白陣列。
- 已順利擷取 Oracle Blockchain Platform 詳細資訊。
- 端點列表已成功抓取 。
- 已進行檢查以判斷鏈碼專案是否已安裝,如果已安裝,則會擷取版本。
- 已順利升級鏈碼版本 (例如,從版本 1.0 升級至版本 2.0)。
在具有多個組織的環境中,若要升級鏈碼,請使用主控台並手動核准參與者的鏈碼。
將您的 Chaincode 專案封裝為 Oracle Blockchain Platform 進行手動部署
您可以封裝鏈碼專案,以便手動部署至 Oracle Blockchain Platform Cloud 或 Enterprise Edition。
Package 函式會建立僅包含編譯和發行檔案的歸檔檔案。不包含鏈碼專案中的 binary
、libs
、node_modules
及 test
資料夾。此封存檔案可手動上傳至 Oracle Blockchain Platform 進行部署。
- 在鏈碼窗格中選取您的鏈碼專案。
- 按一下滑鼠右鍵並選取套裝程序。
- 選取要儲存套裝程式的目標位置,然後按一下選取輸出資料夾。
由於軟體先決條件的變更,當您執行 TypeScript 鏈碼的套裝程式功能時,系統會提示您輸入要建立其套裝程式之 Oracle Blockchain Platform 執行處理的佈建日期。在 Blockchain App Builder 中建立的 TypeScript 鏈碼與舊版的 Oracle Blockchain Platform 不相容,不會變更基礎基礎架構。Blockchain App Builder 會根據您的選擇將鏈碼基礎架構相應地封裝在一起。
當指令順利完成時,就會傳回套裝軟體的位置。