2017-10-19 14:45:37 +00:00
# Vulcanize DB
2018-01-25 23:19:15 +00:00
2019-04-01 20:50:43 +00:00
[![Build Status ](https://travis-ci.org/vulcanize/vulcanizedb.svg?branch=master )](https://travis-ci.org/vulcanize/vulcanizedb)
2020-05-30 03:02:47 +00:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/vulcanize/ipfs-chain-watcher )](https://goreportcard.com/report/github.com/vulcanize/ipfs-chain-watcher)
2017-10-19 14:38:47 +00:00
2019-04-05 15:10:34 +00:00
> Vulcanize DB is a set of tools that make it easier for developers to write application-specific indexes and caches for dapps built on Ethereum.
## Table of Contents
2019-05-10 15:21:08 +00:00
1. [Background ](#background )
1. [Install ](#install )
1. [Usage ](#usage )
1. [Contributing ](#contributing )
1. [License ](#license )
2019-04-05 15:10:34 +00:00
## Background
The same data structures and encodings that make Ethereum an effective and trust-less distributed virtual machine
2019-05-08 16:44:04 +00:00
complicate data accessibility and usability for dApp developers. VulcanizeDB improves Ethereum data accessibility by
providing a suite of tools to ease the extraction and transformation of data into a more useful state, including
allowing for exposing aggregate data from a suite of smart contracts.
2018-06-20 21:55:33 +00:00
2019-05-07 21:21:08 +00:00
VulanizeDB includes processes that sync, transform and expose data. Syncing involves
querying an Ethereum node and then persisting core data into a Postgres database. Transforming focuses on using previously synced data to
query for and transform log event and storage data for specifically configured smart contract addresses. Exposing data is a matter of getting
data from VulcanizeDB's underlying Postgres database and making it accessible.
2018-06-20 21:55:33 +00:00
2019-05-10 15:21:08 +00:00
![VulcanizeDB Overview Diagram ](documentation/diagrams/vdb-overview.png )
2019-05-08 16:44:04 +00:00
2019-05-13 18:44:20 +00:00
## Install
1. [Dependencies ](#dependencies )
1. [Building the project ](#building-the-project )
1. [Setting up the database ](#setting-up-the-database )
1. [Configuring a synced Ethereum node ](#configuring-a-synced-ethereum-node )
### Dependencies
2019-07-17 20:29:24 +00:00
- Go 1.12+
2019-05-14 21:49:05 +00:00
- Postgres 11.2
2018-03-07 21:34:55 +00:00
- Ethereum Node
2019-03-03 09:37:27 +00:00
- [Go Ethereum ](https://ethereum.github.io/go-ethereum/downloads/ ) (1.8.23+)
2018-03-07 21:34:55 +00:00
- [Parity 1.8.11+ ](https://github.com/paritytech/parity/releases )
2018-01-29 19:44:18 +00:00
2019-04-08 16:47:56 +00:00
### Building the project
2019-04-05 15:10:34 +00:00
Download the codebase to your local `GOPATH` via:
2018-08-06 15:25:31 +00:00
2020-05-30 03:02:47 +00:00
`go get github.com/vulcanize/ipfs-chain-watcher`
2017-10-25 15:05:29 +00:00
2019-07-17 20:29:24 +00:00
Move to the project directory:
2018-08-06 15:25:31 +00:00
2020-05-30 03:02:47 +00:00
`cd $GOPATH/src/github.com/vulcanize/ipfs-chain-watcher`
2018-08-06 15:25:31 +00:00
2019-07-17 20:29:24 +00:00
Be sure you have enabled Go Modules (`export GO111MODULE=on`), and build the executable with:
2018-08-06 15:25:31 +00:00
2019-04-08 16:47:56 +00:00
`make build`
2018-08-06 15:25:31 +00:00
2019-07-17 20:29:24 +00:00
If you need to use a different dependency than what is currently defined in `go.mod` , it may helpful to look into [the replace directive ](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive ).
This instruction enables you to point at a fork or the local filesystem for dependency resolution.
2019-04-08 16:47:56 +00:00
If you are running into issues at this stage, ensure that `GOPATH` is defined in your shell.
If necessary, `GOPATH` can be set in `~/.bashrc` or `~/.bash_profile` , depending upon your system.
It can be additionally helpful to add `$GOPATH/bin` to your shell's `$PATH` .
2018-08-06 15:25:31 +00:00
2019-04-05 15:10:34 +00:00
### Setting up the database
2017-10-25 15:05:29 +00:00
1. Install Postgres
2018-03-21 18:44:01 +00:00
1. Create a superuser for yourself and make sure `psql --list` works without prompting for a password.
2018-04-09 16:51:21 +00:00
1. `createdb vulcanize_public`
2020-05-30 03:02:47 +00:00
1. `cd $GOPATH/src/github.com/vulcanize/ipfs-chain-watcher`
2018-04-11 16:00:25 +00:00
1. Run the migrations: `make migrate HOST_NAME=localhost NAME=vulcanize_public PORT=5432`
2019-04-11 17:14:04 +00:00
- There is an optional var `USER=username` if the database user is not the default user `postgres`
2019-01-24 10:54:25 +00:00
- To rollback a single step: `make rollback NAME=vulcanize_public`
- To rollback to a certain migration: `make rollback_to MIGRATION=n NAME=vulcanize_public`
- To see status of migrations: `make migration_status NAME=vulcanize_public`
2018-01-26 19:38:14 +00:00
2017-11-03 21:52:19 +00:00
* See below for configuring additional environments
2019-04-05 15:10:34 +00:00
2019-05-10 15:21:08 +00:00
In some cases (such as recent Ubuntu systems), it may be necessary to overcome failures of password authentication from
localhost. To allow access on Ubuntu, set localhost connections via hostname, ipv4, and ipv6 from peer/md5 to trust in: /etc/postgresql/< version > /pg_hba.conf
2018-01-26 19:51:13 +00:00
2019-04-05 15:10:34 +00:00
(It should be noted that trusted auth should only be enabled on systems without sensitive data in them: development and local test databases)
2018-08-22 17:44:35 +00:00
2019-04-05 15:10:34 +00:00
### Configuring a synced Ethereum node
2018-04-09 16:51:21 +00:00
- To use a local Ethereum node, copy `environments/public.toml.example` to
2018-08-14 21:59:41 +00:00
`environments/public.toml` and update the `ipcPath` and `levelDbPath` .
2018-05-02 16:17:02 +00:00
- `ipcPath` should match the local node's IPC filepath:
2018-08-06 15:25:31 +00:00
- For Geth:
2018-05-02 16:17:02 +00:00
- The IPC file is called `geth.ipc` .
- The geth IPC file path is printed to the console when you start geth.
- The default location is:
2019-05-07 21:21:08 +00:00
- Mac: `<full home path>/Library/Ethereum/geth.ipc`
2018-08-06 15:25:31 +00:00
- Linux: `<full home path>/ethereum/geth.ipc`
2019-05-07 21:21:08 +00:00
- Note: the geth.ipc file may not exist until you've started the geth process
2018-05-02 16:17:02 +00:00
2018-08-06 15:25:31 +00:00
- For Parity:
2018-05-02 16:17:02 +00:00
- The IPC file is called `jsonrpc.ipc` .
- The default location is:
2018-08-06 15:25:31 +00:00
- Mac: `<full home path>/Library/Application\ Support/io.parity.ethereum/`
- Linux: `<full home path>/local/share/io.parity.ethereum/`
2019-02-28 14:59:04 +00:00
2018-05-02 16:17:02 +00:00
- `levelDbPath` should match Geth's chaindata directory path.
- The geth LevelDB chaindata path is printed to the console when you start geth.
- The default location is:
2018-08-06 15:25:31 +00:00
- Mac: `<full home path>/Library/Ethereum/geth/chaindata`
- Linux: `<full home path>/ethereum/geth/chaindata`
2018-05-02 16:17:02 +00:00
- `levelDbPath` is irrelevant (and `coldImport` is currently unavailable) if only running parity.
2018-04-09 16:51:21 +00:00
2019-04-05 15:10:34 +00:00
## Usage
2019-05-07 21:21:08 +00:00
As mentioned above, VulcanizeDB's processes can be split into three categories: syncing, transforming and exposing data.
2019-04-05 15:10:34 +00:00
### Data syncing
2019-05-07 21:21:08 +00:00
To provide data for transformations, raw Ethereum data must first be synced into VulcanizeDB.
2020-02-10 15:00:55 +00:00
This is accomplished through the use of the `headerSync` command.
2019-05-13 21:04:53 +00:00
These commands are described in detail [here ](documentation/data-syncing.md ).
2019-04-05 15:10:34 +00:00
### Data transformation
2019-05-08 22:16:36 +00:00
Data transformation uses the raw data that has been synced into Postgres to filter out and apply transformations to
specific data of interest. Since there are different types of data that may be useful for observing smart contracts, it
follows that there are different ways to transform this data. We've started by categorizing this into Generic and
Custom transformers:
2019-04-05 15:10:34 +00:00
2019-05-08 22:16:36 +00:00
- Generic Contract Transformer: Generic contract transformation can be done using a built-in command,
`contractWatcher` , which transforms contract events provided the contract's ABI is available. It also
provides some state variable coverage by automating polling of public methods, with some restrictions.
2019-05-10 15:21:08 +00:00
`contractWatcher` is described further [here ](documentation/generic-transformer.md ).
2019-04-05 15:10:34 +00:00
2019-05-08 22:16:36 +00:00
- Custom Transformers: In many cases custom transformers will need to be written to provide
more comprehensive coverage of contract data. In this case we have provided the `compose` , `execute` , and
`composeAndExecute` commands for running custom transformers from external repositories. Documentation on how to write,
build and run custom transformers as Go plugins can be found
2019-05-10 15:21:08 +00:00
[here ](documentation/custom-transformers.md ).
2019-04-05 15:10:34 +00:00
2019-05-07 21:21:08 +00:00
### Exposing the data
2019-05-10 15:21:08 +00:00
[Postgraphile ](https://www.graphile.org/postgraphile/ ) is used to expose GraphQL endpoints for our database schemas, this is described in detail [here ](documentation/postgraphile.md ).
2019-04-19 15:13:27 +00:00
2019-04-05 15:10:34 +00:00
2019-05-13 18:44:20 +00:00
### Tests
2019-10-31 16:19:34 +00:00
- Replace the empty `ipcPath` in the `environments/testing.toml` with a path to a full node's eth_jsonrpc endpoint (e.g. local geth node ipc path or infura url)
- Note: must be mainnet
2019-04-08 16:47:56 +00:00
- Note: integration tests require configuration with an archival node
2018-10-17 18:04:55 +00:00
- `make test` will run the unit tests and skip the integration tests
2019-04-05 15:10:34 +00:00
- `make integrationtest` will run just the integration tests
2019-10-31 16:19:34 +00:00
- `make test` and `make integrationtest` setup a clean `vulcanize_testing` db
2019-02-25 09:33:05 +00:00
2019-04-05 15:10:34 +00:00
## Contributing
2019-05-08 18:19:32 +00:00
Contributions are welcome!
2019-04-05 15:10:34 +00:00
2019-05-10 15:07:25 +00:00
VulcanizeDB follows the [Contributor Covenant Code of Conduct ](https://www.contributor-covenant.org/version/1/4/code-of-conduct ).
2019-04-05 15:10:34 +00:00
2019-05-10 15:21:08 +00:00
For more information on contributing, please see [here ](documentation/contributing.md ).
2019-04-05 15:10:34 +00:00
## License
2019-05-10 15:21:08 +00:00
[AGPL-3.0 ](LICENSE ) © Vulcanize Inc