Go-ethereum: abigen fails to support the `--type` flag when data is piped to it.

Created on 12 Sep 2018  路  6Comments  路  Source: ethereum/go-ethereum

System information

Geth version: 1.8.15
OS & Version: Windows/Linux/OSX (all)
Commit hash : n/a

Expected behaviour

When you pipe stuff from solc to abigen (example below) you should be able to
pipe more than 1 contract with a number of calls to the pair of commands. The --type
flag should allow you to keep the code in a single package and not have Go compilation
errors.

Actual behaviour

The --type flag is ignored when you use a pipe. This is different than with a file.

Steps to reproduce the behaviour

mkdir -p ./gocode

cd contracts

 solc --allow-paths . \
    --combined-json abi,bin,devdoc,userdoc,metadata \
    Contract1.sol | \
    abigen --abi - --pkg AbiCode -type Contract1 --out ../gocode/Contract1.go

 solc --allow-paths . \
    --combined-json abi,bin,devdoc,userdoc,metadata \
    Contract2.sol | \
    abigen --abi - --pkg AbiCode -type Contract1 --out ../gocode/Contract2.go

cd ../gocode
go build

Solution

I will create a PR with a fix - it is a very simple 15 or so lines of code to add to abigen.

All 6 comments

After PR https://github.com/ethereum/go-ethereum/pull/17648 it is not possible to use --pkg flag with JSON contract artifacts.

Previously execution of command

cat <contract.json> | abigen --abi -  --pkg <packagename> --out <output.go>

lead to execution of the contractsFromStdin() at https://github.com/ethereum/go-ethereum/blob/7e7781ffaa5c5486c5e7b66dea4986e063524f63/cmd/abigen/main.go#L94

And after the PR pkgFlag == "" condition prevents falling into this branch:
https://github.com/ethereum/go-ethereum/blob/7e7781ffaa5c5486c5e7b66dea4986e063524f63/cmd/abigen/main.go#L78
And fails with the parse error.

Was this condition made by intention? What is the reason of adding it?

That seems like it may be an accidental check, since *pkgFlag == "" should exit earlier anyway:

https://github.com/ethereum/go-ethereum/blob/d88c6ce6b058ccd04b03d079d486b1d55fe5ef61/cmd/abigen/main.go#L56-L59

Seems worth a PR to fix it?

Also maybe seems like this issue could be closed.

@Shadowfiend, do you know how to get my PR merged? I am not able to assign reviewers and CI seems to be red for all PRs. I have asked help in discordapp go-ethereum/abigen channel, but have no answer.

Nope, you're in the land of the maintainers :)

Merged the fix with #19207 last month, closing this issue.

Was this page helpful?
0 / 5 - 0 ratings