openethereum / sol-rs

Solaris - Solidity testing framework in Rust.
GNU General Public License v3.0
54 stars 14 forks source link

How could I get a function iterator of a contract which can be put in as a parameter in eve.call() #41

Open fCorleone opened 5 years ago

fCorleone commented 5 years ago

I found that if I want to call a function of a contract , this line will be used:

eve.call(contract.functions().NAME_OF_YOUR_FUNCTIONS());

How could I get all of the functions' iterator of function list of a contract. Thanks a lot if you could do me a favor.

tomusdrw commented 5 years ago

@fCorleone we don't expose anything like that currently. Could you elaborate why it would be useful? IT's also more ethabi issue than sol-rs.

fCorleone commented 5 years ago

Yes, for the reason that I want to write a program that could parse a contract and get the function name of the contract, and automatically call the functions. But I just don't know how to write evm.call() line. Because the parameter put into the call function should be like contract.function.name(), but I can just get a string to represent the name of the function. So I wonder if I could change the string to the correct type so that I can put it into the eve.call function

tomusdrw commented 5 years ago

The whole point of ethabi-derive is to provide type-safe wrapper for contracts, so you cannot dynamically call a function given it's function name as a string, cause you wouldn't know what types of parameters it's expecting or returns.

What you can do is use ethabi directly, like here: https://docs.rs/ethabi/6.0.1/ethabi/struct.Contract.html#method.function This is untyped API that gives you a builder that will produce data field of a transaction that you should send to interact with the contract. You will most likely need to contstruct ActionParams on your own (https://github.com/paritytech/sol-rs/blob/master/solaris/src/evm.rs#L260), and maybe even expose more "raw" function to perform a call than current EVM exposes.

fCorleone commented 5 years ago

Thank you a lot about this, it's very useful to me.