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 produces invalid go-code, redeclares structs #20282

Closed
MariusVanDerWijden opened this issue Nov 13, 2019 · 3 comments · Fixed by #20381
Closed

abigen produces invalid go-code, redeclares structs #20282

MariusVanDerWijden opened this issue Nov 13, 2019 · 3 comments · Fixed by #20381
Assignees
Labels

Comments

@MariusVanDerWijden
Copy link
Member

MariusVanDerWijden commented Nov 13, 2019

Hey guys,
I'm currently running into a bug while generating go-bindings out of our smart contracts.

Our current setup of the contract is the following:
contract X contains the definition of struct2
contract A includes contract B
contract B includes contract X
contract A includes contract X
both A and B use struct2 as function parameters for public + external functions.

If I generate the go bindings for A like this
go:generate abigen --pkg a --sol A.sol --out ../a/a.go
Abigen generates some structs twice. e.g.

// Struct2 is an auto generated low-level Go binding around an user-defined struct.
type Struct2 struct {
	a   []common.Address
	b [][]*big.Int
	c   []Struct1
}

//...

// Struct2 is an auto generated low-level Go binding around an user-defined struct.
type Struct2 struct {
	a   []common.Address
	b [][]*big.Int
	c   []Struct1
}

The issue still persists with 1.9.7-stable-a718daa6

@MariusVanDerWijden
Copy link
Member Author

It even persists with abigen version 1.9.8-unstable-22e3bbbf which includes #20179

@rjl493456442 rjl493456442 self-assigned this Nov 14, 2019
@rjl493456442
Copy link
Member

@MariusVanDerWijden Can you please share some code snippets so that we can reproduce?

contract X contains the definition of struct2
contract A includes contract B
contract B includes contract X
contract A includes contract X
both A and B use struct2 as function parameters for public + external functions

Do you mean?

contract X {
     struct2
}
contract B is X {...}
contract A is B, X {...}

@MariusVanDerWijden
Copy link
Member Author

MariusVanDerWijden commented Nov 14, 2019

@rjl493456442

pragma solidity 0.5.12;
pragma experimental ABIEncoderV2;

library X {
    struct Params{
		uint256 challengeDuration;
		uint256 nonce;
		address app;
	}
}

contract A {
    function funA(X.Params memory params) public {
        // Do stuff
    }
}

contract B {
    function funB(X.Params memory params) public {
        // Do stuff
    }
}

./abigen --pkg funder --sol test.sol --out test.go

# github.com/ethereum/go-ethereum/build/bin
vet: ./test.go:393:6: XParams redeclared in this block

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

Successfully merging a pull request may close this issue.

2 participants