CLI를 사용하여 체인코드 배포
체인코드 프로젝트가 생성되면 자동으로 생성된 Hyperledger Fabric 네트워크에 로컬로 배포하거나 Oracle Blockchain Platform Cloud 또는 Enterprise Edition에 원격으로 배포할 수 있습니다. Oracle Blockchain Platform에 수동으로 배포하기 위해 체인코드 프로젝트를 패키지화할 수도 있습니다.
로컬 Hyperledger Fabric 네트워크에 체인코드 배포
체인코드 프로젝트를 생성한 후에는 로컬 Hyperledger Fabric 네트워크에 배포할 수 있습니다. 이 단일 채널 테스트 네트워크는 Blockchain App Builder를 설치할 때 만들어집니다.
Blockchain App Builder 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
매개변수에 대해 빈 배열을 제공해야 합니다. 매개변수 정보는 대체 가능한 토큰 및 비실행 가능한 토큰에 대해 다릅니다.
- 토큰 분류법 프레임워크 표준을 사용하는 대체 가능 토큰의 경우 매개변수는
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
- 환경 재구성 필요
- channel not found 오류 또는 다음 텍스트와 유사한 오류가 표시되는 경우 환경을 재구축합니다.
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 세부정보를 성공적으로 인출했습니다.
- 피어 목록이 성공적으로 인출되었습니다.
- 체인코드 프로젝트가 성공적으로 설치되었습니다.
- 체인코드 프로젝트가 성공적으로 승인 및 커밋되었습니다.
- 체인 코드가 각 피어 및 채널에 성공적으로 배치되었습니다.
여러 조직이 있는 환경에서 참가자 인스턴스를 통해 동일한 채널에 체인코드를 재배포하려면 콘솔을 사용하여 체인코드를 배포합니다.
체인코드 프로젝트 업그레이드
체인코드 업그레이드는 Blockchain App Builder에서 자동으로 처리됩니다. 체인코드를 변경한 후 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 인스턴스의 프로비전 날짜를 묻는 메시지가 표시됩니다. Blockchain App Builder에서 만든 TypeScript 체인코드는 기본 인프라를 변경하지 않고 이전 버전의 Oracle Blockchain Platform과 호환되지 않습니다. Blockchain App Builder는 선택 사항에 따라 체인 코드 인프라를 패키지화합니다.
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
이 옵션은 패키지화할 Blockchain App Builder 체인코드 프로젝트의 위치를 정의합니다. 지정하지 않으면 현재 디렉토리가 위치 기본값으로 설정됩니다.
--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"