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

Improve experience around devchain resets #170

Merged
merged 3 commits into from
Aug 13, 2018
Merged
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
25 changes: 20 additions & 5 deletions src/commands/devchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ exports.task = async function ({ port = 8545, reset = false, showAccounts = 2 })
title: 'Starting a local chain from snapshot',
task: async (ctx, task) => {
const server = ganache.server({
// Start on a different networkID every time to avoid Metamask nonce caching issue:
// https://github.com/aragon/aragon-cli/issues/156
network_id: parseInt(1e8 * Math.random()),
gasLimit: BLOCK_GAS_LIMIT,
mnemonic: MNEMONIC,
db_path: snapshotPath,
network_id: 15, // aragen uses network_id 15 when creating snapshot https://github.com/aragon/aragen/blob/3df0d65a9de7bbdeeea763a444e0ab367db366a0/scripts/start-ganache#L6
})
const listen = () => (
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -88,8 +90,10 @@ exports.task = async function ({ port = 8545, reset = false, showAccounts = 2 })
}

exports.printAccounts = (reporter, privateKeys) => {
const firstAccountComment = '(this account is used to deploy DAOs, it has more permissions)'

const formattedAccounts = privateKeys.map(({ address, key }, i) =>
chalk.bold(`Address #${i + 1}: ${address}\nPrivate key: `) + key
chalk.bold(`Address #${i + 1}: ${address} ${ i == 0 ? firstAccountComment : ''}\nPrivate key: `) + key
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like there's an extra space now at the start of the address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vanity feature: addresses and private keys are horizontally aligned to the left now (rather than unaligned by one char).

)

reporter.info(`Here are some Ethereum accounts you can use.
Expand All @@ -99,13 +103,24 @@ exports.printAccounts = (reporter, privateKeys) => {
}

exports.printMnemonic = (reporter, mnemonic) => {
reporter.info(`The accounts were generated from the following mnemonic phrase: ${mnemonic}\n.`)
reporter.info(`The accounts were generated from the following mnemonic phrase:\n${mnemonic}\n`)
}

exports.printResetNotice = (reporter, reset) => {
if (reset) {
reporter.warning(`The devchain was reset, some steps need to be done to prevent issues:
- Reset the application cache in Aragon Core by going to Settings > Troubleshooting.
- If using Metamask: switch to a different network, and then switch back to the 'Private Network' (this will clear the nonce cache and prevent errors when sending transactions)
`)
}
}

exports.handler = async ({ reporter, port, reset, accounts }) => {
const task = await exports.task({ port, reset, showAccounts: accounts })
const { privateKeys } = await task.run()
exports.printAccounts(reporter, privateKeys)
const { privateKeys, mnemonic } = await task.run()
exports.printAccounts(reporter, privateKeys)
exports.printMnemonic(reporter, mnemonic)
exports.printResetNotice(reporter, reset)

reporter.info(`Devchain running: ${chalk.bold('http://localhost:'+port)}.`)
}
3 changes: 3 additions & 0 deletions src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ exports.handler = function ({
if (ctx.privateKeys) {
devchain.printAccounts(reporter, ctx.privateKeys)
}

if (ctx.mnemonic) {
devchain.printMnemonic(reporter, ctx.mnemonic)
}

devchain.printResetNotice(reporter, reset)

const registry = module.appName.split('.').slice(1).join('.')

console.log()
Expand Down