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

[Feature] Turn SolCall::Return into Tuple #444

Closed
MartinquaXD opened this issue Dec 1, 2023 · 2 comments
Closed

[Feature] Turn SolCall::Return into Tuple #444

MartinquaXD opened this issue Dec 1, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@MartinquaXD
Copy link

Component

sol! macro

Describe the feature you would like

Over all I really like the ergonomics of using the sol! macro! 👏
The only thing that currently seems odd is that the return type is a struct instead of a tuple.

So specifically this code:

alloy_sol_types::sol! {
    function example() external returns (uint256, uint256);
}

Roughly results in this return type:

struct exampleReturn {
    pub _0: UInt<256, 4>,
    pub _1: UInt<256, 4>,
}

whereas a return type like this seems more natural to use:

struct exampleReturn (
    UInt<256, 4>,
    UInt<256, 4>,
)

Maybe having the type as a struct is nicer for the internal library code. But in that case at least having a function like into_tuple() would be nice.

Additional context

For context I wanted to have a generic function like this which should immediately return the tuple instead of the struct:

pub async fn call<T: SolCall>(web3: &Web3, to: H160, call: T) -> Result<T::Return, CallError> {
    let call = CallRequest {
        to: Some(to),
        data: Some(Bytes(call.abi_encode())),
        ..Default::default()
    };
    let rpc_response = web3.eth().call(call, None).await.map_err(CallError::Rpc)?;
    if rpc_response.0.is_empty() {
        return Err(CallError::MissingFunction);
    }
    T::abi_decode_returns(&rpc_response.0, true).map_err(CallError::Decode)
}
@MartinquaXD MartinquaXD added the enhancement New feature or request label Dec 1, 2023
@MartinquaXD
Copy link
Author

Shortly after opening the issue I noticed that you already support named function arguments and return tuple fields so this is less of an issue for me now.
But supporting tuples would still be cool.

@DaniPopes
Copy link
Member

I don't believe this is something we should add, as currently all structures have consistent naming schemes in all circumstances. Similar to #580.

@DaniPopes DaniPopes closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 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

2 participants