MetaMask / eth-method-registry

A JS library for getting Solidity method data from a four-byte method signature
ISC License
21 stars 13 forks source link

Support for array arguments #10

Closed ribordy closed 3 years ago

ribordy commented 5 years ago

It looks like the parse function doesn't properly support methods with array arguments. The presence of any array argument results in none of the arguments being parsed:

const MethodRegistry = require('eth-method-registry')
const Eth = require('ethjs')
const provider = new Eth.HttpProvider('https://mainnet.infura.io')
const registry = new MethodRegistry({ provider })

console.log(registry.parse('redeem(uint256[],string)'));
>> { name: 'Redeem', args: [] }

This regex seems to be the culprit. It's not permitting [] characters to be in the argument list. Changing that line to the following allows those arguments to be parsed:

const match = signature.match(new RegExp(rawName[1] + '\\(+([a-z1-9,()\\[\\]]+)\\)'))

Note that the regular expression which parses out individual arguments (here) already supports brackets since they're included in the sequence A-z.

I'll open a PR with the changes I mentioned, but I wanted to confirm that this wasn't an intentional design decision.