Skip to content

Commit

Permalink
temp: bdk cluster generate
Browse files Browse the repository at this point in the history
  • Loading branch information
kidneyweakx committed Jan 17, 2024
1 parent 34b4255 commit ce2f3d7
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 198 deletions.
164 changes: 93 additions & 71 deletions src/quorum/command/cluster/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,86 +28,108 @@ export const handler = async (argv: Arguments<OptType>) => {
const cluster = new Cluster(config)
const wallet = new Wallet()

// network create
const networkCreate: NetworkCreateType = await (async () => {
if (argv.interactive) {
const { chainId, validatorNumber, memberNumber } = await prompts([
{
type: 'number',
name: 'chainId',
message: 'What is your chain id?',
min: 0,
initial: 81712,
},
{
type: 'number',
name: 'validatorNumber',
message: 'How many validator do you want?',
min: 1,
initial: 4,
},
{
type: 'number',
name: 'memberNumber',
message: 'How many member do you want?',
min: 0,
initial: 0,
},
], { onCancel })
const confirm: boolean = await (async () => {
const fileList = cluster.getHelmChartFiles()
if (fileList.length !== 0) {
const confirmDelete = (await prompts({
type: 'confirm',
name: 'value',
message: '⚠️ Detecting quorum nodes already exists. The following processes will remove all existing files. Continue?',
initial: false,
}, { onCancel })).value
if (confirmDelete) {
const spinner = ora('Quorum Network Create ...').start()
cluster.removeHelmChartFiles()
spinner.succeed('Remove all existing files!')
}
return confirmDelete
} else {
return true
}
})()

const { walletOwner } = await prompts({
type: 'select',
name: 'walletOwner',
message: 'Do you already own a wallet?',
choices: [
if (confirm) {
// network create
const networkCreate: NetworkCreateType = await (async () => {
if (argv.interactive) {
const { chainId, validatorNumber, memberNumber } = await prompts([
{
type: 'number',
name: 'chainId',
message: 'What is your chain id?',
min: 0,
initial: 81712,
},
{
title: 'true',
value: true,
type: 'number',
name: 'validatorNumber',
message: 'How many validator do you want?',
min: 1,
initial: 4,
},
{
title: 'false',
value: false,
type: 'number',
name: 'memberNumber',
message: 'How many member do you want?',
min: 0,
initial: 0,
},
],
initial: 1,
})
], { onCancel })

const { walletOwner } = await prompts({
type: 'select',
name: 'walletOwner',
message: 'Do you already own a wallet?',
choices: [
{
title: 'true',
value: true,
},
{
title: 'false',
value: false,
},
],
initial: 1,
})

let walletAddress: string
let walletAddress: string

if (walletOwner) {
const { address } = await prompts({
type: 'text',
name: 'address',
message: 'What is your wallet address?',
validate: walletAddress => ethers.utils.isAddress(walletAddress) ? true : 'Address not valid.',
}, { onCancel })
if (walletOwner) {
const { address } = await prompts({
type: 'text',
name: 'address',
message: 'What is your wallet address?',
validate: walletAddress => ethers.utils.isAddress(walletAddress) ? true : 'Address not valid.',
}, { onCancel })

walletAddress = address
walletAddress = address
} else {
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM)
walletAddress = address
ora().stopAndPersist({
text: `Your ${WalletType.ETHEREUM} wallet address: 0x${walletAddress}`,
symbol: '🔑',
})
ora().stopAndPersist({
text: `Wallet private key: ${privateKey}`,
symbol: '🔑',
})
}

const alloc = [{
account: walletAddress,
amount: '1000000000000000000000000000',
}]

return { chainId, validatorNumber, memberNumber, alloc }
} else {
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM)
walletAddress = address
ora().stopAndPersist({
text: `Your ${WalletType.ETHEREUM} wallet address: 0x${walletAddress}`,
symbol: '🔑',
})
ora().stopAndPersist({
text: `Wallet private key: ${privateKey}`,
symbol: '🔑',
})
return defaultNetworkConfig(address, privateKey)
}

const alloc = [{
account: walletAddress,
amount: '1000000000000000000000000000',
}]

return { chainId, validatorNumber, memberNumber, alloc }
} else {
const { address, privateKey } = wallet.createWalletAddress(WalletType.ETHEREUM)
return defaultNetworkConfig(address, privateKey)
}
})()
const spinner = ora('Quorum Network Import ...').start()
await cluster.apply(networkCreate)
spinner.succeed('Quorum Network Import Successfully!')
})()
const spinner = ora('Quorum Network Import ...').start()
await cluster.apply(networkCreate, spinner)
spinner.succeed('Quorum Network Import Successfully!')
}
}
Loading

0 comments on commit ce2f3d7

Please sign in to comment.