Skip to content

Commit

Permalink
Merge pull request #49 from aragon/grant
Browse files Browse the repository at this point in the history
aragon grant
  • Loading branch information
onbjerg authored and 0xGabi committed Feb 25, 2019
1 parent b381ae1 commit ab0374f
Show file tree
Hide file tree
Showing 8 changed files with 1,337 additions and 334 deletions.
470 changes: 470 additions & 0 deletions packages/aragon-cli/abi/aragonOS/ACL.json

Large diffs are not rendered by default.

469 changes: 469 additions & 0 deletions packages/aragon-cli/abi/aragonOS/Kernel.json

Large diffs are not rendered by default.

591 changes: 266 additions & 325 deletions packages/aragon-cli/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/aragon-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/cli",
"version": "2.0.7",
"version": "2.2.0",
"description": "Aragon command-line tools",
"main": "src/cli.js",
"bin": {
Expand Down
28 changes: 28 additions & 0 deletions packages/aragon-cli/src/acl/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { keccak256 } = require('js-sha3')

module.exports = (web3) => {
const getACL = async (repoAddr) => {
const repo = new web3.eth.Contract(require('../../abi/apm/Repo'), repoAddr)
const daoAddr = await repo.methods.kernel().call()
const dao = new web3.eth.Contract(require('../../abi/aragonOS/Kernel'), daoAddr)
const aclAddr = await dao.methods.acl().call()

return new web3.eth.Contract(require('../../abi/aragonOS/ACL'), aclAddr)
}

return {
grant: async (repoAddr, grantee) => {
const acl = await getACL(repoAddr)

const roleId = '0x0000000000000000000000000000000000000000000000000000000000000001'

const call = acl.methods.grantPermission(grantee, repoAddr, roleId)
return {
to: acl.options.address,
data: call.encodeABI(),
gas: web3.utils.toHex(5e5),
gasPrice: web3.utils.toHex(web3.utils.toWei('15', 'gwei'))
}
}
}
}
2 changes: 1 addition & 1 deletion packages/aragon-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cmd.group(['apm.ens-registry', 'eth-rpc'], 'APM:')
cmd.option('apm.ipfs.rpc', {
description: 'An URI to the IPFS node used to publish files',
default: {
host: 'localhost',
host: 'ipfs.aragon.network',
protocol: 'http',
port: 5001
}
Expand Down
87 changes: 87 additions & 0 deletions packages/aragon-cli/src/commands/grant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const Web3 = require('web3')
const { MessageError } = require('../errors')
const EthereumTx = require('ethereumjs-tx')
const APM = require('../apm')
const ACL = require('../acl')

exports.command = 'grant [address]'
exports.describe = 'Grant an address permission to create new versions in this package'

exports.builder = function (yargs) {
return yargs.positional('address', {
description: 'The address being granted the permission to publish to the repo'
}).option('no-confirm', {
description: 'Exit as soon as transaction is sent, no wait for confirmation',
default: false
})
}

exports.handler = async function (reporter, {
// Globals
cwd,
ethRpc,
keyfile,
key,
module,
apm: apmOptions,

// Arguments
address,
noConfirm
}) {
const web3 = new Web3(keyfile.rpc ? keyfile.rpc : ethRpc)
const privateKey = keyfile.key ? keyfile.key : key

apmOptions.ensRegistry = !apmOptions.ensRegistry ? keyfile.ens : apmOptions.ensRegistry

const apm = await APM(web3, apmOptions)
const acl = ACL(web3)

if (!module || !Object.keys(module).length) {
throw new MessageError('This directory is not an Aragon project',
'ERR_NOT_A_PROJECT')
}

const repo = await apm.getRepository(module.appName)
.catch(() => null)
if (repo === null) {
throw new MessageError(`Repository ${module.appName} does not exist and it's registry does not exist`)
}

reporter.info(`Granting permission to publish on ${module.appName} for ${address}`)

// Decode sender
const from = privateKey ? web3.eth.accounts.privateKeyToAccount('0x' + privateKey).address : null

// Build transaction
const transaction = await acl.grant(repo.options.address, address)

if (from) {
transaction.nonce = await web3.eth.getTransactionCount(from)
transaction.from = from
}

if (!privateKey) {
reporter.info('Sign and broadcast this transaction')
reporter.success(JSON.stringify(transaction))
} else {
// Sign and broadcast transaction
reporter.debug('Signing transaction with passed private key...')

const tx = new EthereumTx(transaction)
tx.sign(Buffer.from(privateKey, 'hex'))
const signed = '0x' + tx.serialize().toString('hex')

const promisedReceipt = web3.eth.sendSignedTransaction(signed)
if (noConfirm) return reporter.success('Transaction sent')

const receipt = await promisedReceipt

reporter.debug(JSON.stringify(receipt))
if (receipt.status === '0x1') {
reporter.success(`Successful transaction ${receipt.transactionHash}`)
} else {
reporter.error(`Transaction reverted ${receipt.transactionHash}`)
}
}
}
22 changes: 15 additions & 7 deletions packages/aragon-cli/src/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.builder = function (yargs) {
}).option('only-artifacts', {
description: 'Whether just generate artifacts file without publishing',
default: false,
boolean: true,
boolean: true
}).option('provider', {
description: 'The APM storage provider to publish files to',
default: 'ipfs',
Expand All @@ -42,6 +42,10 @@ exports.builder = function (yargs) {
description: 'Exit as soon as transaction is sent, no wait for confirmation',
default: false
})
.option('no-contract', {
description: 'Only upload content without generating artifacts',
default: false
})
}

async function generateApplicationArtifact (web3, cwd, outputPath, module, contract, reporter) {
Expand Down Expand Up @@ -138,7 +142,8 @@ exports.handler = async function (reporter, {
key,
files,
ignore,
noConfirm
noConfirm,
noContract
}) {
const web3 = new Web3(keyfile.rpc ? keyfile.rpc : ethRpc)
const privateKey = keyfile.key ? keyfile.key : key
Expand Down Expand Up @@ -175,13 +180,16 @@ exports.handler = async function (reporter, {
// Generate the artifact
reporter.info('Generating application artifact...')
const dir = onlyArtifacts ? cwd : pathToPublish
const artifact = await generateApplicationArtifact(web3, cwd, dir, module, contract, reporter)
reporter.debug(`Generated artifact: ${JSON.stringify(artifact)}`)

// Save artifact
reporter.debug(`Saved artifact in ${dir}/artifact.json`)
if (!noContract) {
const artifact = await generateApplicationArtifact(web3, cwd, dir, module, contract, reporter)
reporter.debug(`Generated artifact: ${JSON.stringify(artifact)}`)

if (onlyArtifacts) return
// Save artifact
reporter.debug(`Saved artifact in ${dir}/artifact.json`)

if (onlyArtifacts) return
}

reporter.info(`Publishing ${module.appName} v${module.version}...`)
reporter.debug(`Publishing "${pathToPublish}" with ${provider}`)
Expand Down

0 comments on commit ab0374f

Please sign in to comment.