-
Notifications
You must be signed in to change notification settings - Fork 15
improve flexibility of gethwrapper helpers #316
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,107 +1,27 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| gethwrappers "github.com/smartcontractkit/chainlink-evm/gethwrappers/helpers" | ||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/helpers/generate/wrap" | ||
| zksyncwrapper "github.com/smartcontractkit/chainlink-evm/gethwrappers/helpers/zksync" | ||
| ) | ||
|
|
||
| var ( | ||
| rootDir = "../../solc/" | ||
| ) | ||
|
|
||
| func main() { | ||
| project := os.Args[1] | ||
| className := os.Args[2] | ||
| pkgName := os.Args[3] | ||
| solcProjectRoot := os.Args[1] | ||
| abiGenPath := os.Args[2] | ||
| contract := os.Args[3] | ||
| pkgName := os.Args[4] | ||
|
|
||
| var outDirSuffix string | ||
| if len(os.Args) >= 5 { | ||
| outDirSuffix = os.Args[4] | ||
| } else { | ||
| outDirSuffix = "latest" | ||
| } | ||
| outDirSuffix := "latest" | ||
|
|
||
| if os.Getenv("ZKSYNC") == "true" { | ||
| outDir := getOutDir(outDirSuffix, pkgName) | ||
| zksyncBytecodePath := filepath.Join("..", "zkout", className+".sol", className+".json") | ||
| zksyncBytecodePath := filepath.Join("..", "zkout", contract+".sol", contract+".json") | ||
| zksyncBytecode := zksyncwrapper.ReadBytecodeFromForgeJSON(zksyncBytecodePath) | ||
| outPath := filepath.Join(outDir, pkgName+"_zksync.go") | ||
| zksyncwrapper.WrapZksyncDeploy(zksyncBytecode, className, pkgName, outPath) | ||
| outPath := filepath.Join(wrap.GetOutDir(outDirSuffix, pkgName), pkgName+"_zksync.go") | ||
| zksyncwrapper.WrapZksyncDeploy(zksyncBytecode, contract, pkgName, outPath) | ||
| } else { | ||
| abiPath := rootDir + project + "/" + className + "/" + className + ".sol/" + className + ".abi.json" | ||
| metadataPath := rootDir + project + "/" + className + "/" + className + ".sol/" + className + ".metadata.json" | ||
| binPath := rootDir + project + "/" + className + "/" + className + ".sol/" + className + ".bin" | ||
| buildInfoPath := rootDir + project + "/" + className + "/build/build.json" | ||
|
|
||
| GenWrapper(abiPath, binPath, buildInfoPath, metadataPath, className, pkgName, outDirSuffix) | ||
| } | ||
| } | ||
|
|
||
| // GenWrapper generates a contract wrapper for the given contract. | ||
| // | ||
| // abiPath is the path to the contract's ABI JSON file. | ||
| // | ||
| // binPath is the path to the contract's binary file, typically with .bin extension. | ||
| // | ||
| // className is the name of the generated contract class. | ||
| // | ||
| // pkgName is the name of the package the contract will be generated in. Try | ||
| // to follow idiomatic Go package naming conventions where possible. | ||
| // | ||
| // outDirSuffixInput is the directory suffix to generate the wrapper in. If not provided, the | ||
| // wrapper will be generated in the default location. The default location is | ||
| // <project>/generated/<pkgName>/<pkgName>.go. The suffix will take place after | ||
| // the <project>/generated, so the overridden location would be | ||
| // <project>/generated/<outDirSuffixInput>/<pkgName>/<pkgName>.go. | ||
| func GenWrapper(abiPath, binPath, buildInfoPath, metadataPath, className, pkgName, outDirSuffixInput string) { | ||
| fmt.Println("Generating", pkgName, "contract wrapper") | ||
|
|
||
| outDir := getOutDir(outDirSuffixInput, pkgName) | ||
| outPath := filepath.Join(outDir, pkgName+".go") | ||
| metadataOutPath := filepath.Join(outDir, pkgName+"_metadata.go") | ||
|
|
||
| gethwrappers.Abigen(gethwrappers.AbigenArgs{ | ||
| Bin: binPath, | ||
| ABI: abiPath, | ||
| BuildInfo: buildInfoPath, | ||
| Metadata: metadataPath, | ||
| Out: outPath, | ||
| BuildInfoOut: metadataOutPath, | ||
| Type: className, | ||
| Pkg: pkgName, | ||
| }) | ||
|
|
||
| // Build succeeded, so update the versions db with the new contract data | ||
| versions, err := gethwrappers.ReadVersionsDB() | ||
| if err != nil { | ||
| gethwrappers.Exit("could not read current versions database", err) | ||
| } | ||
| versions.GethVersion = gethwrappers.GethVersion | ||
| versions.ContractVersions[pkgName] = gethwrappers.ContractVersion{ | ||
| Hash: gethwrappers.VersionHash(abiPath, binPath), | ||
| AbiPath: abiPath, | ||
| BinaryPath: binPath, | ||
| wrap.GenWrapper(solcProjectRoot, contract, pkgName, outDirSuffix, abiGenPath) | ||
| } | ||
| if err := gethwrappers.WriteVersionsDB(versions); err != nil { | ||
| gethwrappers.Exit("could not save versions db", err) | ||
| } | ||
| } | ||
|
|
||
| func getOutDir(outDirSuffixInput, pkgName string) string { | ||
| cwd, err := os.Getwd() // gethwrappers directory | ||
| if err != nil { | ||
| gethwrappers.Exit("could not get working directory", err) | ||
| } | ||
| outDir := filepath.Join(cwd, "generated", outDirSuffixInput, pkgName) | ||
| if mkdErr := os.MkdirAll(outDir, 0700); err != nil { | ||
| gethwrappers.Exit( | ||
| fmt.Sprintf("failed to create wrapper dir, outDirSuffixInput: %s (could be empty)", outDirSuffixInput), | ||
| mkdErr) | ||
| } | ||
|
|
||
| return outDir | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package wrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| gethwrappers "github.com/smartcontractkit/chainlink-evm/gethwrappers/helpers" | ||
| ) | ||
|
|
||
| // GenWrapper generates a contract wrapper for the given contract. | ||
| // | ||
| // solcProjectRoot is the path to the solc artifacts for the project, e.g. `"../../contracts/solc/" + project` | ||
| // abiPath is the path to the contract's ABI JSON file. | ||
| // binPath is the path to the contract's binary file, typically with .bin extension. | ||
| // contract is the name of the generated contract class. | ||
| // pkgName is the name of the package the contract will be generated in. Try | ||
| // to follow idiomatic Go package naming conventions where possible. | ||
| // | ||
| // outDirSuffixInput is the directory suffix to generate the wrapper in. If not provided, the | ||
| // wrapper will be generated in the default location. The default location is | ||
| // <project>/generated/<pkgName>/<pkgName>.go. The suffix will take place after | ||
| // the <project>/generated, so the overridden location would be | ||
| // <project>/generated/<outDirSuffixInput>/<pkgName>/<pkgName>.go. | ||
| func GenWrapper(solcProjectRoot, contract, pkgName, outDirSuffixInput, abiGenPath string) { | ||
| abiPath := filepath.Join(solcProjectRoot, contract, contract+".sol", contract+".abi.json") | ||
| metadataPath := filepath.Join(solcProjectRoot, contract, contract+".sol", contract+".metadata.json") | ||
| binPath := filepath.Join(solcProjectRoot, contract, contract+".sol", contract+".bin") | ||
| buildInfoPath := filepath.Join(solcProjectRoot, contract, "build", "build.json") | ||
|
|
||
| fmt.Println("Generating", pkgName, "contract wrapper") | ||
|
|
||
| outDir := GetOutDir(outDirSuffixInput, pkgName) | ||
| outPath := filepath.Join(outDir, pkgName+".go") | ||
| metadataOutPath := filepath.Join(outDir, pkgName+"_metadata.go") | ||
|
|
||
| gethwrappers.Abigen(gethwrappers.AbigenArgs{ | ||
| Bin: binPath, | ||
| ABI: abiPath, | ||
| BuildInfo: buildInfoPath, | ||
| Metadata: metadataPath, | ||
| Out: outPath, | ||
| BuildInfoOut: metadataOutPath, | ||
| Type: contract, | ||
| Pkg: pkgName, | ||
| AbiGenPath: abiGenPath, | ||
| }) | ||
|
|
||
| // Build succeeded, so update the versions db with the new contract data | ||
| versions, err := gethwrappers.ReadVersionsDB() | ||
| if err != nil { | ||
| gethwrappers.Exit("could not read current versions database", err) | ||
| } | ||
| versions.GethVersion = gethwrappers.GethVersion | ||
| versions.ContractVersions[pkgName] = gethwrappers.ContractVersion{ | ||
| Hash: gethwrappers.VersionHash(abiPath, binPath), | ||
| AbiPath: abiPath, | ||
| BinaryPath: binPath, | ||
| } | ||
| if err := gethwrappers.WriteVersionsDB(versions); err != nil { | ||
| gethwrappers.Exit("could not save versions db", err) | ||
| } | ||
| } | ||
|
|
||
| func GetOutDir(outDirSuffixInput, pkgName string) string { | ||
| cwd, err := os.Getwd() // gethwrappers directory | ||
| if err != nil { | ||
| gethwrappers.Exit("could not get working directory", err) | ||
| } | ||
| outDir := filepath.Join(cwd, "generated", outDirSuffixInput, pkgName) | ||
| if mkdErr := os.MkdirAll(outDir, 0700); mkdErr != nil { | ||
| gethwrappers.Exit( | ||
| fmt.Sprintf("failed to create wrapper dir, outDirSuffixInput: %s (could be empty)", outDirSuffixInput), | ||
| mkdErr) | ||
| } | ||
|
|
||
| return outDir | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrappers are always generated into
latest. Teams that wish to adopt this new wrapper generation should also adopt the versioned gethwrappers.