2017-10-19 14:45:37 +00:00
# Vulcanize DB
2017-10-31 14:13:26 +00:00
[![Build Status ](https://travis-ci.com/8thlight/vulcanizedb.svg?token=GKv2Y33qsFnfYgejjvYx&branch=master )](https://travis-ci.com/8thlight/vulcanizedb)
2017-10-19 14:45:37 +00:00
## Development Setup
2017-10-19 14:38:47 +00:00
2017-10-25 14:01:13 +00:00
### Dependencies
- Go 1.9+
2017-10-25 15:05:29 +00:00
- https://github.com/golang/dep
2017-10-26 15:04:45 +00:00
- `go get -u github.com/golang/dep/cmd/dep`
2017-11-01 15:17:01 +00:00
- https://github.com/go-godo/godo
- `go get -u gopkg.in/godo.v2/cmd/godo`
2017-12-20 20:06:22 +00:00
- Postgres 10
- Go Ethereum
- https://ethereum.github.io/go-ethereum/downloads/
2017-10-25 14:01:13 +00:00
### Cloning the Repository
2017-10-19 14:38:47 +00:00
1. `git config --global url."git@github.com:".insteadOf "https://github.com/"`
2017-10-25 14:01:13 +00:00
- By default, `go get` does not work for private GitHub repos. This will fix that.
2017-10-19 14:38:47 +00:00
2. `go get github.com/8thlight/vulcanizedb`
2017-12-20 20:06:22 +00:00
3. `cd $GOPATH/src/github.com/8thlight/vulcanizedb`
4. `dep ensure`
2017-10-25 14:01:13 +00:00
2017-11-01 15:17:01 +00:00
### Setting up the Databases
2017-10-25 15:05:29 +00:00
1. Install Postgres
2. Create a superuser for yourself and make sure `psql --list` works without prompting for a password.
3. `go get -u -d github.com/mattes/migrate/cli github.com/lib/pq`
4. `go build -tags 'postgres' -o /usr/local/bin/migrate github.com/mattes/migrate/cli`
2017-11-03 21:52:19 +00:00
5. `createdb vulcanize_private`
6. `cd $GOPATH/src/github.com/8thlight/vulcanizedb`
7. `godo migrate -- --environment=<some-environment>`
* See below for configuring additional environments
2017-10-25 15:05:29 +00:00
2017-10-27 19:18:12 +00:00
Adding a new migration: `./scripts/create_migration <migration-name>`
2017-10-25 15:05:29 +00:00
2017-10-25 14:01:13 +00:00
### Creating/Using a Private Blockchain
Syncing the public blockchain takes many hours for the initial sync and will download 20+ GB of data.
Here are some instructions for creating a private blockchain that does not depend on having a network connection.
1. Run `./scripts/setup` to create a private blockchain with a new account.
* This will result in a warning.
2. Run `./scripts/start_private_blockchain` .
2017-11-03 21:52:19 +00:00
3. Run `godo run -- --environment=private` to start listener.
2017-10-25 14:01:13 +00:00
### Connecting to the Public Blockchain
`./scripts/start_blockchain`
### IPC File Paths
2017-10-25 18:27:42 +00:00
The default location for Ethereum is:
2017-10-25 14:01:13 +00:00
- `$HOME/Library/Ethereum` for Mac
- `$HOME/.ethereum` for Ubuntu
- `$GOPATH/src/gihub.com/8thlight/vulcanizedb/test_data_dir/geth.ipc` for private blockchain.
2017-10-19 14:38:47 +00:00
2017-11-03 21:52:19 +00:00
**Note the location of the ipc file is outputted when you connect to a blockchain. It is needed to for configuration**
2017-10-25 18:27:42 +00:00
2017-12-20 20:06:22 +00:00
## Start Vulcanize DB
1. Start a blockchain.
2. In a separate terminal start vulcanize_db
- `godo vulcanizeDb -- --environment=<some-environment>`
2017-10-25 18:27:42 +00:00
## Running Listener
1. Start a blockchain.
2. In a separate terminal start listener (ipcDir location)
2017-11-03 21:52:19 +00:00
- `godo run -- --environment=<some-environment>`
2017-11-06 20:36:12 +00:00
## Retrieving Historical Data
1. Start a blockchain.
2. In a separate terminal start listener (ipcDir location)
- `godo populateBlocks -- --environment=<some-environment> --starting-number=<starting-block-number>`
2017-11-28 21:14:05 +00:00
## Retrieve Contract Attributes
1. Add contract ABI to contracts / environment directory:
```
vulcanizedb/
contracts/
public/
< contract-address > .json
private/
```
2018-01-08 21:59:47 +00:00
The name of the JSON file should correspond the contract's address.
2. Start watching the contract `godo watchContract -- --environment=<some-environment> --contract-hash=<contract-address>`
2017-11-28 21:14:05 +00:00
3. Request summary data `godo showContractSummary -- --environment=<some-environment> --contract-hash=<contract-address>`
2017-11-03 21:52:19 +00:00
2017-12-11 21:08:00 +00:00
## Retrieving Contract Logs
2017-12-22 17:42:35 +00:00
1. Get the logs for a specific contract
- `godo getLogs -- --environment=<some-environment> --contract-hash=<contract-address>`
2017-12-11 21:08:00 +00:00
2017-11-03 21:52:19 +00:00
### Configuring Additional Environments
You can create configuration files for additional environments.
* Among other things, it will require the IPC file path
2017-11-14 15:10:48 +00:00
* See `environments/private.toml` for an example
2017-11-03 21:52:19 +00:00
* You will need to do this if you want to run a node connecting to the public blockchain
2017-10-25 18:27:42 +00:00
2017-10-19 14:45:37 +00:00
## Running the Tests
2017-10-19 14:38:47 +00:00
2017-12-20 20:06:22 +00:00
### Unit Tests
2017-10-24 14:24:07 +00:00
2017-12-20 20:06:22 +00:00
1. `go test ./pkg/...`
2017-10-24 14:24:07 +00:00
2017-12-20 20:06:22 +00:00
### Integration Test
2017-10-24 14:24:07 +00:00
2017-12-20 20:06:22 +00:00
In order to run the integration tests, you will need to run them against a real blockchain. At the moment the integration tests require [Geth v1.7.2 ](https://ethereum.github.io/go-ethereum/downloads/ ) as they depend on the `--dev` mode, which changed in v1.7.3
2017-10-24 14:24:07 +00:00
2017-12-20 20:06:22 +00:00
1. Run `./scripts/start_private_blockchain` as a separate process.
2. `go test ./...` to run all tests.