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

getTransactionPath refactor #840

Merged
merged 18 commits into from
Oct 31, 2019
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
29 changes: 5 additions & 24 deletions packages/aragon-cli/src/commands/apm_cmds/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const startIPFS = require('../ipfs_cmds/start')
const propagateIPFS = require('../ipfs_cmds/propagate')
const execTask = require('../dao_cmds/utils/execHandler').task
const listrOpts = require('@aragon/cli-utils/src/helpers/listr-options')
const { map, filter, first } = require('rxjs/operators')
const { addressesEqual } = require('../../util')

const {
prepareFilesForPublishing,
Expand Down Expand Up @@ -548,28 +546,11 @@ exports.runPublishTask = ({
enabled: () => !onlyArtifacts,
task: async (ctx, task) => {
try {
const getTransactionPath = async wrapper => {
// Wait for app info to load
await wrapper.apps
.pipe(
map(apps =>
apps.find(app =>
addressesEqual(app.proxyAddress, proxyAddress)
)
),
filter(app => app),
first()
)
.toPromise()

return wrapper.getTransactionPath(
proxyAddress,
methodName,
params
)
}

return execTask(dao, getTransactionPath, {
return execTask({
dao,
app: proxyAddress,
method: methodName,
params,
ipfsCheck: false,
reporter,
gasPrice,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
const execHandler = require('../../utils/execHandler').handler
const { keccak256 } = require('web3').utils
const { map, filter, first } = require('rxjs/operators')
const { addressesEqual } = require('../../../../util')
const { ensureWeb3 } = require('../../../../helpers/web3-fallback')

module.exports = async function(
dao,
method,
params,
{ reporter, apm, network, gasPrice, wsProvider, role, silent, debug }
) {
const getTransactionPath = async wrapper => {
const aclAddr = wrapper.aclProxy.address
// Wait for app info to load
await wrapper.apps
.pipe(
map(apps =>
apps.find(app => addressesEqual(app.proxyAddress, aclAddr))
),
filter(app => app),
first()
)
.toPromise()
const web3 = await ensureWeb3(network)
const daoInstance = new web3.eth.Contract(
require('@aragon/os/build/contracts/Kernel').abi,
dao
)
const aclAddress = await daoInstance.methods.acl().call()

let processedParams
const processedParams = role.startsWith('0x')
? params
: params.map(param => (param === role ? keccak256(role) : param))

// If the provided role is its name, the name is hashed
// TODO: Get role bytes from app artifacts
if (role.startsWith('0x')) {
processedParams = params
} else {
processedParams = params.map(param =>
param === role ? '0x' + keccak256(role) : param
)
}

return wrapper.getACLTransactionPath(method, processedParams)
}
return execHandler(dao, getTransactionPath, {
return execHandler({
dao,
app: aclAddress,
method,
params: processedParams,
ipfsCheck: false,
reporter,
gasPrice,
Expand Down
25 changes: 13 additions & 12 deletions packages/aragon-cli/src/commands/dao_cmds/acl_cmds/view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import initAragonJS from '../utils/aragonjs-wrapper'
import { initAragonJS, getApps } from '../../../helpers/aragonjs-wrapper'
const chalk = require('chalk')
const TaskList = require('listr')
const daoArg = require('../utils/daoArg')
Expand Down Expand Up @@ -30,7 +30,7 @@ const printAppName = (appId, addr) => {
if (addr === NO_MANAGER) return NO_MANAGER_TEXT
return knownApps[appId]
? `${knownApps[appId].split('.')[0]} (${addr.slice(0, 6)})`
: addr.slice(0, 16) + '...'
: `${addr.slice(0, 8)}..${addr.slice(-6)}`
}

const appFromProxyAddress = (proxyAddress, apps) => {
Expand Down Expand Up @@ -93,31 +93,32 @@ exports.handler = async function({
task.output = `Fetching permissions for ${dao}...`

return new Promise((resolve, reject) => {
const resolveIfReady = () => {
const resolveIfReady = async () => {
if (ctx.acl && ctx.apps) {
resolve()
}
}

initAragonJS(dao, apm['ens-registry'], {
provider: wsProvider || web3.currentProvider,
ipfsConf: apm.ipfs,
onPermissions: permissions => {
ctx.acl = permissions
resolveIfReady()
},
onApps: apps => {
ctx.apps = apps
resolveIfReady()
},
onDaoAddress: addr => {
ctx.daoAddress = addr
},
onError: err => reject(err),
}).catch(err => {
reporter.error('Error inspecting DAO')
reporter.debug(err)
process.exit(1)
})
.then(async wrapper => {
ctx.apps = await getApps(wrapper)
resolveIfReady()
})
.catch(err => {
reporter.error('Error inspecting DAO')
reporter.debug(err)
process.exit(1)
})
})
},
},
Expand Down
33 changes: 6 additions & 27 deletions packages/aragon-cli/src/commands/dao_cmds/act.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ const web3 = require('web3')
const execHandler = require('./utils/execHandler').handler
const getAppKernel = require('./utils/app-kernel')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
const {
parseArgumentStringIfPossible,
ZERO_ADDRESS,
addressesEqual,
} = require('../../util')
const { map, filter, first } = require('rxjs/operators')
const { parseArgumentStringIfPossible, ZERO_ADDRESS } = require('../../util')

const EXECUTE_FUNCTION_NAME = 'execute'

Expand Down Expand Up @@ -83,29 +78,13 @@ exports.handler = async function({
}

const weiAmount = web3.utils.toWei(ethValue)

const fnArgs = [target, weiAmount, encodeCalldata(signature, callArgs)]

const getTransactionPath = async wrapper => {
// Wait for agent info to load
await wrapper.apps
.pipe(
map(apps =>
apps.find(app => addressesEqual(app.proxyAddress, agentAddress))
),
filter(app => app),
first()
)
.toPromise()

return wrapper.getTransactionPath(
agentAddress,
EXECUTE_FUNCTION_NAME,
fnArgs
)
}

return execHandler(dao, getTransactionPath, {
return execHandler({
dao,
app: agentAddress,
method: EXECUTE_FUNCTION_NAME,
params: fnArgs,
ipfsCheck: true,
reporter,
apm,
Expand Down
27 changes: 13 additions & 14 deletions packages/aragon-cli/src/commands/dao_cmds/apps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import initAragonJS from './utils/aragonjs-wrapper'
import { initAragonJS, getApps } from '../../helpers/aragonjs-wrapper'
const TaskList = require('listr')
const chalk = require('chalk')
const daoArg = require('./utils/daoArg')
Expand Down Expand Up @@ -56,26 +56,25 @@ exports.handler = async function({
[
{
title: 'Inspecting DAO',
task: (ctx, task) => {
task: async (ctx, task) => {
task.output = `Fetching apps for ${dao}...`
const { 'ens-registry': ensRegistry, ipfs } = apmOptions

return new Promise((resolve, reject) => {
initAragonJS(dao, apmOptions['ens-registry'], {
try {
const wrapper = await initAragonJS(dao, ensRegistry, {
ipfsConf: ipfs,
provider: wsProvider || web3.currentProvider,
onApps: apps => {
ctx.apps = apps
resolve()
},
onDaoAddress: addr => {
ctx.daoAddress = addr
},
onError: err => reject(err),
}).catch(err => {
reporter.error('Error inspecting DAO apps')
reporter.debug(err)
process.exit(1)
})
})

ctx.apps = await getApps(wrapper)
} catch (err) {
reporter.error('Error inspecting DAO apps')
reporter.debug(err)
process.exit(1)
}
},
},
{
Expand Down
28 changes: 6 additions & 22 deletions packages/aragon-cli/src/commands/dao_cmds/exec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const execHandler = require('./utils/execHandler').handler
const daoArg = require('./utils/daoArg')
const { parseArgumentStringIfPossible, addressesEqual } = require('../../util')
const { map, filter, first } = require('rxjs/operators')
const { parseArgumentStringIfPossible } = require('../../util')

exports.command = 'exec <dao> <proxy-address> <fn> [fn-args..]'

Expand Down Expand Up @@ -32,26 +31,11 @@ exports.handler = async function({
fnArgs,
wsProvider,
}) {
// TODO (daniel) refactor ConsoleReporter so we can do reporter.debug instead
if (global.DEBUG_MODE) console.log('fn-args before parsing', fnArgs)
fnArgs = fnArgs.map(parseArgumentStringIfPossible)
if (global.DEBUG_MODE) console.log('fn-args after parsing', fnArgs)

const getTransactionPath = async wrapper => {
// Wait for app info to load
await wrapper.apps
.pipe(
map(apps =>
apps.find(app => addressesEqual(app.proxyAddress, proxyAddress))
),
filter(app => app),
first()
)
.toPromise()

return wrapper.getTransactionPath(proxyAddress, fn, fnArgs)
}
return execHandler(dao, getTransactionPath, {
return execHandler({
dao,
app: proxyAddress,
method: fn,
params: fnArgs.map(parseArgumentStringIfPossible),
ipfsCheck: true,
reporter,
apm,
Expand Down
38 changes: 22 additions & 16 deletions packages/aragon-cli/src/commands/dao_cmds/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const execTask = require('./utils/execHandler').task
const { resolveEnsDomain } = require('./utils/aragonjs-wrapper')
const { resolveEnsDomain } = require('../../helpers/aragonjs-wrapper')
const TaskList = require('listr')
const daoArg = require('./utils/daoArg')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
Expand Down Expand Up @@ -117,17 +117,18 @@ exports.task = async ({
ctx.notInitialized = true
}

const getTransactionPath = wrapper => {
const fnArgs = [
ctx.repo.appId,
ctx.repo.contractAddress,
initPayload,
false,
]
return wrapper.getTransactionPath(dao, 'newAppInstance', fnArgs)
}
const fnArgs = [
ctx.repo.appId,
ctx.repo.contractAddress,
initPayload,
false,
]

return execTask(dao, getTransactionPath, {
return execTask({
dao,
app: dao,
method: 'newAppInstance',
params: fnArgs,
ipfsCheck: false,
reporter,
gasPrice,
Expand Down Expand Up @@ -187,15 +188,20 @@ exports.task = async ({
if (!ctx.accounts) {
ctx.accounts = await web3.eth.getAccounts()
}
const daoInstance = new web3.eth.Contract(
kernelAbi,
dao
)
const aclAddress = await daoInstance.methods.acl().call()

return Promise.all(
permissions.map(params => {
const getTransactionPath = async wrapper => {
return wrapper.getACLTransactionPath('createPermission', params)
}

return (
execTask(dao, getTransactionPath, {
execTask({
dao,
app: aclAddress,
method: 'createPermission',
params,
reporter,
gasPrice,
apm: apmOptions,
Expand Down
17 changes: 6 additions & 11 deletions packages/aragon-cli/src/commands/dao_cmds/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const execTask = require('./utils/execHandler').task
const { resolveEnsDomain } = require('./utils/aragonjs-wrapper')
const { resolveEnsDomain } = require('../../helpers/aragonjs-wrapper')
const TaskList = require('listr')
const daoArg = require('./utils/daoArg')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
Expand Down Expand Up @@ -65,16 +65,11 @@ exports.task = async ({
.APP_BASES_NAMESPACE()
.call()

const getTransactionPath = wrapper => {
const fnArgs = [
basesNamespace,
ctx.repo.appId,
ctx.repo.contractAddress,
]
return wrapper.getTransactionPath(dao, 'setApp', fnArgs)
}

return execTask(dao, getTransactionPath, {
return execTask({
dao,
app: dao,
method: 'setApp',
params: [basesNamespace, ctx.repo.appId, ctx.repo.contractAddress],
ipfsCheck: false,
reporter,
gasPrice,
Expand Down
Loading