-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new command
bdk channel decode-envelop
- Loading branch information
Showing
10 changed files
with
235 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import prompts from 'prompts' | ||
import { Arguments, Argv } from 'yargs' | ||
import { logger, onCancel, ParamsError } from '../../util' | ||
import config from '../../config' | ||
import Channel from '../../service/channel' | ||
import { getChannelEnvelopeList } from '../../model/prompts/util' | ||
import { EnvelopeTypeEnum } from '../../model/type/channel.type' | ||
|
||
export const command = 'decode-envelope' | ||
|
||
export const desc = '解析 Approve 或 Update 的信封內容' | ||
|
||
interface OptType { | ||
interactive: boolean | ||
channelName: string | ||
} | ||
|
||
const channelEnvelopeList = getChannelEnvelopeList(config) | ||
|
||
export const builder = (yargs: Argv<OptType>) => { | ||
return yargs | ||
.example('bdk channel decode-envelope --interactive', 'Cathay BDK 互動式問答') | ||
.example('bdk channel decode-envelope --channel-name test', '解析 channel test 的更動資訊') | ||
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' }) | ||
.option('channel-name', { type: 'string', choices: channelEnvelopeList, description: 'Channel 的名稱', alias: 'c' }) | ||
} | ||
|
||
export const handler = async (argv: Arguments<OptType>) => { | ||
const channel = new Channel(config) | ||
|
||
const channelName: string = await (async () => { | ||
if (argv.interactive) { | ||
return (await prompts([ | ||
{ | ||
type: 'select', | ||
name: 'channelName', | ||
message: 'What is your channel name?', | ||
choices: channelEnvelopeList.map(x => ({ | ||
title: x, | ||
value: x, | ||
})), | ||
}, | ||
], { onCancel })).channelName | ||
} else if (argv.channelName) { | ||
return argv.channelName | ||
} else { | ||
throw new ParamsError('Invalid params: Required parameter missing <channel-name>') | ||
} | ||
})() | ||
|
||
const decodeResult = (await channel.decodeEnvelope({ channelName })) | ||
logger.info(`Approved org: ${decodeResult.approved.toString()}`) | ||
switch (decodeResult.type) { | ||
case EnvelopeTypeEnum.ADD_PEER_TO_SYSTEM_CHANNEL: | ||
case EnvelopeTypeEnum.ADD_PEER_TO_APPLICATION_CHANNEL: | ||
logger.info(`Add peer org "${decodeResult.org}" into channel`) | ||
logger.info(`Verify: ${decodeResult.verify}`) | ||
break | ||
case EnvelopeTypeEnum.ADD_ORDERER_TO_CHANNEL: | ||
logger.info(`Add orderer org "${decodeResult.org}" into channel`) | ||
logger.info(`Verify: ${decodeResult.verify}`) | ||
break | ||
case EnvelopeTypeEnum.UPDATE_ANCHOR_PEER: | ||
logger.info(`Update anchor peer of peer org "${decodeResult.org}": ${decodeResult.anchorPeers}`) | ||
break | ||
case EnvelopeTypeEnum.ADD_ORDERER_CONSENTER: | ||
logger.info(`Update consenter: ${decodeResult.consensus}`) | ||
break | ||
default: | ||
break | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.