使用 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 基本網路、其他服務,並為您安裝和部署鏈碼。

  1. 鏈碼詳細資訊窗格中,選取部署
  2. 在部署精靈中:
    • 請確定選取的鏈碼名稱正確。
    • 選取您的目標環境 - 若為本機部署,請選擇本機環境
    • 選取要建置到的通道。依預設,擴充套件安裝會建立名為 "mychannel" 的通道,並可用於測試。
    • 選擇性地輸入任何可能需要的初始參數。
    • 對於記號專案,您第一次部署時必須輸入記號管理員清單作為參數。此清單是指定權杖管理員的 {user_id, org_id} 資訊陣列。若為本機 Hyperledger Fabric 網路,請在 org_id 欄位使用 Org1MSP 值。若為 NFT 鏈碼,adminList 參數的索引鍵為 userIdorgId (若為 TypeScript),而 UserId 則為 OrgId (若為 Go)。第一次部署之後,您可以為 adminList 參數提供空白陣列,或者使用 adminList 參數來新增記號管理員。其他不是第一次建置程式的建置者,必須為 adminList 參數提供空白陣列。若要這麼做,請在建置窗格中開啟 Init 參數清單,然後按一下 adminList 參數旁邊的減號 (–) 按鈕,即可選取空白陣列。
  3. 按一下建置

當鏈碼完成部署後,輸出主控台會說明該鏈碼已成功將其安裝並部署到指定的通道上。

疑難排解

在區域網路上執行鏈碼專案時,可能會發生下列問題。

遺漏 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
這是因為遺漏 Go 的權限。此錯誤僅在 Mac OS 中出現。此為已知問題:
解決方案:變更 $GOROOT 的權限,然後嘗試重新部署:
sudo chmod -R 777 /usr/local/go
部署失敗
由於部署失敗、部署損毀、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 Network

在本機網路上部署並測試鏈碼專案後,確定鏈碼專案如設計般運作後,即可將其部署到 Oracle Blockchain Platform。

建立 Oracle Blockchain Platform 執行處理的連線組態

您必須啟動並執行區塊鏈平台執行處理,才能完成此步驟。

  1. 在 Visual Studio 程式碼環境窗格中,按一下建立環境圖示。
  2. 環境詳細資訊精靈中:
    • 輸入遠端環境的名稱。
    • 輸入描述。
    • 遠端 URL 中,輸入遠端 Oracle Blockchain Platform 執行處理的 URL。
    • 輸入具有 ADMINREST_CLIENT 角色之 Oracle Blockchain Platform 使用者的 Oracle Identity Cloud Service 使用者名稱和密碼。若要呼叫鏈碼,只需要 REST_CLIENT 角色。若要部署或升級鏈碼,也必須將 ADMIN 角色指派給 IDCS 使用者。如需有關使用者和角色的詳細資訊,請參閱設定使用者和應用程式角色
  3. 按一下建立即可儲存環境。使用者名稱和密碼會暫時儲存在本機 Visual Studio 程式碼階段作業中。如果您關閉 Visual Studio 程式碼,然後啟動新的 Visual Studio 程式碼階段作業,則必須再次輸入使用者名稱和密碼。

部署您的 Chaincode

  1. 選取要在鏈碼窗格中部署的鏈碼專案。
  2. 鏈碼詳細資訊窗格中,選取部署
  3. 在部署精靈中,應該預先填入鏈碼專案的名稱。
    • 選取您的目標環境 - 若為遠端部署,請選擇先前設定的 Oracle Blockchain Platform 環境。
    • 輸入您要部署的通道名稱。
    • 選擇性地設定任何必要的初始參數。
  4. 按一下建置
順利將鏈碼部署到遠端 Oracle Blockchain Platform 之後,主控台日誌會顯示發生下列事件:
  • 已順利擷取 Oracle Blockchain Platform 詳細資訊。
  • 已順利擷取對等清單。
  • 已順利安裝 chaincode 專案。
  • 已順利核准並確認鏈碼專案。
  • 已順利在每個對等和通道上部署鏈碼。

在具有多個組織的環境中,若要透過參與者執行處理在相同通道上重新部署鏈碼,請使用主控台部署鏈碼。

升級 Chaincode 專案

區塊鏈 App 產生器會自動處理升級鏈碼。變更鏈碼後,只要再部署一次,就會自動為您升級專案。當您執行升級處理作業時,可以傳送空的陣列給 adminList 參數,或使用 adminList 參數來新增記號管理員。如果您不是第一次建置程式,則必須為 adminList 參數提供空白陣列。若要傳送空白陣列給 adminList 參數,請在建置窗格中開啟 Init 參數清單,然後按一下 adminList 參數旁邊的減號 (–) 按鈕,即可選取空白陣列。

如果升級成功,記錄將顯示發生下列事件:
  • 已順利擷取 Oracle Blockchain Platform 詳細資訊。
  • 已順利擷取對等清單。
  • 已進行檢查以判斷是否已安裝 chaincode 專案,如果已安裝,則會擷取版本。
  • 鏈碼版本已成功升級 (例如,從 1.0 版升級至 2.0 版)。

在具有多個組織的環境中,若要升級鏈碼,請使用主控台並手動核准參與者中的鏈碼。

將您的 Chaincode 專案封裝到 Oracle Blockchain Platform 手動部署

您可以封裝鏈碼專案,以便將手動部署至 Oracle Blockchain Platform Cloud 或 Enterprise Edition。

Package 函數會建立一個僅包含編譯和發行版本檔的歸檔檔案。不包括鏈碼專案中的 binarylibsnode_modulestest 資料夾。此封存檔案可手動上傳至 Oracle Blockchain Platform 進行部署。

  1. 鏈碼窗格中選取您的鏈碼專案。
  2. 按一下滑鼠右鍵並選取套裝程序
  3. 選取要儲存套裝程式的位置,然後按一下選取輸出資料夾

由於軟體先決條件的變更,當您執行 TypeScript 鏈碼的套裝程式功能時,系統會提示您輸入要建立套裝程式之 Oracle Blockchain Platform 執行處理的佈建日期。在 Blockchain App Builder 中建立的 TypeScript 鏈碼與舊版的 Oracle Blockchain Platform 不相容,無法變更基礎基礎架構。Blockchain App Builder 會根據您的選擇,相應地封裝鏈碼基礎架構。

當指令成功完成時,將傳回套裝軟體的位置。