Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: besu network update #111

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"statements": 0,
"include": [
"src/fabric/service/**.ts",
"src/quorum/service/**.ts",
"src/eth/service/**.ts",
"src/wallet/service/**.ts"
],
"exclude": [
"src/fabric/service/Service.abstract.ts",
"src/quorum/service/Service.abstract.ts",
"src/quorum/service/network.ts"
"src/eth/service/Service.abstract.ts",
"src/eth/service/network.ts"
],
"reporter": [
"text-summary",
Expand Down
2 changes: 1 addition & 1 deletion src/bdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const argv = yargs
return true
})
.commandDir('fabric')
.commandDir('quorum')
.commandDir('eth')
.commandDir('wallet')
.commandDir('hello')
.commandDir('dashboard')
Expand Down
2 changes: 1 addition & 1 deletion src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (npmBuild.status !== 0) { console.error(`${npmBuild.output[1]}`); console.err
* copy helm chart file
*/
console.log('[*] exec spawnSync: copy helm chart file')
const cp = spawnSync('cp', ['-r', 'src/quorum/instance/infra/kubernetes/charts', 'dist/quorum/instance/infra/kubernetes'])
const cp = spawnSync('cp', ['-r', 'src/eth/instance/infra/kubernetes/charts', 'dist/eth/instance/infra/kubernetes'])
console.log(`[+] child process exited with code ${cp.status}`)
if (cp.status !== 0) { console.error('\x1b[31m%s\x1b[0m', cp.stderr); exit(0) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Argv } from 'yargs'

export const command = 'backup'

export const desc = '管理 Quorum backup 的指令'
export const desc = '管理 Eth Network backup 的指令'

export const builder = (yargs: Argv) => {
return yargs.commandDir('backup').demandCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@ import Backup from '../../service/backup'
import { onCancel, ParamsError, ProcessError } from '../../../util/error'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices } from '../../config/network.type'

export const command = 'export'

export const desc = '匯出現有的 Quorum Network'
export const desc = '匯出現有的 Eth Network'

interface OptType {
interactive: boolean
}

export const builder = (yargs: Argv<OptType>) => {
return yargs
.example('bdk quorum backup export --interactive', 'Cathay BDK 互動式問答')
.example('bdk quorum backup export --all', '備份 BDK 資料夾下所有 Quorum Network 資料')
.example('bdk eth backup export --interactive', 'Cathay BDK 互動式問答')
.example('bdk eth backup export --all', '備份所選 BDK 資料夾下所有 Eth Network 資料')
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' })
.option('all', { type: 'boolean', description: '是否備份所有資料', alias: 'a' })
}

export const handler = async (argv: Arguments<OptType>) => {
const backup = new Backup(config)
const { networkType } = await prompts([
{
type: 'select',
name: 'networkType',
message: 'What is your network?',
choices: getNetworkTypeChoices(),
},
])
const networkTypeWithBigFirstLetter = networkType.charAt(0).toUpperCase() + networkType.slice(1)
const backup = new Backup(config, networkType)

if (argv.all) {
const spinner = ora('Quorum Network Export All ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Network Export All ...`).start()
await backup.exportAll()
spinner.succeed('Quorum Network Export All Successfully!')
spinner.succeed(`${networkTypeWithBigFirstLetter} Network Export All Successfully!`)
} else if (argv.interactive) {
const node: string = await (async () => {
const nodeList = backup.getExportItems()
Expand All @@ -43,9 +53,9 @@ export const handler = async (argv: Arguments<OptType>) => {
}
})()

const spinner = ora(`Quorum Network Export ${node} ...`).start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Network Export ${node} ...`).start()
await backup.export(node)
spinner.succeed(`Quorum Network Export ${node} Successfully!`)
spinner.succeed(`${networkTypeWithBigFirstLetter} Network Export ${node} Successfully!`)
} else {
throw new ParamsError('Invalid params: Required parameter missing')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ import Backup from '../../service/backup'
import { onCancel, ParamsError } from '../../../util/error'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices } from '../../config/network.type'

export const command = 'import'

export const desc = '匯入現有的 Quorum Network'
export const desc = '匯入現有的 Eth Network'

interface OptType {
interactive: boolean
}

export const builder = (yargs: Argv<OptType>) => {
return yargs
.example('bdk quorum backup import --interactive', 'Cathay BDK 互動式問答')
.example('bdk eth backup import --interactive', 'Cathay BDK 互動式問答')
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' })
}

export const handler = async (argv: Arguments<OptType>) => {
const backup = new Backup(config)
const { networkType } = await prompts([
{
type: 'select',
name: 'networkType',
message: 'What is your network?',
choices: getNetworkTypeChoices(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊改成這樣,就不需要再轉換大小寫一次了

choices: getNetworkTypeChoices().map(choice => ({
    title: choice.title,
    value: choice.title, 
})),

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成討論,此部分無修改。

},
])
const networkTypeWithBigFirstLetter = networkType.charAt(0).toUpperCase() + networkType.slice(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這行就可以刪掉了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成討論,此部分無修改。

const backup = new Backup(config, networkType)

const archive: string = await (async () => {
const archiveList = backup.getBackupItems()
Expand All @@ -35,7 +45,7 @@ export const handler = async (argv: Arguments<OptType>) => {
throw new ParamsError('Invalid params: Required parameter missing')
}
})()
const spinner = ora('Quorum Network Import ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Network Import ...`).start()
await backup.import(archive)
spinner.succeed('Quorum Network Import Successfully!')
spinner.succeed(`${networkTypeWithBigFirstLetter} Network Import Successfully!`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Argv } from 'yargs'

export const command = 'cluster'

export const desc = '管理 Quorum cluster 的指令'
export const desc = '管理 Eth Network cluster 的指令'

export const builder = (yargs: Argv) => {
return yargs.commandDir('cluster').demandCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@ import { WalletType } from '../../../wallet/model/type/wallet.type'
import { defaultNetworkConfig } from '../../model/defaultNetworkConfig'
import prompts from 'prompts'
import ora from 'ora'

import { getNetworkTypeChoices, NetworkType } from '../../config/network.type'
export const command = 'apply'

export const desc = '產生 Quorum Cluster 所需的相關設定檔案並建立網路'
export const desc = '產生 Eth Network Cluster 所需的相關設定檔案並建立網路'

interface OptType {
interactive: boolean
}

export const builder = (yargs: Argv<OptType>) => {
return yargs
.example('bdk quorum cluster apply --interactive', 'Cathay BDK 互動式問答')
.example('bdk eth network cluster apply --interactive', 'Cathay BDK 互動式問答')
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' })
}

export const handler = async (argv: Arguments<OptType>) => {
const cluster = new Cluster(config)
const { networkType } = await prompts([
{
type: 'select',
name: 'networkType',
message: 'What is your network?',
choices: getNetworkTypeChoices(),
},
]) as { networkType: NetworkType }

const networkTypeWithBigFirstLetter = networkType.charAt(0).toUpperCase() + networkType.slice(1)
const cluster = new Cluster(config, networkType)
const wallet = new Wallet()

const confirm: boolean = await (async () => {
Expand All @@ -34,11 +43,11 @@ export const handler = async (argv: Arguments<OptType>) => {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: '⚠️ Detecting quorum cluster already exists. The following processes will remove all existing files. Continue?',
message: `⚠️ Detecting ${networkTypeWithBigFirstLetter} cluster already exists. The following processes will remove all existing files. Continue?`,
initial: false,
}, { onCancel })).value
if (confirmDelete) {
const spinner = ora('Quorum Cluster Delete ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Cluster Delete ...`).start()
cluster.removeHelmChartFiles()
spinner.succeed('Remove all existing files!')
}
Expand Down Expand Up @@ -157,15 +166,15 @@ export const handler = async (argv: Arguments<OptType>) => {
const isBootNode = false
const bootNodeList: boolean[] = Array(validatorNumber + memberNumber).fill(false)

return { provider, region, chainId, validatorNumber, memberNumber, alloc, isBootNode, bootNodeList }
return { provider, region, chainId, validatorNumber, memberNumber, alloc, isBootNode, bootNodeList, networkType }
} else {
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM)
const config = defaultNetworkConfig(address, privateKey)
return { ...config, provider: 'local' }
const config = defaultNetworkConfig(address, privateKey, networkType)
return { ...config, provider: 'local', networkType }
}
})()
const spinner = ora('Quorum Cluster Apply ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Cluster Apply ...`).start()
await cluster.apply(clusterCreate, spinner)
spinner.succeed('Quorum Cluster Apply Successfully!')
spinner.succeed(`${networkTypeWithBigFirstLetter} Cluster Apply Successfully!`)
}
}
53 changes: 53 additions & 0 deletions src/eth/command/cluster/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Argv } from 'yargs'
import config from '../../config'
import Cluster from '../../service/cluster'
import { onCancel } from '../../../util/error'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices, NetworkType } from '../../config/network.type'

export const command = 'delete'

export const desc = '刪除現有的 Eth Network Cluster 網路'

interface OptType {
interactive: boolean
}

export const builder = (yargs: Argv<OptType>) => {
return yargs
.example('bdk eth network cluster delete', 'Cathay BDK 互動式問答')
}

export const handler = async () => {
const { networkType } = await prompts([{
type: 'select',
name: 'networkType',
message: 'What is your network?',
choices: getNetworkTypeChoices(),
}]) as { networkType: NetworkType }

const networkTypeWithBigFirstLetter = networkType.charAt(0).toUpperCase() + networkType.slice(1)
const cluster = new Cluster(config, networkType)
const confirm: boolean = await (async () => {
const fileList = cluster.getHelmChartFiles()
if (fileList.length !== 0) {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: `⚠️ Detecting ${networkTypeWithBigFirstLetter} cluster already exists. The following processes will remove all existing files. Continue?`,
initial: false,
}, { onCancel })).value
return confirmDelete
} else {
return true
}
})()

if (confirm) {
const spinner = ora(`${networkTypeWithBigFirstLetter} Cluster Delete ...`).start()
await cluster.delete(networkType)
cluster.removeHelmChartFiles()
spinner.succeed(`${networkTypeWithBigFirstLetter} Cluster Delete Successfully!`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ import { defaultNetworkConfig } from '../../model/defaultNetworkConfig'
import { onCancel } from '../../../util/error'
import prompts from 'prompts'
import ora from 'ora'
import { getNetworkTypeChoices, NetworkType } from '../../config/network.type'

export const command = 'generate'

export const desc = '產生 Quorum Cluster 所需的相關設定檔案'
export const desc = '產生 Eth Network Cluster 所需的相關設定檔案'

interface OptType {
interactive: boolean
}

export const builder = (yargs: Argv<OptType>) => {
return yargs
.example('bdk quorum cluster generate --interactive', 'Cathay BDK 互動式問答')
.example('bdk eth network cluster generate --interactive', 'Cathay BDK 互動式問答')
.option('interactive', { type: 'boolean', description: '是否使用 Cathay BDK 互動式問答', alias: 'i' })
}

export const handler = async (argv: Arguments<OptType>) => {
const cluster = new Cluster(config)
const { networkType } = await prompts([
{
type: 'select',
name: 'networkType',
message: 'What is your network?',
choices: getNetworkTypeChoices(),
},
]) as { networkType: NetworkType }

const networkTypeWithBigFirstLetter = networkType.charAt(0).toUpperCase() + networkType.slice(1)
const cluster = new Cluster(config, networkType)
const wallet = new Wallet()

const confirm: boolean = await (async () => {
Expand All @@ -34,11 +45,11 @@ export const handler = async (argv: Arguments<OptType>) => {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: '⚠️ Detecting quorum cluster already exists. The following processes will remove all existing files. Continue?',
message: `⚠️ Detecting ${networkTypeWithBigFirstLetter} cluster already exists. The following processes will remove all existing files. Continue?`,
initial: false,
}, { onCancel })).value
if (confirmDelete) {
const spinner = ora('Quorum Cluster Delete ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Cluster Delete ...`).start()
cluster.removeHelmChartFiles()
spinner.succeed('Remove all existing files!')
}
Expand Down Expand Up @@ -183,16 +194,16 @@ export const handler = async (argv: Arguments<OptType>) => {
const isBootNode = false
const bootNodeList: boolean[] = Array(validatorNumber + memberNumber).fill(false)

return { provider, region, chainId, validatorNumber, memberNumber, alloc, isBootNode, bootNodeList }
return { provider, region, chainId, validatorNumber, memberNumber, alloc, isBootNode, bootNodeList, networkType }
} else {
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM)
const config = defaultNetworkConfig(address, privateKey)
return { ...config, provider: 'local' }
const config = defaultNetworkConfig(address, privateKey, networkType)
return { ...config, provider: 'local', networkType }
}
})()

const spinner = ora('Quorum Cluster Generate ...').start()
const spinner = ora(`${networkTypeWithBigFirstLetter} Cluster Generate ...`).start()
await cluster.generate(clusterGenerate, networkCreate)
spinner.succeed('Quorum Cluster Generate Successfully!')
spinner.succeed(`${networkTypeWithBigFirstLetter} Cluster Generate Successfully!`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Argv } from 'yargs'

export const command = 'explorer'

export const desc = '管理 Quorum explorer 的指令'
export const desc = '管理 Eth Network explorer 的指令'

export const builder = (yargs: Argv) => {
return yargs.commandDir('explorer').demandCommand()
Expand Down
Loading
Loading