Skip to content

Commit

Permalink
Add change-controller command
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwhisperer committed Jan 13, 2019
1 parent 4f9f6be commit fb096ca
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions src/commands/dao_cmds/change-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const TaskList = require('listr')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
const { getContract } = require('../../util')
const listrOpts = require('../../helpers/listr-options')
const chalk = require('chalk')

exports.command = 'change-controller <token-address> <new-controller>'

exports.describe = 'Change the controller of a minime token'

exports.builder = yargs => {
return yargs
.positional('token-address', {
description: 'Address of the MiniMe token',
})
.positional('new-controller', {
description: 'Address of the new controller',
})
}

exports.task = async ({ web3, tokenAddress, newController, silent, debug }) => {
// Decode sender
const accounts = await web3.eth.getAccounts()
const from = accounts[0]

return new TaskList(
[
{
title: 'Changing the MiniMe token controller',
task: async (ctx, task) => {
let artifact = getContract('@aragon/os', 'MiniMeToken')
let contract = new web3.eth.Contract(artifact.abi, tokenAddress)

const tx = contract.methods.changeController(newController)
// this fails if from is not passed
const gas = await tx.estimateGas({ from })

const sendPromise = tx.send({ from, gas })
sendPromise
.on('transactionHash', transactionHash => {
ctx.txHash = transactionHash
})
.on('error', function(error) {
throw error
})

task.output = `Waiting for the transaction to be mined...`
return sendPromise
},
},
],
listrOpts(silent, debug)
)
}

exports.handler = async function({
reporter,
network,
tokenAddress,
newController,
silent,
debug,
}) {
const web3 = await ensureWeb3(network)

const task = await exports.task({
web3,
reporter,
tokenAddress,
newController,
silent,
debug,
})
return task.run().then(ctx => {
reporter.success(
`Successfully changed the controller of ${tokenAddress} to ${newController}`
)
reporter.info(`Transaction hash: ${chalk.bold(ctx.txHash)}`)

process.exit()
})
}
2 changes: 1 addition & 1 deletion src/commands/dao_cmds/utils/daoArg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const isValidAragonID = dao => /[a-z0-9]+\.eth/.test(dao)

module.exports = yargs => {
return yargs.positional('dao', {
description: 'Address of the Kernel or AragonID)',
description: 'Address of the Kernel or AragonID',
type: 'string',
coerce: dao =>
!isAddress(dao) && !isValidAragonID(dao)
Expand Down

0 comments on commit fb096ca

Please sign in to comment.