CLIを使用したチェーンコードのデプロイ
チェーンコード・プロジェクトが作成されると、自動的に生成されたHyperledger Fabricネットワークにローカルにデプロイするか、Oracle Blockchain Platform CloudまたはEnterprise Editionにリモートにデプロイできます。チェーンコード・プロジェクトをパッケージ化して、Oracle Blockchain Platformに手動でデプロイすることもできます。
ローカルHyperledger Fabricネットワークへのチェーンコードのデプロイ
チェーンコード・プロジェクトを作成したら、ローカルHyperledger Fabricネットワークにデプロイできます。この単一チャネル・テスト・ネットワークは、ブロックチェーン・アプリケーション・ビルダーのインストール時に作成されます。
ブロックチェーン・アプリケーション・ビルダーのochain run
コマンドは、Hyperledger Fabricネットワークおよびその他のサービスを起動し、チェーンコードをインストールしてデプロイします。
my-mac:GOProject myname$ 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
です。
次の例は、非代替トークン用です。
adminList
配列の例:'[{"userId":"userid", "orgId":"OrgMSPId"}]'
adminList
配列の例:'[{"UserId":"userid", "OrgId":"OrgMSPId"}]'
adminList
配列の例:"[{\"userId\":\"userid\", \"orgId\":\"OrgMSPId\"}]"
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チェーンコード・プロジェクトをローカル・ネットワークにインストール中に、次のようなエラーが表示される場合があります:
My-Mac:GoProj myname$ ochain run 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
- デプロイメントの失敗
- デプロイメントの失敗、デプロイメントの破損、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にデプロイできます。
チェーンコードのデプロイ
使用方法: ochain deploy [options] [...args]
ochain deploy
コマンドでは、次の引数およびオプションを使用できます:
my-mac:TSProject myname$ 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 Enterprise Editionの管理』のユーザーおよびアプリケーション・ロールの設定に関する項を参照してください。
チェーンコードを呼び出すには、REST_CLIENT
ロールのみが必要です。チェーンコードをデプロイまたはアップグレードするには、IDCSユーザーにADMIN
ロールも割り当てられている必要があります。
- 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
コマンドは、ビルドおよび配布ファイルのみを含むアーカイブ・ファイルを作成します。チェーンコード・プロジェクトのbinary
、libs
、node_modules
およびtest
フォルダは含まれません。このアーカイブ・ファイルは、デプロイメントのためにOracle Blockchain Platformに手動でアップロードできます。
ソフトウェアの前提条件が変更されたため、TypeScriptチェーンコードに対してochain package
コマンドを実行すると、パッケージを作成するOracle Blockchain Platformインスタンスのプロビジョニング日の入力を求められます。ブロックチェーン・アプリケーション・ビルダーで作成されたTypeScriptチェーンコードは、基盤となるインフラストラクチャを変更しないかぎり、以前のバージョンのOracle Blockchain Platformと互換性がありません。ブロックチェーン・アプリケーション・ビルダーは、選択した内容に応じてチェーンコード・インフラストラクチャをパッケージ化します。
my-mac:~ myname$ 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>
コマンドが正常に完了すると、パッケージの場所が返されます。
--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"