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

[Suggestion] Improve API around (single) unnamed return values #580

Closed
zerosnacks opened this issue Mar 21, 2024 · 3 comments
Closed

[Suggestion] Improve API around (single) unnamed return values #580

zerosnacks opened this issue Mar 21, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@zerosnacks
Copy link
Member

zerosnacks commented Mar 21, 2024

Component

contract

Describe the feature you would like

Follow up from conversation: alloy-rs/examples#8 (comment)

Consider the following:

 let Counter::numberReturn { _0 } = contract.number().call().await?;

Where Counter is implemented as follows:

contract Counter {
    uint256 public number;

    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }

    function increment() public {
        number++;
    }
}

It would be preferable to either:

  • Be able to assign this return directly to a value (let ret = contract.number().call().await?;)
  • Or be able to rename the return value _0 into a user defined value

Additional context

Any changes will be reflected in alloy/examples

@zerosnacks zerosnacks added the enhancement New feature or request label Mar 21, 2024
@prestwich prestwich transferred this issue from alloy-rs/alloy Mar 21, 2024
@mattsse
Copy link
Member

mattsse commented Apr 9, 2024

having an unwrapped return type would be more convenient,
I think we can check this when analyzing the abi and check the outputs, if it's just a single type, use that

@prestwich
Copy link
Member

we can, but it breaks encoding symmetry for any case where (T,) and T have different abi encodings, which would need to be accounted for

@DaniPopes
Copy link
Member

We deemed the current API consistent and good enough. This change would require some specific workarounds and maybe hard to do in the current type system.

If you want return types to have a "nicer name" in functions, you can name them in the returns (...) tuple.

The example in the issue already has a named return value due to it being an elementary type getter:

fn getter_names() {
sol! {
contract Getters {
string public value;
string[] public array;
mapping(bytes32 => string) public map;
mapping(bytes32 k => string v) public mapWithNames;
mapping(bytes32 k1 => mapping(uint256 k2 => string v2) v1) public nestedMapWithNames;
}
}
let _ = Getters::valueCall {};
let _ = Getters::valueReturn { value: String::new() };

@DaniPopes DaniPopes closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants