|
| 1 | +## Changes to function call bindings |
| 2 | + |
| 3 | +With [core#884](https://github.com/alloy-rs/core/pull/884) the form of the generated call type (used for abi-encoding) is now dependent upon two factors: |
| 4 | + |
| 5 | +1. Number of parameters/args does the function take |
| 6 | +2. Whether the parameter is named or unnamed in case it has only **one** param |
| 7 | + |
| 8 | +Consider the following: |
| 9 | + |
| 10 | +```rust,ignore |
| 11 | +sol! { |
| 12 | + // No params/args |
| 13 | + function totalSupply() returns (uint256) |
| 14 | + // Exactly one unnamed param |
| 15 | + function balanceOf(address) returns (uint256); |
| 16 | + // Multiple params - Bindings for this remain unchanged. |
| 17 | + function approve(address spender, uint256 amount) returns (bool); |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +### Before |
| 22 | + |
| 23 | +Generated bindings were independent of the number of parameters and names, and the following struct were generated for the above function calls |
| 24 | + |
| 25 | +```rust,ignore |
| 26 | +// A struct with no fields as there are no parameters. |
| 27 | +pub struct totalSupplyCall { }; |
| 28 | +let encoding = totalSupplyCall { }.abi_encode(); |
| 29 | +
|
| 30 | +pub struct balanceOfCall { _0: Address }; |
| 31 | +let encoding = balanceOfCall { _0: Address::ZERO }.abi_encode(); |
| 32 | +``` |
| 33 | + |
| 34 | +### After |
| 35 | + |
| 36 | +```rust,ignore |
| 37 | +// A unit struct is generated when there are no parameters. |
| 38 | +pub struct totalSupplyCall; |
| 39 | +let encoding = totalSupplyCall.abi_encode(); |
| 40 | +
|
| 41 | +// A tuple struct with a single value is generated in case of a SINGLE UNNAMED param. |
| 42 | +pub struct balanceOfCall(pub Address); |
| 43 | +let encoding = balanceOfCall(Address::ZERO).abi_encode(); |
| 44 | +``` |
| 45 | + |
| 46 | +Now if the parameter in `balanceOf` was named like so: |
| 47 | + |
| 48 | +```rust,ignore |
| 49 | +sol! { |
| 50 | + function balanceOf(address owner) returns (uint256); |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +Then a regular struct would be generated like before: |
| 55 | + |
| 56 | +```rust, ignore |
| 57 | +pub struct balanceOfCall { owner: Address }; |
| 58 | +``` |
| 59 | + |
| 60 | +Bindings for function calls with **multiple parameters** are **unchanged**. |
0 commit comments