Skip to content
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

Bentobox: Microservice to extract data from parity into IPFS #7

Merged
10 commits merged into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,20 @@ block-header-syncer:
./build/modify-geth
go build -v -o ./build/bin/block-header-syncer ./services/block-header-syncer/*.go

bentobox:
go build -v -o ./build/bin/bentobox ./services/bentobox/*.go

custom-psql-image:
docker build docker/custom-psql/. -t mustekala-psql

run-psql:
docker run \
-ti --rm \
--net=host \
--name psql \
-e POSTGRES_PASSWORD=mysecretpassword \
-v ${PWD}/services/bentobox:/workdir \
-v ${HOME}/.psql:/var/lib/postgresql/data \
mustekala-psql
clean:
rm -rf build/bin/*
rm -rf build/bin/*
2 changes: 2 additions & 0 deletions docker/custom-psql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM postgres:10.3
ADD config.sh /docker-entrypoint-initdb.d/
4 changes: 4 additions & 0 deletions docker/custom-psql/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

sed -ri "s/#log_statement = 'none'/log_statement = 'all'/g" /var/lib/postgresql/data/postgresql.conf
74 changes: 74 additions & 0 deletions services/bentobox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## BentoBox

Microservice. Polls a *parity* or *go-ethereum* JSON/RPC endpoint.
On new block header it will extract certain specified data.

### Quick Start

If you don't have a PSQL at hand, run one using docker, with the instructions
in the below section "Run and Configure a PostgreSQL using docker"

make bentobox && ./build/bin/bentobox

### Run and Configure a PostgreSQL DB using docker

Create this custom container (logs all queries)

```
make custom-psql-image
```

Then, just use the command, always from this repository root

```
make run-psql
```

Will mount the dir `$HOME/.psql` and have a DB for you.

You need to setup your database if it is the first time using it.
Use the instructions below.

#### Setup the database

You can have your database already, or you can use docker as above.
This script will set you up with your database.

Get in a console able to use `psql` and Run

```
psql -U postgres
```

*TIP*: If you are running PSQL with docker,
to access bash inside the container do

```
docker exec -ti <psql-container> /bin/bash
```

Once inside you create your database with

```
CREATE DATABASE bentobox;
\q
```

Now you need to restore the schema. Do from the comamnd line

```
psql -U postgres bentobox < database.sql
```

You are good to go.

### Command Line Options

| Options | Description | Default |
| --- | --- | --- |
| dbname | Postgres DB name | bentobox |
| dbuser | Postgres DB user name | postgres |
| dbpassword | Postgres DB user password | mysecretpassword |
| eth-host | URL of the ethereum JSON RPC source of data | http://127.0.0.1:8545/ |
| ipfs-host | URL of the ipfs HTTP API | http://127.0.0.1:5001/ |
| last-block-polling-interval | value in seconds for the last block polling | 1 |
17 changes: 17 additions & 0 deletions services/bentobox/cheatsheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Cheatsheet

### Get the last block in the canonical chain

curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' http://tigress.musteka.la:8545

### Get the block body. i.e. block header + txs + ommers

curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1b4", true],"id":1}' http://tigress.musteka.la:8545

### Get the info of one specific tx (you don't really need that, see above)

curl -H 'Content-Type: application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x3f9d0c7c39f9dad2a41254af6ca3e531be06db9739cbf9d9343c52e592267adc"],"id":1}' http://tigress.musteka.la:8545

### Get the transaction receipt

curl -H 'Content-Type: application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x3f9d0c7c39f9dad2a41254af6ca3e531be06db9739cbf9d9343c52e592267adc"],"id":1}' http://tigress.musteka.la:8545
Loading