Skip to content

Commit

Permalink
Merge 1d49cbf into 1d74748
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai committed Sep 9, 2019
2 parents 1d74748 + 1d49cbf commit 01f06f2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
15 changes: 14 additions & 1 deletion docs/API.md
Expand Up @@ -303,7 +303,20 @@ Decodes an EVM callscript and tries to describe the transaction path that the sc

- `script` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**: The EVM callscript to describe

Returns **[Observable](https://rxjs-dev.firebaseapp.com/api/index/class/Observable)**: A single-emission observable that emits the described transaction path. The emitted transaction path is an array of objects, where each item has a `destination`, `data` and `description` key.
Returns **[Observable](https://rxjs-dev.firebaseapp.com/api/index/class/Observable)**: A single-emission observable that emits the described transaction path. The emitted transaction path is an array of objects, where each item has a `to`, `data`, and `description` key.

### describeTransaction

Tries to describe an Ethereum transaction based on its input data.

#### Parameters

- `transaction` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**: Transaction object, holding `to` and `data`.

Returns **[Observable](https://rxjs-dev.firebaseapp.com/api/index/class/Observable)**: A single-emission observable that emits the description, if describable. The result is an object with:

- `description`: a string description
- `annotatedDescription`: (if available) an array of objects annotating the description

### events

Expand Down
17 changes: 17 additions & 0 deletions packages/aragon-api/src/index.js
Expand Up @@ -262,6 +262,23 @@ export class AppProxy {
)
}

/**
* Try to describe a transaction based on its input data.
*
* @param {Object} transaction Transaction object
* @param {string} transaction.data Transaction's bytes data
* @param {string} transaction.to Transaction's to address
* @return {Observable} Single-emission Observable that emits the transaction's description, if describable. The result is an object holding a string `description` and an array of objects as `annotatedDescription`.
*/
describeTransaction (transaction) {
return this.rpc.sendAndObserveResponse(
'describe_transaction',
[transaction]
).pipe(
pluck('result')
)
}

/**
* Subscribe for events on your app's smart contract
*
Expand Down
1 change: 1 addition & 0 deletions packages/aragon-wrapper/src/index.js
Expand Up @@ -1103,6 +1103,7 @@ export default class Aragon {
handlers.createRequestHandler(request$, 'accounts', handlers.accounts),
handlers.createRequestHandler(request$, 'cache', handlers.cache),
handlers.createRequestHandler(request$, 'describe_script', handlers.describeScript),
handlers.createRequestHandler(request$, 'describe_transaction', handlers.describeTransaction),
handlers.createRequestHandler(request$, 'get_apps', handlers.getApps),
handlers.createRequestHandler(request$, 'network', handlers.network),
handlers.createRequestHandler(request$, 'path', handlers.path),
Expand Down
18 changes: 14 additions & 4 deletions packages/aragon-wrapper/src/radspec/index.js
Expand Up @@ -19,22 +19,32 @@ export async function tryEvaluatingRadspec (intent, wrapper) {
// If the intent matches an installed app, use only that app to search for a
// method match, otherwise fallback to searching all installed apps
const appsToSearch = app ? [app] : apps
const method = appsToSearch.reduce((method, app) => {
return method || findAppMethodFromData(app, intent.data)
const foundMethod = appsToSearch.reduce((found, app) => {
if (found) { return found }

const method = findAppMethodFromData(app, intent.data)
if (method) {
return {
method,
abi: app.abi
}
}
}, undefined)

const { abi, method } = foundMethod || {}

let evaluatedNotice
if (method && method.notice) {
try {
evaluatedNotice = await radspec.evaluate(
method.notice,
{
abi: app.abi,
abi,
transaction: intent
},
{ ethNode: wrapper.web3.currentProvider }
)
} catch (err) { }
} catch (err) {}
}

return {
Expand Down
30 changes: 30 additions & 0 deletions packages/aragon-wrapper/src/rpc/handlers/describe-transaction.js
@@ -0,0 +1,30 @@
import { postprocessRadspecDescription, tryEvaluatingRadspec } from '../../radspec'

export default async function (request, proxy, wrapper) {
const [transaction = {}] = request.params
if (!transaction.to) {
throw new Error(`Could not describe transaction: missing 'to'`)
}
if (!transaction.data) {
throw new Error(`Could not describe transaction: missing 'data'`)
}

let description
try {
description = await tryEvaluatingRadspec(transaction, wrapper)
} catch (_) {}

if (description) {
try {
const processed = await postprocessRadspecDescription(description, wrapper)
return {
annotatedDescription: processed.annotatedDescription,
description: processed.description
}
} catch (_) {}
}

return {
description
}
}
1 change: 1 addition & 0 deletions packages/aragon-wrapper/src/rpc/handlers/index.js
Expand Up @@ -49,6 +49,7 @@ export function combineRequestHandlers (...handlers) {
export { default as accounts } from './accounts'
export { default as cache } from './cache'
export { default as describeScript } from './describe-script'
export { default as describeTransaction } from './describe-transaction'
export { default as getApps } from './get-apps'
export { default as network } from './network'
export { default as path } from './path'
Expand Down

0 comments on commit 01f06f2

Please sign in to comment.