diff --git a/Makefile b/Makefile index 8afc30b1..0e216c2a 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,4 @@ add-license: check-license: ${LICENCE_SCRIPT} -check analyzer airgap cmd db examples internal service main.go -gen-contracts: - go run ./scripts/gen-contracts.go -gcelo $(CELO_BLOCKCHAIN_PATH) -monorepo $(CELO_MONOREPO_PATH) - .PHONY: gen-contracts lint fmt diff --git a/README.md b/README.md index ce3dc99d..2ad2f4c0 100644 --- a/README.md +++ b/README.md @@ -80,30 +80,19 @@ Running the Rosetta RPC Server from scratch will take some time to sync, since i You will need the following three repositories cloned locally: * `rosetta` (this repo) -* [`celo-monorepo`](https://github.com/celo-org/celo-monorepo) * [`celo-blockchain`](https://github.com/celo-org/celo-blockchain) You also need the following dependencies to be met: * `go >= 1.14` -* `rust >= 1.41.0` (`blockchain` dependency) -* `node = 10` (`celo-monorepo` dependency) * `golangci` ([installation instructions](https://golangci-lint.run/usage/install/#local-installation)) (linter dependency for the Makefile) #### Running on Alfajores (Testnet) Prerequisites: -* Checkout `celo-monorepo` branch `alfajores` and run `yarn && yarn build --ignore docs` -* Checkout `celo-blockchain` tag `v1.1.2` (`git fetch --all && git checkout v1.1.2`) (NOTE: check that this matches the version specified in the `rosetta` `go.mod` file) and `make all` -* Set paths to `celo-monorepo` and `celo-blockchain` as `CELO_MONOREPO_PATH` and `CELO_BLOCKCHAIN_PATH` respectively (paths can be absolute or relative to the `rosetta` repo. If desired, add these lines to your bash profile: - - ```sh - export CELO_MONOREPO_PATH=path/to/celo-monorepo - export CELO_BLOCKCHAIN_PATH=path/to/celo-blockchain - ``` - -* Checkout `rosetta` tag `v0.8.0` (`git fetch --all && git checkout v0.8.0`) (or latest released tag) and `make gen-contracts && make all` +* Checkout `celo-blockchain` tag `v1.2.4` (`git fetch --all && git checkout v1.2.4`) (NOTE: check that this matches the version specified in `rosetta`'s `go.mod` file) and `make geth` +* Checkout `rosetta` tag `v0.8.0` (`git fetch --all && git checkout v0.8.0`) (or latest released tag) and `make all` * Run `make alfajores-env` to create an empty datadir with the genesis block (only needs to be run the first time, upon initializing the service). The output should look something like this: ```sh @@ -134,7 +123,6 @@ This is the same as above with a few differences (generally: specifying `rc1` vs Prerequisites: -* Checkout `celo-monorepo` branch `rc1` instead of `alfajores`, run `yarn && yarn build --ignore docs` as above * `celo-blockchain`: same as above * Export paths: same as above * Checkout `rosetta`: same as above @@ -246,28 +234,16 @@ In addition to the dependencies listed above under the instructions for running * `openapi-generator` To re-generate rpc scaffold ([install link](https://openapi-generator.tech)) -The `Makefile` requires the following env variable to be set and pointed to your local `celo-blockchain` and `celo-monorepo` clones, respectively. Note that relative paths are fine: - -* `CELO_BLOCKCHAIN_PATH` -* `CELO_MONOREPO_PATH` - ### Build Commands Important commands: -* `make all`: Builds project (compiles go project, compiles bls-zexe) -* `make gen-contracts`: Regenerates contract wrappers +* `make all`: Builds project (compiles all modules), same as `go build ./...` * `make test` or `go test ./...` to run unit tests -* `go build ./...` to build all modules (only compiles, doesn't generate or compile rust library) - -### Managing Generated Contracts -Rosetta requires a few Celo Core Contracts +### Interaction with Celo Core Contracts -* The list of required contracts is defined on `scripts/gen-contracts.go` file -* Generation requires acces to `celo-blockchain` & `celo-monorepo`. -* Generation assumes both projects are **already properly built** (see above under instructions for running `rosetta` from source for more details on how to do this) -* To run generator do `make gen-contracts` +Rosetta uses [kliento](https://github.com/celo-org/kliento) to interact with the necessary Celo Core Contracts. ## How to run rosetta-cli-checks diff --git a/scripts/gen-contracts.go b/scripts/gen-contracts.go deleted file mode 100644 index 313aedc3..00000000 --- a/scripts/gen-contracts.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "path" - "strings" - - "github.com/celo-org/rosetta/internal/build" -) - -const contractsPath = "celo/contract" - -var contractsToGenerate = []string{ - "Registry", - "LockedGold", - "Election", - "StableToken", - "GasPriceMinimum", - "Election", - "EpochRewards", - "Validators", - "GoldToken", - "Reserve", - "Accounts", - "ReleaseGold", -} - -func main() { - monorepoPath := flag.String("monorepo", "", "Path to celo-monorepo") - celoBlockchainPath := flag.String("gcelo", "", "Path to celo-blockchain") - - flag.Parse() - fmt.Println(*monorepoPath, *celoBlockchainPath) - - if *monorepoPath == "" || *celoBlockchainPath == "" { - exitWithHelpMessage() - } - - validatePathExists(*monorepoPath) - validatePathExists(*celoBlockchainPath) - - if pathExists(contractsPath) { - if err := os.RemoveAll(contractsPath); err != nil { - exitMessage("Error removing "+contractsPath+" directory: %s\n", err) - } - } - if err := os.MkdirAll(contractsPath, os.ModePerm); err != nil { - exitMessage("Error creating "+contractsPath+" directory: %s\n", err) - } - - abigen := path.Join(*celoBlockchainPath, "build/bin", "abigen") - - for _, contract := range contractsToGenerate { - contractTrufflePath := path.Join(*monorepoPath, "packages/protocol/build/contracts/", contract+".json") - validatePathExists(contractTrufflePath) - build.MustRunCommand(abigen, "--truffle", contractTrufflePath, - "--pkg", "contract", "--type", contract, - "--out", path.Join(contractsPath, strings.ToLower(contract)+".go")) - } -} - -func pathExists(path string) bool { - _, err := os.Stat(path) - return err == nil -} - -func validatePathExists(dirpath string) { - if _, err := os.Stat(dirpath); err != nil { - if os.IsNotExist(err) { - fmt.Printf("Path %s does not exists", dirpath) - } else { - fmt.Printf("Can't access %s: %s", dirpath, err) - } - exitWithHelpMessage() - } -} - -func exitWithHelpMessage() { - flag.PrintDefaults() - os.Exit(1) -} - -func exitMessage(msg string, a ...interface{}) { - fmt.Printf(msg, a...) - os.Exit(1) -}