Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Add return struct support from abigen function signatures #661

Closed
alxiong opened this issue Dec 9, 2021 · 0 comments · Fixed by #664
Closed

Add return struct support from abigen function signatures #661

alxiong opened this issue Dec 9, 2021 · 0 comments · Fixed by #664

Comments

@alxiong
Copy link
Contributor

alxiong commented Dec 9, 2021

Is your feature request related to a problem? Please describe.
Currently for a function in contract that returns a struct, its abigen! generated signature would have a tuple as its return types in rust.

pragma solidity >=0.8.0;

contract Test {
  struct Person {
    string name;
    uint age;
  }
  function defaultPerson() public pure returns (Person memory) {
    return Person("Alice", 20);
  }
}
contract's ABI
[
	{
		"inputs": [],
		"name": "defaultPerson",
		"outputs": [
			{
				"components": [
					{
						"internalType": "string",
						"name": "name",
						"type": "string"
					},
					{
						"internalType": "uint256",
						"name": "age",
						"type": "uint256"
					}
				],
				"internalType": "struct Hello.Person",
				"name": "",
				"type": "tuple"
			}
		],
		"stateMutability": "pure",
		"type": "function"
	}
]

and in my Rust code:

// assume `contract` has been instantiated 
let person = contract.defaultPerson().call().await?;
    // ^^^ this is a tuple of (String, U256), instead of struct Person from abigen!

Describe the solution you'd like
Ideally we could also have return types matched the solidity function signature instead of ABIEncoderV2's representation.

Thanks a lot! @mattsse

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

Successfully merging a pull request may close this issue.

1 participant