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

abigen to create an output type for contract functions rather than declaring return type directly #29689

Open
crisog opened this issue May 1, 2024 · 3 comments

Comments

@crisog
Copy link

crisog commented May 1, 2024

Right now, the abigen-generated Go methods don't create/export the output types used for the functions, which makes it quite complex to use in a general way. The following is an example of how it looks now:

// GetMinipoolCountPerStatus is a free data retrieval call binding the contract method 0x3b5ecefa.
//
// Solidity: function getMinipoolCountPerStatus(uint256 _offset, uint256 _limit) view returns(uint256 initialisedCount, uint256 prelaunchCount, uint256 stakingCount, uint256 withdrawableCount, uint256 dissolvedCount)
func (_RocketMinipoolManager *RocketMinipoolManagerCaller) GetMinipoolCountPerStatus(opts *bind.CallOpts, _offset *big.Int, _limit *big.Int) (struct {
    InitialisedCount  *big.Int
    PrelaunchCount    *big.Int
    StakingCount      *big.Int
    WithdrawableCount *big.Int
    DissolvedCount    *big.Int
}, error) {
    var out []interface{}
    err := _RocketMinipoolManager.contract.Call(opts, &out, "getMinipoolCountPerStatus", _offset, _limit)

    outstruct := new(struct {
        InitialisedCount  *big.Int
        PrelaunchCount    *big.Int
        StakingCount      *big.Int
        WithdrawableCount *big.Int
        DissolvedCount    *big.Int
    })
    if err != nil {
        return *outstruct, err
    }

    outstruct.InitialisedCount = *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
    outstruct.PrelaunchCount = *abi.ConvertType(out[1], new(*big.Int)).(**big.Int)
    outstruct.StakingCount = *abi.ConvertType(out[2], new(*big.Int)).(**big.Int)
    outstruct.WithdrawableCount = *abi.ConvertType(out[3], new(*big.Int)).(**big.Int)
    outstruct.DissolvedCount = *abi.ConvertType(out[4], new(*big.Int)).(**big.Int)

    return *outstruct, err

}

Ideally, instead of putting the return type right in the return for the function, it would be great that a proper type gets created & exported like this:

type GetMinipoolCountPerStatusOutput struct {
    InitialisedCount  *big.Int
    PrelaunchCount    *big.Int
    StakingCount      *big.Int
    WithdrawableCount *big.Int
    DissolvedCount    *big.Int
}

func (_RocketMinipoolManager *RocketMinipoolManagerCaller) GetMinipoolCountPerStatus(opts *bind.CallOpts, _offset *big.Int, _limit *big.Int) (GetMinipoolCountPerStatusOutput, error) {
    var out []interface{}
    err := _RocketMinipoolManager.contract.Call(opts, &out, "getMinipoolCountPerStatus", _offset, _limit)

    outstruct := GetMinipoolCountPerStatusOutput{
        InitialisedCount: *abi.ConvertType(out[0], new(*big.Int)).(**big.Int),
        PrelaunchCount: *abi.ConvertType(out[1], new(*big.Int)).(**big.Int),
        StakingCount:  *abi.ConvertType(out[2], new(*big.Int)).(**big.Int),
        WithdrawableCount: *abi.ConvertType(out[3], new(*big.Int)).(**big.Int),
        DissolvedCount: *abi.ConvertType(out[4], new(*big.Int)).(**big.Int),
    }

    if err != nil {
        return outstruct, err
    }

    return outstruct, err
}
@crisog crisog changed the title Abigen to create an output type for contract functions rather than declaring structs as return type Abigen to create an output type for contract functions rather than declaring return type directly May 1, 2024
@crisog crisog changed the title Abigen to create an output type for contract functions rather than declaring return type directly abigen to create an output type for contract functions rather than declaring return type directly May 1, 2024
@JuliusCaesar1370
Copy link

HBI

@joey1123455
Copy link

HBI

hi Julius are you working on this

@joey1123455
Copy link

I have started working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants