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

add an ABI returns structs in some functions, messing up the codegen #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martyall
Copy link
Collaborator

No description provided.

@iostat
Copy link
Member

iostat commented Nov 16, 2023

Consider the following solidity

contract StructBreakage {
  struct SomeStruct {
    uint256 a;
    address b;
  }

  mapping(bytes32 => SomeStruct) public tonsOfStructs;

  function getAStruct(bytes32 k) public view returns (SomeStruct memory) {
    return tonsOfStructs[k];
  }
}

notice the mapping is defined as public, which means solc generates an accessor function. The accessor function that solc generates, however, will destructure SomeStruct into its components, i.e.:

// autogenerated by solc since tonsOfStructs is `mapping(...) public`:
function tonsOfStructs(bytes32 k) public view returns (uint256 a, address b) {
  return (tonsOfStructs[k].a, tonsOfStructs[k].b)
}

purescript-web3-codegen is perfectly happy with that ABI, since it's just a normal tuple. However, for getAStruct, it seems to think that since there's only one element in the outputs, it must be returning a single value, i.e. Tuple1 { a :: IntN 256, b :: Address }, when, well, that kinda makes no sense.


Anyway, I threw in a couple of combinations of struct sizes and combinations of (struct, primitive) in that ABI.

I think I accidentally defined S2A as struct S2A { uint96 d; }) -- so don't let that throw you off in the ABI for getS2A and s2as. Unfortunately my browser tab with the actual Solidity crashed, otherwise I would've fixed that before pushing. There might be another weird one, just assume the ABI makes sense (i.e., not a solc bug) if the names don't immediately match up with what they suggest.

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

Successfully merging this pull request may close these issues.

2 participants