-
Notifications
You must be signed in to change notification settings - Fork 83
Generate Go bindings for V2 contracts #3016
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
Conversation
The common Makefile is based on the Makefile used for go bindings generation for contracts from V1. It is a common file that should be included in other Makefiles for projects. The main difference is that solc generation was extracted to a function that expects dependencies imports mapping and source file as arguments.
Configuration for Go bindings generator for ECDSA contracts.
Configuration for Go bindings generator for Random Beacon contracts. It also contains contracts pulled as dependencies: Token Staking and Sortition Pool.
Configuration for Go bindings generator for TBTC v2 contracts.
Configuration for Go bindings generator for Threshold Network contracts.
We don't want to push files installed from npm like node_modules.
We don't need to define the paths to the solidity source files as this can be simplified and we can look for the contract file names.
We can use the default `contracts/` directory for internal projects, but for external ones we need to define the path inside the `node_modules`.
As `**/*` pattern is not supported we have to define subdirectories for recursive search.
To ignore a directory in go build we have to prefix it with the underscore.
Move code out ouf `v2` directory.
Mark the direcotries that has to be revisited when working on V2 and removed or refactored. We leave the code for now so we don't break the build.
Updated the dependendcy to main branch commit after keep-network/keep-common#88 is merged.
This commit contains bindings generated by `go generate` command for V2 solidity contracts.
For go bindings generation we need contracts artifacts.
Npm pack outputs a filename that we can use in tar command to extract it.
Version 7.x introduced `pack-destination` flag that we use.
We don't need to set GO111MODULE as it's already set in the version of go we use (1.18)
We download the artifacts for V2 contracts in the docker image building process. There is an optional argument `CONTRACTS_NPM_PACKAGE_TAG` that can be set to a tag with which npm packages should be downloaded (e.g. ropsten, mainnet). By default if the argument is not set the `development` artifacts will be downloaded.
It's tiny change, but looks cleaner.
We use existings bindings that are commited to the repository under `pkg/chain/gen` instead of generating the new ones.
We don't want to regenerate V1 bindings. We leave the existing code so the build is not broken.
The outputs is not needed.
|
I was able to successfully download artifacts, generate bindings and build an image from Dockerfile. Looks good. |
|
👀 |
Having a separate bash script for getting the artifacts is another complication. To simplify the generation we include the download artifact in the go generate command execution. It makes sense to pull the artifacts each time the go generate is run as we want to build the fresh bindings in case the packages were updated.
We want to force the rm so it doesn't error if the directories don't exist.
The file was removed.
|
Potential improvements we discussed:
|

Closes #3005
Depends on keep-network/keep-common#88
Depends on threshold-network/tbtc-v2#376
TODO:
Introduction
This PR implements Go bindings generation for Solidity contracts:
TokenStakingSortitionPoolRandomBeaconWalletRegistryBridgeSortitionPool
Please note that bindings for
SortitionPoolare generated separately forrandom-beaconandecdsaas those projects can use different dependency versions.Contracts Artifacts
This PR changes the approach to what we consider the source for code generation.
Previously we were generating Go bindings from solidity contract sources which was causing a lot of headaches in regards to setting up
solccompiler just for this task.What is more, there are problems with
solcsupport on machines that run on Apple M1 processors, which some folks in the team transitioned to.Instead of generating ABIs from sources, we use contracts artifacts that are being published as part of NPM packages. We download the artifacts to
_contractsdirectory. The directory name is prefixed with the underscore (_), so it is ignored by the go tool.V1 Contracts
We will be removing parts of V1-related code from the client bit by bit. In this PR we remove the generation of the binding for V1 contracts. We leave the already generated code and use it in the docker image building process. This simplifies the docker build and reduces the build time.
Execution
Ensure
npmat least v7.x is installed and run: