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

Add call command #141

Merged
merged 8 commits into from
Aug 31, 2018
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ The local chain is started at `PORT`, which defaults to 8545.

The publish step of the app works exactly as `aragon apm publish`, described below.

#### `aragon apm publish` or `apm publish`
#### `aragon apm publish`

```
$ apm publish [CONTRACT_ADDRESS or CONTRACT_NAME] [--files PATTERN] [--ignore PATTERN] [--skip-confirm] [--only-artifacts]
$ aragon apm publish [CONTRACT_ADDRESS or CONTRACT_NAME] [--files PATTERN] [--ignore PATTERN] [--skip-confirm] [--only-artifacts]
```

Publishes a new (or the first!) version of your app.
Expand All @@ -80,30 +80,30 @@ Before publishing, your smart contract source code is scanned to generate an art

If `--skip-confirm` is specified the command will not wait for the transaction to receive confirmations.

#### `aragon apm version` or `apm version`
#### `aragon apm version`

```
$ apm version <BUMP>
$ aragon apm version <BUMP>
```

Bumps the version of your Aragon app, where a valid `BUMP` is either *major*, *minor* or *patch*.

Note that you are only allowed to release a version with a new smart contract address if the bump specified is major.

#### `aragon apm versions` or `apm versions`
#### `aragon apm versions`

```
$ apm versions
$ aragon apm versions
```

View a list of published versions for the app in the current directory.

### DAOs

#### `aragon apm grant` or `apm grant`
#### `aragon apm grant`

```
$ apm grant <ADDRESS> [--skip-confirm]
$ aragon apm grant <ADDRESS> [--skip-confirm]
```

Grants permission for `ADDRESS` to interact with the APM repository of the app in the current directory.
Expand Down
2 changes: 0 additions & 2 deletions aliases/apm

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "dist/cli.js",
"bin": {
"aragon": "./dist/cli.js",
"apm": "./aliases/apm",
"dao": "./aliases/dao"
},
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ cmd.option('network', {
}
let provider
if (truffleNetwork.provider) {
provider = truffleNetwork.provider
if (typeof truffleNetwork.provider === 'function') {
provider = truffleNetwork.provider()
} else {
provider = truffleNetwork.provider
}
} else if (truffleNetwork.host && truffleNetwork.port) {
provider = new Web3.providers.WebsocketProvider(`ws://${truffleNetwork.host}:${truffleNetwork.port}`)
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/apm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exports.command = 'apm <command>'

exports.describe = 'Publish and manage your APM package'

exports.aliases = ['package']

exports.builder = function (yargs) {
const cmd = yargs.commandDir('apm_cmds', {
visit: (cmd) => {
Expand Down
116 changes: 116 additions & 0 deletions src/commands/dao_cmds/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const TaskList = require('listr')
const Web3 = require('web3')
const daoArg = require('./utils/daoArg')
import initAragonJS from './utils/aragonjs-wrapper'
const { listApps } = require('./utils/knownApps')
const { rolesForApps } = require('./acl_cmds/utils/knownRoles')
const { ensureWeb3 } = require('../../helpers/web3-fallback')
import { addressesEqual } from './utils/web3-utils'

const Table = require('cli-table')
const colors = require('colors')

const knownRoles = rolesForApps()
const ANY_ENTITY = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF'
const ANY_ENTITY_TEXT = 'Any entity'
const GAS_ESTIMATE_ERROR_FACTOR = 2

const path = require('path')
let knownApps

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

exports.describe = 'Executes a call in an app of a DAO'

exports.builder = function (yargs) {
return daoArg(yargs)
.positional('proxy-address', {
description: 'Proxy address of the app with the function to be run'
})
.positional('fn', {
description: 'Function to be executed'
})
.option('fn-args', {
description: 'Arguments to be passed to the function',
array: true,
default: [],
})
}

exports.handler = async function ({ reporter, dao, apm, network, proxyAddress, fn, fnArgs }) {
knownApps = listApps()
const web3 = await ensureWeb3(network)

const tasks = new TaskList([
{
title: 'Generating transaction',
task: async (ctx, task) => {
task.output = `Fetching dao at ${dao}...`

if (!ctx.accounts) {
ctx.accounts = await web3.eth.getAccounts()
}

return new Promise((resolve, reject) => {
let wrapper, appsLoaded

const tryFindTransactionPath = async () => {
if (appsLoaded && wrapper) {
ctx.transactionPath = await wrapper.getTransactionPath(proxyAddress, fn, fnArgs)
resolve()
}
}

initAragonJS(dao, apm['ens-registry'], {
accounts: ctx.accounts,
provider: web3.currentProvider,
onApps: async apps => {
appsLoaded = true
await tryFindTransactionPath()
},
onError: err => reject(err)
})
.then(async (initializedWrapper) => {
wrapper = initializedWrapper
await tryFindTransactionPath()
})
.catch(err => {
reporter.error('Error inspecting DAO')
reporter.debug(err)
process.exit(1)
})
})
}
},
{
title: `Executing ${fn} in ${proxyAddress}`,
task: async (ctx, task) => {
task.output = `Waiting for response...`
let tx = ctx.transactionPath[0] // TODO: Support choosing between possible transaction paths

if (!tx) {
throw new Error('Cannot find transaction path for executing action')
}

const estimatedGas = await web3.eth.estimateGas(ctx.transactionPath[0])
tx.gas = parseInt(GAS_ESTIMATE_ERROR_FACTOR * estimatedGas)
return new Promise((resolve, reject) => {
web3.eth.sendTransaction(ctx.transactionPath[0],(err,res) => {
if(err){
reject(err)
return
}
ctx.res = res
resolve()
})
})
}
},
])

return tasks.run()
.then((ctx) => {
reporter.success(`Successfully sent transaction starting with transaction: ` + JSON.stringify(ctx.transactionPath[0].description))
process.exit()
})
}
4 changes: 2 additions & 2 deletions src/commands/dao_cmds/utils/aragonjs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const initWrapper = async (
ensRegistryAddress,
{
provider,
accounts = '',
walletProvider = null,
ipfsConf = ipfsDefaultConf,
onError = noop,
Expand Down Expand Up @@ -93,9 +94,8 @@ const initWrapper = async (
apm: { ipfs: ipfsConf },
})

const account = ''
try {
await wrapper.init(account && [account])
await wrapper.init(accounts || [accounts])
} catch (err) {
if (err.message === 'connection not open') {
onError(
Expand Down
12 changes: 12 additions & 0 deletions src/commands/dao_cmds/utils/web3-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Web3 from 'web3'

// Check address equality without checksums
export function addressesEqual(first, second) {
first = first && first.toLowerCase()
second = second && second.toLowerCase()
return first === second
}

export function etherToWei(ether) {
return ether * 10e17
}
3 changes: 2 additions & 1 deletion src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ exports.builder = (yargs) => {
coerce: function resolveTemplateName (tmpl) {
const aliases = {
bare: 'aragon/aragon-bare-boilerplate',
react: 'aragon/aragon-react-boilerplate'
react: 'aragon/aragon-react-boilerplate',
['react-kit']: 'aragon/aragon-react-kit-boilerplate'
}

if (!tmpl.includes('/')) {
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/web3-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const ensureWeb3 = async (network) => {
const connected = await web3.eth.net.isListening()
if (connected) return web3
} catch (err) {
throw new Error(`Please execute aragon run or aragon devchain before running this`)
throw new Error(`Web3 cannot connect using the network provider.

Make sure 'aragon devchain' is running or your provider settings are correct.

For more info you can check the Truffle docs on network configuration: https://truffleframework.com/docs/truffle/reference/configuration#networks`)
}
}

Expand Down