Skip to content

Commit

Permalink
cmd/abigen: change --exc to exclude by type name
Browse files Browse the repository at this point in the history
When using combined-json input, the contract names generated by
`compiler.ParseCombinedJSON` are the fully qualified contract names,
that is, are of the form `<solFilePath>:<type>`. So when checking for
excluded types, the type name has to be split from the f.q. name.

If the contract name is of the short version `<type>`, then the behavior
is as before.
  • Loading branch information
sebastianst authored and holiman committed Sep 23, 2022
1 parent 65f3c1b commit ffc6fc2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func abigen(c *cli.Context) error {
}
// Gather all non-excluded contract for binding
for name, contract := range contracts {
if exclude[strings.ToLower(name)] {
// fully qualified name is of the form <solFilePath>:<type>
nameParts := strings.Split(name, ":")
typeName := nameParts[len(nameParts)-1]
if exclude[strings.ToLower(typeName)] {
continue
}
abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
Expand All @@ -191,15 +194,14 @@ func abigen(c *cli.Context) error {
abis = append(abis, string(abi))
bins = append(bins, contract.Code)
sigs = append(sigs, contract.Hashes)
nameParts := strings.Split(name, ":")
types = append(types, nameParts[len(nameParts)-1])
types = append(types, typeName)

// Derive the library placeholder which is a 34 character prefix of the
// hex encoding of the keccak256 hash of the fully qualified library name.
// Note that the fully qualified library name is the path of its source
// file and the library name separated by ":".
libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] // the first 2 chars are 0x
libs[libPattern] = nameParts[len(nameParts)-1]
libs[libPattern] = typeName
}
}
// Extract all aliases from the flags
Expand Down

0 comments on commit ffc6fc2

Please sign in to comment.