ewasm / design

Ewasm Design Overview and Specification
Apache License 2.0
1.02k stars 125 forks source link

How to invoke a specified method of contract? #159

Closed lowesyang closed 5 years ago

lowesyang commented 6 years ago

ECI spec tells us that every contract will export a main function with no parameters and returns. But i have two questions:

  1. What's the main function generally for?
  2. If a contract has several methods, how can i invoke one of the methods with some parameters in eWASM, just like EVM1?
axic commented 6 years ago

Currently it uses the same Contract ABI encoding design to be compatible with EVM.

e.g. the main function will use callDataCopy to retrieve the call data (input) as in EVM and use finish to return the output.

lowesyang commented 6 years ago

Can i explicitly define the main function in the contract, and how? It's better to have some examples~

axic commented 6 years ago

I agree, we're working on the documentation at https://github.com/ewasm/testnet which should include these.

Here's an example contract in Rust: https://github.com/ewasm/ewasm-precompiles/blob/master/sha256/src/lib.rs

lowesyang commented 6 years ago

So main function may do the things below:

  1. retrieve the call data(input)
  2. decode the hex code of contract method from the input. e.g. 0xedfdfdfd with 4 bytes.
  3. call the func referenced by the above hex code
  4. use finish to return the output.

is that right?

axic commented 6 years ago

Correct, it has to implement ABI handling on its own. Just like it is happening in EVM at the moment.

We're exploring other options though, see the umbrella issue #1

lowesyang commented 6 years ago

Got that, thanks very much!
Maybe an automatically ABI handling just like in EVM is very in need, cause developers don't need to write the dispatcher themselves~

lrettig commented 5 years ago

Can we close in favor of #1? Let's continue the conversation there

axic commented 5 years ago

We'd need to document this for clarity though.