Skip to content

Commit

Permalink
parseSignature - fix no args case
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
kumavis authored Nov 11, 2016
1 parent 4a33f23 commit f73ef91
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,22 @@ function parseNumber (arg) {
}
}

// someMethod()
// someMethod(bytes,uint)
// someMethod(bytes,uint):(boolean)
function parseSignature (sig) {
var tmp = /^(\w+)\((.+)\)$/.exec(sig)
if (tmp.length !== 3) {
function parseSignature (sigString) {
var methodEndIndex = sigString.indexOf('(')
if (methodEndIndex === -1) {
throw new Error('Invalid method signature')
}

var args = /^(.+)\):\((.+)$/.exec(tmp[2])

if (args !== null && args.length === 3) {
return {
method: tmp[1],
args: args[1].split(','),
retargs: args[2].split(',')
}
} else {
return {
method: tmp[1],
args: tmp[2].split(',')
}
var methodName = sigString.slice(0,methodEndIndex)
var allArgs = sigString.slice(methodEndIndex+1,-1)
var [ inputArgs, outputArgs ] = allArgs.split(':')

return {
method: methodName,
args: (inputArgs ? inputArgs.split(',') : []),
retargs: (outputArgs ? outputArgs.split(',') : null),
}
}

Expand Down

0 comments on commit f73ef91

Please sign in to comment.