-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from aragon/grant
aragon grant
- Loading branch information
Showing
8 changed files
with
1,337 additions
and
334 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters