Skip to content

Commit

Permalink
Fix solidity extractor (aragon#229)
Browse files Browse the repository at this point in the history
* Fix solidity extractor when radspec strings have function calls

* Add string type

* Fix visibility modifier detection in multiline function declaration
  • Loading branch information
izqui authored and 0xGabi committed Jan 5, 2019
1 parent c133486 commit 32b3258
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/aragon-cli/src/helpers/solidity-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ const fs = require('fs')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)

const modifiesStateAndIsPublic = (declaration) => {
const blacklist = ['internal', 'private', 'view', 'pure']

// space words to ensure they are not part of another word
return blacklist.filter((w) => declaration.indexOf(` ${w} `) != -1).length == 0
}
const modifiesStateAndIsPublic = (declaration) => (
!declaration.match(/\b(internal|private|view|pure|constant)\b/)
)

const typeOrAddress = type => {
const types = ['address', 'byte', 'uint', 'int', 'bool']
const types = ['address', 'byte', 'uint', 'int', 'bool', 'string']

// check if the type starts with any of the above types, otherwise it is probably
// a typed contract, so we need to return address for the signature
Expand All @@ -19,8 +16,12 @@ const typeOrAddress = type => {

// extracts function signature from function declaration
const getSignature = (declaration) => {
const name = declaration.match(/function ([^]*?)\(/)[0].replace('function ', '')
let params = declaration.match(/\(([^]*?)\)/)[0].replace('(', '').replace(')', '')
let [ name, params ] = declaration.match(/function ([^]*?)\)/)[1].split('(')

if (!name) {
return 'fallback'
}

if (params) {
// Has parameters
params = params
Expand All @@ -32,7 +33,7 @@ const getSignature = (declaration) => {
.join(',')
}

return name + params + ')'
return `${name}(${params})`
}

const getNotice = (declaration) => {
Expand Down

0 comments on commit 32b3258

Please sign in to comment.