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

parseSignature breaks on zero input params #35

Open
kumavis opened this issue Nov 11, 2016 · 2 comments · May be fixed by #36
Open

parseSignature breaks on zero input params #35

kumavis opened this issue Nov 11, 2016 · 2 comments · May be fixed by #36

Comments

@kumavis
Copy link
Member

kumavis commented Nov 11, 2016

src: https://github.com/ethereumjs/ethereumjs-abi/blob/master/lib/index.js#L81-L83

works

/^(\w+)\((.+)\)$/.exec('hi(bytes)')
["hi(bytes)", "hi", "bytes"]

breaks

/^(\w+)\((.+)\)$/.exec('hi()')
null
@kumavis
Copy link
Member Author

kumavis commented Nov 11, 2016

this seems to work, will PR

// someMethod()
// someMethod(bytes,uint)
// someMethod(bytes,uint):(boolean)
function parseSignature (sigString) {
  var methodEndIndex = sigString.indexOf('(')
  if (methodEndIndex === -1) {
    throw new Error('Invalid method signature')
  }
  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),
  }
}

@mcgwiz
Copy link

mcgwiz commented Nov 21, 2018

In order to handle "someMethod():(boolean)" you might consider changing

var [ inputArgs, outputArgs ] = allArgs.split(':')

to

var [ inputArgs, outputArgs ] = allArgs.split('):(')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants