diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ef52917..646146c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to rosetta-ethereum +# Contributing to mesh-ethereum ## Code of Conduct @@ -48,6 +48,6 @@ be locked to prevent further discussion. All support requests must be made via [our support team][3]. -[1]: https://github.com/coinbase/rosetta-ethereum/issues +[1]: https://github.com/coinbase/mesh-ethereum/issues [2]: https://chris.beams.io/posts/git-commit/#seven-rules [3]: https://support.coinbase.com/customer/en/portal/articles/2288496-how-can-i-contact-coinbase-support- diff --git a/README.md b/README.md index 2e5045a..967b72a 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,21 @@

- Rosetta Ethereum + Mesh Ethereum

-This repository contains a sample implementation of Rosetta API for the Ethereum blockchain. +This repository contains a sample implementation of Mesh API for the Ethereum blockchain.

- Build Status - - - - - + Build Status + + + + +

- +

Build once. Integrate your blockchain everywhere. @@ -38,9 +33,9 @@ USE AT YOUR OWN RISK. ## Overview -The `rosetta-ethereum` repository provides an implementation sample of the Rosetta API for Ethereum in Golang. We created this repository for developers of Ethereum-like (a.k.a., account-based) blockchains, who may find it easier to fork this implementation sample than write one from scratch. +The `mesh-ethereum` repository provides an implementation sample of the Mesh API for Ethereum in Golang. We created this repository for developers of Ethereum-like (a.k.a., account-based) blockchains, who may find it easier to fork this implementation sample than write one from scratch. -[Rosetta](https://www.rosetta-api.org/docs/welcome.html) is an open-source specification and set of tools that makes integrating with blockchains simpler, faster, and more reliable. The Rosetta API is specified in the [OpenAPI 3.0 format](https://www.openapis.org). +[Mesh](https://www.mesh-api.org/docs/welcome.html) is an open-source specification and set of tools that makes integrating with blockchains simpler, faster, and more reliable. The Mesh API is specified in the [OpenAPI 3.0 format](https://www.openapis.org). You can craft requests and responses with auto-generated code using [Swagger Codegen](https://swagger.io/tools/swagger-codegen) or [OpenAPI Generator](https://openapi-generator.tech). These requests and responses must be human-readable (easy to debug and understand), and able to be used in servers and browsers. @@ -62,12 +57,12 @@ Jump to: RAM: 16 MB minimum -We tested `rosetta-ethereum` on an [AWS c5.2xlarge instance](https://aws.amazon.com/ec2/instance-types/c5). -This instance type has 8 vCPU and 16 GB of RAM. If you use a computer with less than 16 GB of RAM, it is possible that `rosetta-ethereum` will exit with an OOM error. +We tested `mesh-ethereum` on an [AWS c5.2xlarge instance](https://aws.amazon.com/ec2/instance-types/c5). +This instance type has 8 vCPU and 16 GB of RAM. If you use a computer with less than 16 GB of RAM, it is possible that `mesh-ethereum` will exit with an OOM error. ### Network Settings -To increase the load `rosetta-ethereum` can handle, we recommend these actions: +To increase the load `mesh-ethereum` can handle, we recommend these actions: 1. Tune your OS settings to allow for more connections. On a linux-based OS, run the following commands to do so ([source](http://www.tweaked.io/guide/kernel)): @@ -79,12 +74,12 @@ sysctl -w net.ipv4.tcp_max_syn_backlog=10000 sysctl -w net.core.somaxconn=10000 sysctl -p (when done) ``` -_We have not tested `rosetta-ethereum` with `net.ipv4.tcp_tw_recycle` and do not recommend enabling it._ +_We have not tested `mesh-ethereum` with `net.ipv4.tcp_tw_recycle` and do not recommend enabling it._ 2. Modify your open file settings to `100000`. You can do this on a linux-based OS with the command: `ulimit -n 100000`. ### Memory-Mapped Files -`rosetta-ethereum` uses [memory-mapped files](https://en.wikipedia.org/wiki/Memory-mapped_file) to persist data in the `indexer`. As a result, you **must** run `rosetta-ethereum` on a 64-bit architecture (the virtual address space easily exceeds 100s of GBs). +`mesh-ethereum` uses [memory-mapped files](https://en.wikipedia.org/wiki/Memory-mapped_file) to persist data in the `indexer`. As a result, you **must** run `mesh-ethereum` on a 64-bit architecture (the virtual address space easily exceeds 100s of GBs). If you receive a kernel OOM, you may need to increase the allocated size of swap space on your OS. There is a great tutorial for how to do this on Linux [here](https://linuxize.com/post/create-a-linux-swap-file/). @@ -133,22 +128,22 @@ make coverage-local ## Docker Deployment -As specified in the [Rosetta API Principles](https://www.rosetta-api.org/docs/automated_deployment_testing.html), all Rosetta implementations must be deployable via Docker and support running via either an [`online` or `offline` mode](https://www.rosetta-api.org/docs/node_deployment.html#multiple-modes). +As specified in the [Mesh API Principles](https://www.mesh-api.org/docs/automated_deployment_testing.html), all Mesh implementations must be deployable via Docker and support running via either an [`online` or `offline` mode](https://www.mesh-api.org/docs/node_deployment.html#multiple-modes). **YOU MUST INSTALL DOCKER FOR THE FOLLOWING INSTRUCTIONS TO WORK. YOU CAN DOWNLOAD DOCKER [HERE](https://www.docker.com/get-started).** ### Image Installation -Running the following commands will create a Docker image called `rosetta-ethereum:latest`. +Running the following commands will create a Docker image called `mesh-ethereum:latest`. #### Installing from GitHub To download the pre-built Docker image from the latest release, run: ```text -curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-ethereum/master/install.sh | sh -s +curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-ethereum/master/install.sh | sh -s ``` -_Do not try to install rosetta-ethereum using GitHub Packages!_ +_Do not try to install mesh-ethereum using GitHub Packages!_ #### Installing from Source @@ -167,7 +162,7 @@ make build-local **Options:** `ONLINE`, `OFFLINE` **Default:** None -`MODE` determines if Rosetta can make outbound connections. +`MODE` determines if Mesh can make outbound connections. **`NETWORK`** **Type:** `String` @@ -181,7 +176,7 @@ make build-local **Options:** `8080`, any compatible port number **Default:** None -`PORT` is the port to use for Rosetta. +`PORT` is the port to use for Mesh. #### Optional Arguments @@ -197,13 +192,13 @@ make build-local **Options:** `TRUE`, `FALSE` **Default:** `FALSE` -`SKIP_GETH_ADMIN` instructs Rosetta to not use the `geth` `admin` RPC calls. This is typically disabled by hosted blockchain node services. +`SKIP_GETH_ADMIN` instructs Mesh to not use the `geth` `admin` RPC calls. This is typically disabled by hosted blockchain node services. ### Run Docker Running the commands below will start a Docker container in [detached mode](https://docs.docker.com/engine/reference/run/#detached--d), with -a data directory at `/ethereum-data` and the Rosetta API accessible at port `8080`. +a data directory at `/ethereum-data` and the Mesh API accessible at port `8080`. #### Example Commands @@ -213,7 +208,7 @@ You can run these commands from the command line. If you cloned the repository, Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/ethereum-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 30303:30303 rosetta-ethereum:latest +docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/ethereum-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 30303:30303 mesh-ethereum:latest ``` Cloned repo: @@ -225,7 +220,7 @@ make run-mainnet-online Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -e "GETH=" -p 8080:8080 -p 30303:30303 rosetta-ethereum:latest +docker run -d --rm --ulimit "nofile=100000:100000" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -e "GETH=" -p 8080:8080 -p 30303:30303 mesh-ethereum:latest ``` Cloned repo: @@ -237,7 +232,7 @@ make run-mainnet-remote geth= Uncloned repo: ```text -docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-ethereum:latest +docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 mesh-ethereum:latest ``` Cloned repo: @@ -249,7 +244,7 @@ make run-mainnet-offline Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/ethereum-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 30303:30303 rosetta-ethereum:latest +docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/ethereum-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 30303:30303 mesh-ethereum:latest ``` Cloned repo: @@ -264,7 +259,7 @@ geth attach http://127.0.0.1:8545 Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -e "GETH=" -p 8080:8080 -p 30303:30303 rosetta-ethereum:latest +docker run -d --rm --ulimit "nofile=100000:100000" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -e "GETH=" -p 8080:8080 -p 30303:30303 mesh-ethereum:latest ``` Cloned repo: @@ -276,7 +271,7 @@ make run-testnet-remote geth= Uncloned repo: ```text -docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-ethereum:latest +docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 mesh-ethereum:latest ``` Cloned repo: @@ -284,20 +279,20 @@ Cloned repo: make run-testnet-offline ``` -## Test the Implementation with rosetta-cli +## Test the Implementation with mesh-cli -To validate `rosetta-ethereum`, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install) +To validate `mesh-ethereum`, [install `mesh-cli`](https://github.com/coinbase/mesh-cli#install) and run one of the following commands: -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `testnet` node. It also ensures that the implementation does not miss any balance-changing operations. -* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the `testnet` network. -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `mainnet` node. It also ensures that the implementation does not miss any balance-changing operations. +* `mesh-cli check:data --configuration-file mesh-cli-conf/testnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `testnet` node. It also ensures that the implementation does not miss any balance-changing operations. +* `mesh-cli check:construction --configuration-file mesh-cli-conf/testnet/config.json` - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the `testnet` network. +* `mesh-cli check:data --configuration-file mesh-cli-conf/mainnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `mainnet` node. It also ensures that the implementation does not miss any balance-changing operations. -Read the [How to Test your Rosetta Implementation](https://www.rosetta-api.org/docs/rosetta_test.html) documentation for additional details. +Read the [How to Test your Mesh Implementation](https://www.mesh-api.org/docs/mesh_test.html) documentation for additional details. ## Contributing -You may contribute to the `rosetta-ethereum` project in various ways: +You may contribute to the `mesh-ethereum` project in various ways: * [Asking Questions](CONTRIBUTING.md/#asking-questions) * [Providing Feedback](CONTRIBUTING.md/#providing-feedback) @@ -305,36 +300,36 @@ You may contribute to the `rosetta-ethereum` project in various ways: Read our [Contributing](CONTRIBUTING.MD) documentation for more information. -When you've finished an implementation for a blockchain, share your work in the [ecosystem category of the community site](https://community.rosetta-api.org/c/ecosystem). Platforms looking for implementations for certain blockchains will be monitoring this section of the website for high-quality implementations they can use for integration. Make sure that your implementation meets the [expectations](https://www.rosetta-api.org/docs/node_deployment.html) of any implementation. +When you've finished an implementation for a blockchain, share your work in the [ecosystem category of the community site](https://community.mesh-api.org/c/ecosystem). Platforms looking for implementations for certain blockchains will be monitoring this section of the website for high-quality implementations they can use for integration. Make sure that your implementation meets the [expectations](https://www.mesh-api.org/docs/node_deployment.html) of any implementation. -You can also find community implementations for a variety of blockchains in the [rosetta-ecosystem](https://github.com/coinbase/rosetta-ecosystem) repository. +You can also find community implementations for a variety of blockchains in the [mesh-ecosystem](https://github.com/coinbase/mesh-ecosystem) repository. ## Documentation -You can find the Rosetta API documentation at [rosetta-api.org](https://www.rosetta-api.org/docs/welcome.html). +You can find the Mesh API documentation at [mesh-api.org](https://www.mesh-api.org/docs/welcome.html). -Check out the [Getting Started](https://www.rosetta-api.org/docs/getting_started.html) section to start diving into Rosetta. +Check out the [Getting Started](https://www.mesh-api.org/docs/getting_started.html) section to start diving into Mesh. Our documentation is divided into the following sections: -* [Product Overview](https://www.rosetta-api.org/docs/welcome.html) -* [Getting Started](https://www.rosetta-api.org/docs/getting_started.html) -* [Rosetta API Spec](https://www.rosetta-api.org/docs/Reference.html) -* [Samples](https://www.rosetta-api.org/docs/reference-implementations.html) -* [Testing](https://www.rosetta-api.org/docs/rosetta_cli.html) -* [Best Practices](https://www.rosetta-api.org/docs/node_deployment.html) -* [Repositories](https://www.rosetta-api.org/docs/rosetta_specifications.html) +* [Product Overview](https://www.mesh-api.org/docs/welcome.html) +* [Getting Started](https://www.mesh-api.org/docs/getting_started.html) +* [Mesh API Spec](https://www.mesh-api.org/docs/Reference.html) +* [Samples](https://www.mesh-api.org/docs/reference-implementations.html) +* [Testing](https://www.mesh-api.org/docs/mesh_cli.html) +* [Best Practices](https://www.mesh-api.org/docs/node_deployment.html) +* [Repositories](https://www.mesh-api.org/docs/mesh_specifications.html) ## Related Projects -* [rosetta-geth-sdk](https://github.com/coinbase/rosetta-geth-sdk) — This SDK helps accelerate Rosetta API implementation on go-ethereum based chains. -* [rosetta-sdk-go](https://github.com/coinbase/rosetta-sdk-go) — The `rosetta-sdk-go` SDK provides a collection of packages used for interaction with the Rosetta API specification. -* [rosetta-specifications](https://github.com/coinbase/rosetta-specifications) — Much of the SDKs’ code is generated from this repository. -* [rosetta-cli](https://github.com/coinbase/rosetta-ecosystem) — Use the `rosetta-cli` tool to test your Rosetta API implementation. The tool also provides the ability to look up block contents and account balances. +* [mesh-geth-sdk](https://github.com/coinbase/mesh-geth-sdk) — This SDK helps accelerate Mesh API implementation on go-ethereum based chains. +* [mesh-sdk-go](https://github.com/coinbase/mesh-sdk-go) — The `mesh-sdk-go` SDK provides a collection of packages used for interaction with the Mesh API specification. +* [mesh-specifications](https://github.com/coinbase/mesh-specifications) — Much of the SDKs’ code is generated from this repository. +* [mesh-cli](https://github.com/coinbase/mesh-ecosystem) — Use the `mesh-cli` tool to test your Mesh API implementation. The tool also provides the ability to look up block contents and account balances. ### Other Implementation Samples -You can find community implementations for a variety of blockchains in the [rosetta-ecosystem](https://github.com/coinbase/rosetta-ecosystem) repository, and in the [ecosystem category](https://community.rosetta-api.org/c/ecosystem) of our community site. +You can find community implementations for a variety of blockchains in the [mesh-ecosystem](https://github.com/coinbase/mesh-ecosystem) repository, and in the [ecosystem category](https://community.mesh-api.org/c/ecosystem) of our community site. ## License diff --git a/ethereum/graphql_client.go b/ethereum/graphql_client.go index 05b5cdd..6913f00 100644 --- a/ethereum/graphql_client.go +++ b/ethereum/graphql_client.go @@ -18,7 +18,8 @@ import ( "bytes" "context" "encoding/json" - "io/ioutil" + "fmt" + "io" "net/http" "net/url" "path" @@ -64,9 +65,14 @@ func (g *GraphQLClient) Query(ctx context.Context, input string) (string, error) if err != nil { return "", err } - defer response.Body.Close() + defer func() { + if cerr := response.Body.Close(); cerr != nil { + // Log or handle the error + fmt.Printf("Failed to close response body: %v", cerr) + } + }() - data, err := ioutil.ReadAll(response.Body) + data, err := io.ReadAll(response.Body) if err != nil { return "", err }