Skip to content

Commit

Permalink
Print permissionless apps (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelwhisperer authored Jan 15, 2019
1 parent cc0ff3c commit ed54c40
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions src/commands/dao_cmds/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ const daoArg = require('./utils/daoArg')
const { listApps } = require('./utils/knownApps')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
const listrOpts = require('../../helpers/listr-options')

const { getContract } = require('../../util')
const Table = require('cli-table')

const addressesEqual = (a, b) => a.toLowerCase() === b.toLowerCase()

let knownApps

exports.command = 'apps <dao>'

exports.describe = 'Get all the apps in a DAO'

exports.builder = function(yargs) {
return daoArg(yargs)
return daoArg(yargs).option('all', {
description: 'Whether to include apps without permissions as well',
boolean: true,
})
}

const printAppName = appId => {
Expand All @@ -33,6 +38,7 @@ const printContent = content => {
exports.handler = async function({
reporter,
dao,
all,
network,
apm: apmOptions,
wsProvider,
Expand Down Expand Up @@ -69,34 +75,73 @@ exports.handler = async function({
})
},
},
{
title: 'Fetching permissionless apps',
enabled: () => all,
task: async (ctx, task) => {
const kernel = new web3.eth.Contract(
getContract('@aragon/os', 'Kernel').abi,
ctx.daoAddress
)

const events = await kernel.getPastEvents('NewAppProxy', {
fromBlock: await kernel.methods.getInitializationBlock().call(),
toBlock: 'latest',
})

ctx.appsWithoutPermissions = events
.map(event => ({
proxyAddress: event.returnValues.proxy,
appId: event.returnValues.appId,
}))
// Remove apps that have permissions
.filter(
({ proxyAddress }) =>
!ctx.apps.find(app =>
addressesEqual(app.proxyAddress, proxyAddress)
)
)
},
},
],
listrOpts(silent, debug)
)

return tasks.run().then(ctx => {
reporter.success(`Successfully fetched DAO apps for ${ctx.daoAddress}`)
const appsContent = ctx.apps.map(
({ appId, proxyAddress, codeAddress, content, appName, version }) => [
appName ? `${appName}@v${version}` : printAppName(appId),
proxyAddress,
printContent(content),
]
)

// filter registry name to make it shorter
// TODO: Add flag to turn off
const filteredContent = appsContent.map(row => {
row[0] = row[0].replace('.aragonpm.eth', '')
return row
})
const appsContent = ctx.apps
.map(
({ appId, proxyAddress, codeAddress, content, appName, version }) => [
appName ? `${appName}@v${version}` : printAppName(appId),
proxyAddress,
printContent(content),
]
)
// filter registry name to make it shorter
// TODO: Add flag to turn off
.map(row => {
row[0] = row[0].replace('.aragonpm.eth', '')
return row
})

const table = new Table({
head: ['App', 'Proxy address', 'Content'].map(x => chalk.white(x)),
})
appsContent.forEach(row => table.push(row))
console.log(table.toString())

filteredContent.forEach(row => table.push(row))
// Print permisionless apps
const tableForPermissionlessApps = new Table({
head: ['Permissionless app', 'Proxy address'].map(x => chalk.white(x)),
})
ctx.appsWithoutPermissions.forEach(app =>
tableForPermissionlessApps.push([
printAppName(app.appId).replace('.aragonpm.eth', ''),
app.proxyAddress,
])
)
console.log(tableForPermissionlessApps.toString())

console.log(table.toString())
process.exit() // force exit, as aragonjs hangs
})
}

0 comments on commit ed54c40

Please sign in to comment.