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
トークン・プロジェクト
ochain run
コマンドを使用して管理のリストを指定する必要があります:
ochain run <adminList array>
adminList
配列は、トークン管理者を指定する情報の配列です。トークン・チェーンコード・プロジェクトを初めてデプロイする場合、adminList
配列は必須パラメータです。プロジェクトを再度デプロイする場合は、adminList
パラメータに空の配列を渡すか、adminList
パラメータを使用してトークン管理者を追加できます。初めてデプロイするデプロイヤではない他のデプロイヤは、adminList
パラメータに空の配列を指定する必要があります。パラメータ情報は、fungibleトークンとnon-fungibleトークンでは異なります。
- トークン・タクソノミ・フレームワーク標準を使用する実行可能なトークンの場合、パラメータは
org_id
およびuser_id
です。 - ERC-1155標準を使用するトークンの場合、パラメータは
orgId
およびuserId
です。 - ERC-721標準およびTypeScriptプロジェクトを使用する非真菌トークンの場合、パラメータは
orgId
およびuserId
です。 - ERC-721標準およびGoプロジェクトを使用する非fungibleトークンの場合、パラメータは
OrgId
およびUserId
です。
次の例は、fungible以外のトークン用です。
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) URL of the remote OBP instance. Example: https://<blockchain-instance-url>:7443/
Examples:
$> ochain deploy -u <username> -s <password> -r <url of the remote OBP instance> -c <name of the channel>
ADMIN
またはREST_CLIENT
ロールを持つOracle Blockchain PlatformユーザーのOracle Identity Cloud Serviceのユーザー名とパスワードを入力します。ユーザーおよびロールの詳細は、ユーザーおよびアプリケーション・ロールの設定を参照してください。
チェーンコードを起動するには、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"