diff --git a/cicd/test_script/steps/add-new-peer-org.sh b/cicd/test_script/steps/add-new-peer-org.sh index 1bd573c8..2043e279 100644 --- a/cicd/test_script/steps/add-new-peer-org.sh +++ b/cicd/test_script/steps/add-new-peer-org.sh @@ -68,7 +68,8 @@ sleep 5 # [orgnew] deploy chaincode export_env 'peer' ${PEER_ORG_NAME_ORGNEW} ${PEER_ORG_DOMAIN_ORGNEW} 'peer0' -bdk chaincode deploy -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I -a --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} +bdk chaincode install -l ${CHAINCODE_LABEL} +bdk chaincode approve -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} # [orgnew] install only export_env 'peer' ${PEER_ORG_NAME_ORGNEW} ${PEER_ORG_DOMAIN_ORGNEW} 'peer1' diff --git a/cicd/test_script/steps/chaincode.sh b/cicd/test_script/steps/chaincode.sh index 27d6c03c..f9f4bf41 100644 --- a/cicd/test_script/steps/chaincode.sh +++ b/cicd/test_script/steps/chaincode.sh @@ -3,14 +3,16 @@ bdk chaincode package -n fabcar -v 1 -p ./chaincode/fabcar/go # deploy export_env 'peer' ${PEER_ORG_NAME_ORG0} ${PEER_ORG_DOMAIN_ORG0} 'peer0' -bdk chaincode deploy -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I -a --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} +bdk chaincode install -l ${CHAINCODE_LABEL} +bdk chaincode approve -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} export_env 'peer' ${PEER_ORG_NAME_ORG0} ${PEER_ORG_DOMAIN_ORG0} 'peer1' bdk chaincode install -l ${CHAINCODE_LABEL} export_env 'peer' ${PEER_ORG_NAME_ORG0} ${PEER_ORG_DOMAIN_ORG0} 'peer2' bdk chaincode install -l ${CHAINCODE_LABEL} export_env 'peer' ${PEER_ORG_NAME_ORG1} ${PEER_ORG_DOMAIN_ORG1} 'peer0' -bdk chaincode deploy -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I -a --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} +bdk chaincode install -l ${CHAINCODE_LABEL} +bdk chaincode approve -C ${CHANNEL_NAME} -l ${CHAINCODE_LABEL} -I --orderer ${ORDERER_ORG_URL_ORG0_ORDERER0} export_env 'peer' ${PEER_ORG_NAME_ORG2} ${PEER_ORG_DOMAIN_ORG2} 'peer0' bdk chaincode install -l ${CHAINCODE_LABEL} diff --git a/docs/COMMANDS.md b/docs/COMMANDS.md index 8d0f4ce5..b9c8f0eb 100644 --- a/docs/COMMANDS.md +++ b/docs/COMMANDS.md @@ -122,23 +122,6 @@ Description: 代表環境變數中 BDK_ORG_NAME 的 Peer org 發布 Chaincode | --orderer | string | 選擇 Orderer 同意 Chaincode | | | --peer-addresses | array | 需要簽名的 Peer address | | -### `bdk chaincode deploy` - -Description: 部署 / 更新 Chaincode - -| Options | Type | Description | Required | Default | -| --------------------- | :-----: | -------------------------------------- | :------: | ------- | -| --help | boolean | Show help | | -| --version | boolean | Show version number | | -| -i, --interactive | boolean | 是否使用 Cathay BDK 互動式問答 | | -| -C, --channel-id | string | 選擇欲部署 Chaincode 在的 Channel 名稱 | | -| -l, --chaincode-label | string | Chaincode package 的標籤名稱 | | -| -a, --approve-only | boolean | 是否只需要做到同意的步驟 | | -| -c, --commit-only | boolean | 是否只需要做到部署的步驟 | | -| -I, --init-required | boolean | Chaincode 是否需要初始化 | | -| --orderer | string | 選擇 Orderer 部署 Chaincode | | -| --peer-addresses | array | 需要簽名的 Peer address | | - ### `bdk chaincode install` Description: 安裝 Chaincode diff --git a/docs/EXAMPLE-EN.md b/docs/EXAMPLE-EN.md index b9704287..c5b03e9f 100644 --- a/docs/EXAMPLE-EN.md +++ b/docs/EXAMPLE-EN.md @@ -213,14 +213,16 @@ bdk chaincode package -n fabcar -v 1 -p ./chaincode/fabcar/go # export BDK_HOSTNAME='peer0' # Install and approve chaincode on peer0 in Org1 -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 # export BDK_ORG_NAME='Org2' # export BDK_ORG_DOMAIN='org2.example.com' # export BDK_HOSTNAME='peer0' # Install and approve chaincode on peer0 in Org2 -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 ``` ### Step 3: Install chaincode on peer1 in Org1 @@ -245,7 +247,7 @@ Deploys the chaincode labelled *fabcar_1*. Parameter `-c` is passed to restrict # export BDK_ORG_DOMAIN='org1.example.com' # export BDK_HOSTNAME='peer0' -bdk chaincode deploy -C test -l fabcar_1 -I -c --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:7151 +bdk chaincode commit -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:7151 ``` ### Step 5: Initial chaincode from Org1 @@ -513,7 +515,8 @@ Install and approve the chaincode named fabcar_1. Since we are using the blockch # export BDK_HOSTNAME='peer0' # Install and approve chaincode on peer0 of Org3 -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 # export BDK_ORG_NAME='Org3' # export BDK_ORG_DOMAIN='org3.example.com' diff --git a/docs/EXAMPLE.md b/docs/EXAMPLE.md index 13c43054..5f2197cb 100644 --- a/docs/EXAMPLE.md +++ b/docs/EXAMPLE.md @@ -213,14 +213,16 @@ bdk chaincode package -n fabcar -v 1 -p ./chaincode/fabcar/go # export BDK_HOSTNAME='peer0' # Org1 的 peer0 安裝、同意 Chaincode -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 # export BDK_ORG_NAME='Org2' # export BDK_ORG_DOMAIN='org2.example.com' # export BDK_HOSTNAME='peer0' # Org2 的 peer0 安裝、同意 Chaincode -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 ``` ### Step 3:Org1 的 peer1 安裝 Chaincode @@ -245,7 +247,7 @@ bdk chaincode install -l fabcar_1 # export BDK_ORG_DOMAIN='org1.example.com' # export BDK_HOSTNAME='peer0' -bdk chaincode deploy -C test -l fabcar_1 -I -c --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:7151 +bdk chaincode commit -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:7151 ``` ### Step 5:Org1 初始化 Chaincode @@ -513,7 +515,8 @@ bdk channel join -n test --orderer orderer0.example.com:7050 # export BDK_HOSTNAME='peer0' # Org3 的 peer0 安裝、同意 Chaincode -bdk chaincode deploy -C test -l fabcar_1 -I -a --orderer orderer0.example.com:7050 +bdk chaincode install -l fabcar_1 +bdk chaincode approve -C test -l fabcar_1 -I --orderer orderer0.example.com:7050 # export BDK_ORG_NAME='Org3' # export BDK_ORG_DOMAIN='org3.example.com' diff --git a/src/command/chaincode/deploy.ts b/src/command/chaincode/deploy.ts deleted file mode 100644 index ac0fed3f..00000000 --- a/src/command/chaincode/deploy.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { Arguments, Argv } from 'yargs' -import prompts from 'prompts' -import { logger, onCancel } from '../../util' -import { ChaincodeDeployType } from '../../model/type/chaincode.type' -import Chaincode from '../../service/chaincode' -import Channel from '../../service/channel' -import config from '../../config' -import { getChaincodeList, joinedChannelChoice } from '../../model/prompts/util' - -export const command = 'deploy' - -export const desc = '部署 / 更新 Chaincode' - -interface OptType { - interactive: boolean - channelId: string - chaincodeLabel: string - approveOnly: boolean - commitOnly: boolean - initRequired: boolean - orderer: string - peerAddresses: string[] -} - -const chaincodeList = getChaincodeList(config) -export const builder = (yargs: Argv) => { - return yargs - .example('bdk chaincode deploy --interactive', 'Cathay BDK 互動式問答') - .example('bdk chaincode deploy --channel-id fabcar --chaincode-label test_1 --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:8051', '使用 orderer0.example.com:7050 部署名稱為 test 中標籤為 test_1 的 Chaincode,此 Chaincode 需要初始化並且 Org1 和 Org2 的 Peer org 簽名(包含安裝、同意、部署、初始 Chaincode 步驟)') - .example('bdk chaincode deploy --channel-id fabcar --chaincode-label test_1 --init-required --approve-only --orderer orderer0.example.com:7050', '使用 orderer0.example.com:7050 同意名稱為 test 中標籤為 test_1 的 Chaincode,此 Chaincode 需要初始化(包含安裝、同意 Chaincode 步驟)') - .example('bdk chaincode deploy --channel-id fabcar --chaincode-label test_1 --init-required --commit-only --orderer orderer0.example.com:7050 --peer-addresses peer0.org1.example.com:7051 --peer-addresses peer0.org2.example.com:8051', '使用 orderer0.example.com:7050 部署名稱為 test 中標籤為 test_1 的 Chaincode,此 Chaincode 需要初始化並且 Org1 和 Org2 的 Peer org 簽名(包含安裝、同意、部署 Chaincode 步驟)') - .option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' }) - .option('channel-id', { type: 'string', description: '選擇欲部署 Chaincode 在的 Channel 名稱', alias: 'C' }) - .option('chaincode-label', { type: 'string', description: 'Chaincode package 的標籤名稱', alias: 'l', choices: chaincodeList.map(x => `${x.name}_${x.version}`) }) - .option('approve-only', { type: 'boolean', description: '是否只需要做到同意的步驟', alias: 'a' }) - .option('commit-only', { type: 'boolean', description: '是否只需要做到部署的步驟', alias: 'c' }) - .option('init-required', { type: 'boolean', description: 'Chaincode 是否需要初始化', alias: 'I' }) - .option('orderer', { type: 'string', description: '選擇 Orderer 部署 Chaincode' }) - .option('peer-addresses', { type: 'array', description: '需要簽名的 Peer address' }) -} - -export const handler = async (argv: Arguments) => { - logger.debug('exec chaincode deploy') - - const chaincode = new Chaincode(config) - const channel = new Channel(config) - - let deployChannelInput: ChaincodeDeployType - const chaincodeVersionMap: Map = new Map() - chaincodeList.forEach(chaincode => { - chaincodeVersionMap.set(chaincode.name, [...(chaincodeVersionMap.get(chaincode.name) || []), chaincode.version]) - }) - if (argv.interactive) { - const { channelId, chaincodeName } = await prompts([ - { - type: 'select', - name: 'channelId', - message: 'Which channel do you want deploy chaincode', - choices: await joinedChannelChoice(channel), - }, - { - type: 'select', - name: 'chaincodeName', - message: 'What is your chaincode name?', - choices: Array.from(chaincodeVersionMap.keys()).map(x => ({ - title: x, - value: x, - })), - }, - ], { onCancel }) - const { chaincodeVersion, initRequired, approveOrCommit } = await prompts([ - { - type: 'select', - name: 'chaincodeVersion', - message: 'What is your chaincode version?', - choices: (chaincodeVersionMap.get(chaincodeName) || []).sort((a, b) => (a - b)).map(x => ({ - title: x.toString(), - value: x, - })), - }, - { - type: 'select', - name: 'initRequired', - message: 'Whether the chaincode requires invoking \'init\'', - choices: [ - { - title: 'true', - value: true, - }, - { - title: 'false', - value: false, - }, - ], - - }, - { - type: 'multiselect', - name: 'approveOrCommit', - message: 'Do approve or do commit?', - choices: [ - { - title: 'Do approve', - value: 'approve', - }, - { - title: 'Do commit', - value: 'commit', - }, - ], - }, - ], { onCancel }) - - const channelGroup = await channel.getChannelGroup(channelId) - - const { orderer } = await prompts([ - { - type: 'select', - name: 'orderer', - message: 'Ordering service endpoint', - choices: channelGroup.orderer.map(x => ({ - title: x, - value: x, - })), - }, - ], { onCancel }) - const peerAddresses = approveOrCommit.includes('commit') - ? (await prompts([{ - type: 'multiselect', - name: 'peerAddresses', - message: 'The addresses of the peers to connect to', - choices: channelGroup.anchorPeer.map(x => ({ - title: x, - value: x, - })), - }], { onCancel })).peerAddresses - : [] - - deployChannelInput = { - channelId, - chaincodeName, - chaincodeVersion, - approve: approveOrCommit.includes('approve'), - commit: approveOrCommit.includes('commit'), - initRequired, - orderer, - peerAddresses, - } - } else { - deployChannelInput = { - channelId: argv.channelId, - chaincodeName: argv.chaincodeLabel.split('_')[0], - chaincodeVersion: parseInt(argv.chaincodeLabel.split('_')[1].split('.')[0], 10), - approve: argv.approveOnly || (!argv.commitOnly), - commit: argv.commitOnly || (!argv.approveOnly), - initRequired: argv.initRequired, - orderer: argv.orderer, - peerAddresses: argv.peerAddresses, - } - } - - if (deployChannelInput.approve) { - const chaincodeLabel = `${deployChannelInput.chaincodeName}_${deployChannelInput.chaincodeVersion}` - await chaincode.install({ chaincodeLabel }) - await chaincode.approve({ - channelId: deployChannelInput.channelId, - chaincodeName: deployChannelInput.chaincodeName, - chaincodeVersion: deployChannelInput.chaincodeVersion, - initRequired: deployChannelInput.initRequired, - orderer: deployChannelInput.orderer, - }) - } - if (deployChannelInput.commit) { - await chaincode.commit({ - channelId: deployChannelInput.channelId, - chaincodeName: deployChannelInput.chaincodeName, - chaincodeVersion: deployChannelInput.chaincodeVersion, - initRequired: deployChannelInput.initRequired, - orderer: deployChannelInput.orderer, - peerAddresses: deployChannelInput.peerAddresses || [], - }) - } -} diff --git a/src/command/chaincode/package.ts b/src/command/chaincode/package.ts index db64f318..23952f39 100644 --- a/src/command/chaincode/package.ts +++ b/src/command/chaincode/package.ts @@ -27,7 +27,7 @@ export const builder = (yargs: Argv) => { } export const handler = async (argv: Arguments) => { - logger.debug('exec chaincode deploy') + logger.debug('exec chaincode package') const chaincode = new Chaincode(config) diff --git a/src/index.ts b/src/index.ts index a7065558..587cf193 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,7 @@ export { export { AbstractService, ParserType } from './service/Service.abstract' export { CaUpType, CaDownType, CaIntermediateType, CaCsrType, CaEnrollCommandTypeEnum, CaEnrollTypeEnum, CaRegisterTypeEnum, CaEnrollType, CaRegisterType, CaBasicType, CaCryptoType, CaSigningType } from './model/type/caService.type' -export { ChaincodePackageType, ChaincodeApproveType, ChaincodeCommitType, ChaincodeDeployType, ChaincodeQueryType, ChaincodeInvokeType, ChaincodeInstallType } from './model/type/chaincode.type' +export { ChaincodePackageType, ChaincodeApproveType, ChaincodeCommitType, ChaincodeQueryType, ChaincodeInvokeType, ChaincodeInstallType } from './model/type/chaincode.type' export { PolicyTypeEnum, PolicyStyleEnum, ChannelPolicyType, ChannelCreateType, ChannelJoinType, ChannelUpdateAnchorPeerType, ConfigtxlatorEnum, ChannelCreateChannelConfigComputeType, ChannelCreateChannelConfigSignType, ChannelCreateChannelConfigUpdateType, ChannelConfigEnum, ChannelFetchBlockType, ChannelApproveType, ChannelUpdateType, DecodeEnvelopeType, EnvelopeTypeEnum, EnvelopeVerifyEnum as EnvelopeVerifyENum, DecodeEnvelopeReturnType } from './model/type/channel.type' export { ConfigEnvType, ConfigSetType } from './model/type/config.type' export { DiscoverPeersType, DiscoverChannelConfigType, DiscoverChaincodeEndorsersType, DiscoverPeersResultType, DiscoverChannelConfigResultType, DiscoverChaincodeEndorsersResultType } from './model/type/discover.type' diff --git a/src/model/type/chaincode.type.ts b/src/model/type/chaincode.type.ts index a9cae20d..1def036b 100644 --- a/src/model/type/chaincode.type.ts +++ b/src/model/type/chaincode.type.ts @@ -50,26 +50,6 @@ export interface ChaincodeCommitType { peerAddresses: string[] } -/** - * @requires channelId - [string] channel 的名稱 - * @requires label - [string] chaincode 的標籤名稱 - * @requires approve - [boolean] 是否只做到同意的步驟 - * @requires commit - [boolean] 是否只做到發布的步驟 - * @requires initRequired - [boolean] 是否需要初始化 chaincode - * @requires orderer - [string] orderer 的 address 和 port - * @requires peerAddresses - [string array] peer address 和 port 的 array - */ -export interface ChaincodeDeployType { - channelId: string - chaincodeName: string - chaincodeVersion: number - approve: boolean - commit: boolean - initRequired: boolean - orderer: string - peerAddresses?: string[] -} - /** * @requires channelId - [string] channel 的名稱 * @requires chaincodeName - [string] chaincode 的名稱