新增 Fabric Organizations 至網路

本主題包含將 Hyperledger Fabric 組織加入 Oracle Blockchain Platform 網路的相關資訊。

加入 Fabric Organization 至 Oracle Blockchain Platform Network 的典型工作流程

Fabric 組織和 Oracle Blockchain Platform 創辦人組織必須完成以下任務,才能將 Fabric 組織加入 Oracle Blockchain Platform 網路。

作業 這是誰? 描述 其他資訊
建立 Fabric 組織的憑證檔案 Fabric 組織 尋找 Fabric 組織的 Admin、CA 和 TLS 憑證資訊,並用來撰寫 JSON 憑證檔案。 建立 Fabric Organization 的憑證檔案
將 Fabric 組織的憑證檔案上傳至 Oracle Blockchain Platform 網路 創辦人組織 您可以使用主控台來上傳和匯入 Fabric 組織的憑證檔案,將 Fabric 組織新增至網路。 匯入憑證以新增組織至網路
建立通道 創辦人組織 建立通路,並為其新增 Fabric 組織。 建立通道
從建立者匯出訂購服務設定值 創辦人組織 將創始者的排序服務設定寫入 JSON 檔案,並將該檔案傳送至 Fabric 組織。 將參加者或橫向擴展 OSN 加入創始人訂購服務
撰寫 Orderer 憑證檔案 Fabric 組織 建立名為 orderer.pem 的檔案,其中包含 tlscacert 資訊。

移至匯出的排序服務設定值檔案,並複製 tlscacert 資訊。將 tlscacert 資訊貼到 orderer.pem 檔案後,您必須以換行字元取代 \n 的所有例項。

orderer.pem 檔案必須具有下列格式:

-----BEGIN CERTIFICATE-----
... 
...
... 
-----END CERTIFICATE-----
建立 Fabric Organization 的憑證檔案
提供訂購服務設定值 創辦人組織 開啟訂購服務設定值檔案,然後尋找訂購服務的地址和連接埠,並將它們提供給 Fabric 組織,如下列範例所示:
"orderingServiceNodes": [
{
"address": "grpcs://example_address:7443",
...
}]
新增 Fabric 組織至網路 Fabric 組織 Fabric 組織會將憑證複製到其環境、設定環境變數、擷取 genesis 區塊、加入通道,以及安裝鏈碼。 準備使用 Oracle Blockchain Platform Network 的 Fabric 環境

建立 Fabric Organization 的憑證檔案

如果 Fabric 組織要加入 Oracle Blockchain Platform 網路,則必須寫入包含其 admincerts、cacerts 和 tlscacerts 資訊的憑證檔案。Oracle Blockchain Platform 創辦人組織匯入此檔案,將 Fabric 組織新增至網路。

Fabric 憑證資訊儲存在 PEM 檔案 (位於 Fabric 組織的 MSP 資料夾中)。例如,network_name_example/crypto-config/peerOrganizations/example_org.com/msp/

憑證檔案必須以 JSON 撰寫,且必須包含下列欄位。對於所有憑證,當您將憑證資訊複製到 JSON 檔案中時,您必須將每一行換成 \n ,如此一來,資訊就會出現在一行,而且沒有空格,如下列範例所示。

  • mspid — 指定 Fabric 組織的名稱。

  • type — 指示組織為網路參與者。這個值必須是 Participant
  • admincert — 包含組織之 Admin 憑證檔案的內容:Admin@example_org.com-cert.pem

  • cacert — 包含組織之 CA 憑證檔案的內容:ca.example_org-cert.pem

  • tlscacert — 包含組織之 TLS 憑證檔案的內容:tlsca.example_org-cert.pem

  • intermediatecerts — 此選擇性元素包含中介 CA 憑證檔案的內容。除非有中介 CA 憑證檔案,否則請勿指定此元素。
  • nodeouidentifiercert — 此區段包含識別節點 OU 角色的憑證。
  • adminouidentifiercert — 包含組織憑證檔案的內容,用來識別節點 OU 管理員角色。如果您不需要管理員角色,可以使用 cacert 檔案內容或中間憑證檔案內容作為管理員識別碼內容。

  • clientouidentifiercert — 包含組織憑證檔案的內容,用來識別節點 OU 用戶端角色。

  • ordererouidentifiercert — 包含組織憑證檔案的內容,用於識別節點 OU 排序器角色。如果您不需要 Orderer 角色,可以使用 cacert 檔案內容,或是中間憑證檔案內容作為 ordererouidentifier 內容。

  • peerouidentifiercert — 包含組織憑證檔案的內容,用於識別節點 OU 對等角色。

建構與下列範例類似的檔案:
{
  "mspID": "examplemspID",
  "type":  "Participant",
  "certs": { 
   "admincert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n",
   "cacert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n",
   "tlscacert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n"
   "nodeouidentifiercert": {
      "adminouidentifiercert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n",
      "clientouidentifiercert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n",
      "ordererouidentifiercert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n",
      "peerouidentifiercert": "-----BEGIN CERTIFICATE-----\nexample_certificate\nexample_certificate==\n-----END CERTIFICATE-----\n"
    }
  }
} 
    

準備使用 Oracle Blockchain Platform 網路的 Fabric 環境

您必須先修改 Fabric 組織的環境,才能使用 Oracle Blockchain Platform 網路。

確認下列先決條件作業已完成。如需詳細資訊,請參閱將 Fabric Organization 加入 Oracle Blockchain Platform Network 的典型工作流程

  • 已建立 Fabric 組織的憑證檔案,並傳送給 Oracle Blockchain Platform 網路創辦人。

  • 網路創始人上傳了憑證檔案,以便將 Fabric 組織新增至網路。

  • 網路創辦人會建立一個新通道,並將 Fabric 組織加入該通道。

  • 網路創辦人下載了其訂購服務設定,並將他們傳送至 Fabric 組織。

  • Fabric 組織已建立 orderer 憑證檔案。

  • 網路創辦人將訂購服務位址及連接埠提供給 Fabric 組織。

您必須新增 Fabric 組織,並安裝並測試鏈碼。

  1. 瀏覽至 Fabric 網路目錄並啟動對等容器。

  2. 使用下列指令取得頻道的 genesis 區塊 :

    peer channel fetch 0 mychannel.block -o ${orderer_addr}:${orderer_port} -c mychannel --tls --cafile orderer.pem --logging-level debug  

    其中:

    • {orderer_addr} 是創立者的訂購者地址。

    • {orderer_port} 是 Founder 的連接埠號碼。

    • -c mychannel 是創立者建立的通路名稱。這是 Fabric 組織在 Oracle Blockchain Platform 網路上傳送和接收交易的通道。

    • orderer.pem 是 Founder 的 Orderer 憑證檔案。

  3. 使用以下命令加入通道:

    peer channel join -b mychannel.block -o ${orderer_addr}:${orderer_port} --tls --cafile orderer.pem --logging-level debug
  4. 使用以下指令安裝鏈碼:

    peer chaincode install -n mycc -v 1.0 -l "golang" -p ${CC_SRC_PATH}

    其中 CC_SRC_PATH 是包含鏈碼的資料夾。

  5. 使用下列命令建立鏈碼:

    peer chaincode instantiate -o  ${orderer_addr}:${orderer_port} --tls --cafile orderer.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P <policy_string> --logging-level debug
  6. 使用此命令呼叫鏈碼:

    peer chaincode invoke -o ${orderer_addr}:${orderer_port}  --tls true --cafile orderer.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}' --logging-level debug
  7. 使用以下命令查詢鏈碼:

    peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'  --logging-level debug