CLIを使用したチェーンコードのデプロイ

チェーンコード・プロジェクトを作成した後、自動的に生成されたHyperledger Fabricネットワークにローカルにデプロイするか、Oracle Blockchain Platform CloudまたはEnterprise Editionにリモートにデプロイできます。チェーンコード・プロジェクトをパッケージ化して、Oracle Blockchain Platformに手動でデプロイすることもできます。

ローカルHyperledger Fabricネットワークへのチェーンコードのデプロイ

チェーンコード・プロジェクトを作成した後、それをローカルのHyperledger Fabricネットワークにデプロイできます。この単一チャネル・テスト・ネットワークは、ブロックチェーン・アプリケーション・ビルダーのインストール時に作成されます。

ブロックチェーン・アプリケーション・ビルダーのochain runコマンドは、Hyperledger Fabricネットワークおよびその他のサービスを起動し、チェーンコードをインストールしてデプロイします。

ochain run -h
Usage: run [options] [...args]
Run chaincode project locally in debug mode.

Arguments :
[...args] (optional) Chaincode instantiate arguments. Arguments should be space separated.

Options:
-h, --help        output command usage information 
-D, --debug       enable debug logging
-P, --debug-port  (optional) specify debug process port
-b, --build       (optional) rebuild runtime if already exists
-p, --project     (optional) Path to Chaincode project to run. If not specified, it defaults to current directory.  

Examples :
$> ochain run   

ブロックチェーン・アプリケーション・ビルダーのインストール時に作成されるテスト・ネットワークは、Hyperledger Fabric v2.5.7およびHyperledger Fabric CA v1.5.9を実行します。

トークン・プロジェクト

トークン・チェーンコード・プロジェクトの場合、ochain runコマンドを使用してトークンの管理者のリストを指定する必要があります:
ochain run <adminList array>
adminList配列は、トークン管理者に指定する情報の配列ですトークン・チェーンコード・プロジェクトを初めてデプロイする場合、adminList配列は必須パラメータです。プロジェクトを再度デプロイする場合は、adminListパラメータに空の配列を渡すか、adminListパラメータを使用してトークン管理者が追加できます。初回デプロイヤではない他のデプロイヤは、adminListパラメータに空の配列を指定する必要があります。パラメータ情報は、代替可能トークンと非代替トークンで異なります:
  • トークン・タクソノミ・フレームワーク標準を使用する代替可能トークンの場合、パラメータはorg_idおよびuser_idです。
  • ERC-1155標準を使用するトークンの場合、パラメータはorgIdおよびuserIdです。
  • ERC-721標準およびTypeScriptプロジェクトを使用する非代替トークンの場合、パラメータはorgIdおよびuserIdです。
  • ERC-721標準およびGoプロジェクトを使用する非代替トークンの場合、パラメータはOrgIdおよびUserIdです。

次の例は、非代替トークン用です。

macOSおよびLinuxでのTypeScriptのadminList配列の例:
'[{"userId":"userid", "orgId":"OrgMSPId"}]'
macOSおよびLinuxでのGoのadminList配列の例:
'[{"UserId":"userid", "OrgId":"OrgMSPId"}]'
Microsoft WindowsでのTypeScriptのadminList配列の例:
"[{\"userId\":\"userid\", \"orgId\":\"OrgMSPId\"}]"
Microsoft WindowsでのGoのadminList配列の例:
"[{\"UserId\":\"userid\", \"OrgId\":\"OrgMSPId\"}]"

ローカルHyperledger Fabricネットワークの場合、OrgMSPIdフィールドは値Org1MSPに固定されます。

デバッグ・ログを表示するには、--debugオプションをコマンドに渡します。Windowsでは、--debugオプションを指定する場合は、PowerShellのかわりにコマンド・プロンプトを使用します。--portオプションをコマンドに渡すことで、基本ネットワークを実行し、チェーンコードをデフォルトとは異なるポートにデプロイできます。

検証

次のログは、チェーンコードが正常にインストールおよびデプロイされたことを示しています。

my-mac:TSProject myname$ ochain run
Recreating orderer.example.com ... done
Recreating ca.example.com ... done
Recreating peer0.org1.example.com ... done
[2020-09-23T18: 04:09.132] [INFO] default -
============ Started Install Chaincode ============
[2020-09-23T18:04:09.193] [INFO] default Chaincode TSProject:l not installed.
[2020-09-23T18:04:09.317] [INFO] default - Successfully sent install Proposal and received ProposalResponse
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.317] [INFO] default -
============ Finished Install Chaincode ============
[2020-09-23T18:04:09.317] [INFO] default - Successfully installed chaincode TSProject
[2020-09-23T18:04:09.318] [INFO] default -
============ started instantiate Chaincode ============
[2020-09-23T18:04:09.366] [INFO] default - Successfully sent Proposal and received ProposalResponse
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction has been committed on peer localhost:7051
[2020-09-23T18:04:11.434] [INFO] default - The chaincode instantiate transaction was valid.
[2020-09-23T18:04:11.435] [INFO] default - Successfully sent transaction to the orderer.
[2020-09-23T18:04:11.435] [INFO] default - Successfully instantiated chaincode TSProject on channel mychannel
[2020-09-23T18:04:11.435] [INFO] default - 
============ Finished instantiate Chaincode ============
[2020-09-23T18:04:11.4351 INFO] default - Successfully instantiated chaincode TSProject on channel mychannel 
INFO (Runtime): Chaincode TSProject installed and ready:
INFO (RunCommand): Chaincode TSProject deployed

トラブル・シューティング

ローカル・ネットワークでチェーンコード・プロジェクトを実行するときに、次の問題が発生する可能性があります。

Go権限の欠落
Goチェーンコード・プロジェクトのローカル・ネットワークへのインストール時に、次のようなエラーが表示される場合があります:
Starting ca.example.com    ... done
Starting orderer.example.com ... done
Starting peer0.orgl.example.com ... done
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

Stopping peer0.orgl.exmple.com ... done 
Stopping ca.example.com	... done
Stopping orderer.example.con ... done
これは、Goに対する権限がないことが原因です。このエラーはMac OSでのみ表示されています。これは既知の問題です。
解答: 次のコマンドを使用して、$GOROOTディレクトリの権限を変更し、ochain runコマンドを再試行します。
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
これは、ピア・コンテナが正しく再起動できないことが原因です。
解決策: ochain runコマンドを再実行しますが、-bオプションを指定します。このオプションでは、ランタイムが自動的に再構築されます。
ochain run -b
環境の再構築が必要な場合
チャネルが見つからないというエラーまたは次のテキストのようなエラーが表示された場合は、環境を再構築します:
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
ローカル環境を再構築するには、次のコマンドを実行します:
ochain run -b

リモートOracle Blockchain Platformネットワークへのチェーンコードのデプロイ

チェーンコード・プロジェクトがローカル・ネットワークにデプロイしてテストされ、設計どおりに動作することを確認した後、Oracle Blockchain Platformにデプロイできます。

チェーンコードのデプロイ

使用方法: ochain deploy [options] [...args]

ochain deployコマンドでは、次の引数およびオプションを使用できます:

ochain deploy -h 
Usage: deploy [options] [...args]
Deploy chaincode project to Oracle Blockchain Platform

Arguments:
     [...args]    (optional) Chaincode instantiate arguments. Arguments should be space separated.
 
Options :
    -h, --help                      output command usage information
    -D, --debug                     enable debug logging
    -P, --project <project>         (optional) Path to Chaincode project to deploy. If not specified, it defaults to current directory.
    -c, --channel <channel>         (optional) Blockchain Channel to deploy chaincode to. If not specified, it defaults to the 'default' channel.
    -u, --username <username>       (required) A user name that has install chaincode privileges. Contact your administrator for more details.
    -v, --userversion <userversion> (optional) A user-specified chaincode version.
                             If a version isn't specified, for a new chaincode it will start at v1 and then increment to v2, v3, and so on.
                             For an existing chaincode, v1.a will increment to v1.a1, v1 will increment to v2, and v1.0 will increment to v1.1.
    -s --sign <password>            (required) Password to authenticate user.
    -r, --url <url>                 (required) Restproxy Url of the remote OBP instance.
    For example,
    OBP Cloud Services: https://test-xyz-abc.blockchain.ocp.oraclecloud.com:7443/restproxy
    OBP Enterprise Edition: https://restproxy.test-xyz-abc.blockchain.platform.com:443/restproxy

Examples:
$> ochain deploy -u <username> -s <password> -r <REST proxy URL of the remote instance> -c <name of the channel>

ADMINまたはREST_CLIENTロールを持つOracle Blockchain PlatformユーザーのOracle Identity Cloud Serviceユーザー名とパスワードを入力します。ユーザーおよびロールの詳細は、Oracle Blockchain Platformの管理ユーザーおよびアプリケーション・ロールの設定を参照してください。

チェーンコードを呼び出すには、REST_CLIENTロールのみが必要です。チェーンコードをデプロイまたはアップグレードするには、Identity Cloud ServiceユーザーにADMINロールも割り当てられている必要があります。

チェーンコードがリモートのOracle Blockchain Platformに正常にデプロイされた後に、ログに次のイベントが発生したことが示されます:
  • Oracle Blockchain Platformの詳細が正常にフェッチされました。
  • ピアのリストが正常にフェッチされました。
  • チェーンコード・プロジェクトが正常にインストールされました。
  • チェーンコード・プロジェクトが正常に承認およびコミットされました。
  • チェーンコードが、各ピアおよびチャネルに正常にデプロイされました。

複数の組織を持つ環境では、参加者インスタンスを介して同じチャネルにチェーンコードを再度デプロイするために、コンソールを使用してチェーンコードをデプロイします。

チェーンコード・プロジェクトのアップグレード

チェーンコードのアップグレードは、ブロックチェーン・アプリケーション・ビルダーによって自動的に処理されます。チェーンコードを変更した後、ochain deployコマンドを再度コールします。これにより、プロジェクトが自動的にアップグレードされます。ochain deployコマンドを再度実行する場合は、adminListパラメータに空の配列を指定するか、adminListパラメータを使用してトークン管理者の追加を行います。初回デプロイヤでない場合は、adminListパラメータに空の配列を指定する必要があります。

アップグレードが成功すると、次のイベントが発生したことがログに示されます:
  • Oracle Blockchain Platformの詳細が正常にフェッチされました。
  • ピアのリストが正常にフェッチされました。
  • チェーンコード・プロジェクトがすでにインストールされているかどうかが確認され、インストールされている場合はバージョンがフェッチされました。
  • チェーンコード・バージョンが正常にアップグレードされました(たとえば、バージョン1.0から2.0へ)。

複数の組織がある環境では、チェーンコードをアップグレードするには、コンソールを使用し、参加者のチェーンコードを手動で承認します。

Oracle Blockchain Platformへの手動デプロイメント用のチェーンコード・プロジェクトのパッケージ化

チェーンコード・プロジェクトをパッケージ化して、Oracle Blockchain Platform CloudまたはEnterprise Editionに手動でデプロイできます。

使用方法: ochain package

packageコマンドは、ビルドおよび配布ファイルのみを含むアーカイブ・ファイルを作成します。チェーンコード・プロジェクトのbinarylibsnode_modulesおよびtestフォルダは含まれません。このアーカイブ・ファイルは、デプロイメントのためにOracle Blockchain Platformに手動でアップロードできます。

ソフトウェアの前提条件が変更されたため、TypeScriptチェーンコードに対してochain packageコマンドを実行すると、パッケージを作成するOracle Blockchain Platformインスタンスのプロビジョニング日の入力を求められます。ブロックチェーン・アプリケーション・ビルダーで作成されたTypeScriptチェーンコードには、基盤となるインフラストラクチャを変更しないかぎり、以前のバージョンのOracle Blockchain Platformとの互換性がありません。ブロックチェーン・アプリケーション・ビルダーは、選択した内容に応じてチェーンコード・インフラストラクチャをパッケージ化します。

ochain package -h 
Usage: package [options]
Package and archive an Ochain chaincode project 
Options :
    -h, --help             output command usage information
    -D, --debug            enable debug logging
    -p, --project <path>   Path to the Ochain chaincode project to be packaged. If not specified, it defaults to current directory.
    -o, --out <path>       Path to the generated chaincode archive file. If not specified, it defaults to current directory.
About:
This CLI command packages and archives an existing chaincode project 
Examples:
$> ochain package --project <Path to the Ochain chaicode project> —out <Path to the generated chaincode archive file>

コマンドが正常に完了すると、パッケージの場所が返されます。

このコマンドは次の2つのオプションの引数を使用します:
  • --project

    このオプションは、パッケージ化するブロックチェーン・アプリケーション・ビルダーのチェーンコード・プロジェクトの場所を定義します。指定しない場合は、デフォルトで現在のディレクトリが使用されます。

  • --out

    このオプションを使用すると、生成されたアーカイブ・ファイルの出力パスを指定できます。指定しない場合は、デフォルトで現在のディレクトリが使用されます。

次に例を示します:
ochain package -p /Blockchain/DevTools/bp1/CC -o /Blockchain/DevTools/bp1/output

"Your chaincode project has been packaged at /Blockchain/DevTools/bp1/output/CC.zip"