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

Draft V2 #4

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/docker
/geth+
/data
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/docker/**
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:alpine

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go build -o main .

WORKDIR /dist

RUN cp /build/main .

# Expose ports (when we have WS or REST endpoints)
# EXPOSE 3000

# start container
CMD ["/dist/main"]
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Helios

**Note**: working on v0.2, check back soon!
# Helios V2

Helios is a tool built on-top of [go-ethereum](https://github.com/ethereum/go-ethereum) and the [ELK stack](https://www.elastic.co/what-is/elk-stack) to query and monitor the mempool.

Expand Down
69 changes: 69 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package config

import (
"os"
"gopkg.in/yaml.v2"
)

type Config struct {
Helios struct {
NodeUrl string `yaml:"nodeUrl"`, // node ws url
Mode string `yaml:"mode"`, // quick or full
} `yaml:"helios"`

Postgres struct {
PostgresHot string `yaml:"postgres_host"`
PostgresUser string `yaml:"postgres_user"`
PostgresPassword string `yaml:"postgres_password"`
} `yaml:"postgres"`

Redis struct {
RedisHost string `yaml:"redis_host"`
RedisUser string `yaml:"redis_user"`
RedisPassword string `yaml:"redis_password"`
} `yaml:"redis"`
}

func NewConfig(configPath string) (*Config, err) {
config := &Config{}

file, err := os.Open(configPath)

if err != nil {
return nil, err
}

defer file.Close()

decoder := yaml.NewDecoder(file)

if err := decoder.Decode(&config); err != nil {
return nil, err
}
return config, nil
}

func ValidatePath(path string) error {
s, err := os.Stat(path)
if err != nil {
return err
}
if s.IsDir() {
return fmt.Errorf("'%s' is a directory, please specify a file", path)
}
return nil
}

func ParseFlags() (string, error) {
var configPath string

flag.StringVar(&configPath, "ocnfig", "./helios.yml", "path to yaml config for helios")

flag.Parse()

if err := ValidatePath(configPath); err != nil {
return "", err
}

return configPath, nil
}
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.7'

services:
postgres:
image: postgres:10.5
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5432:5432'
container_name: postgres
volumes:
- ./postgres-data:/var/lib/postgresql/data
# sql script to create tables
- ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
redis:
image: 'redis:6'
ports:
- '6379:6379'
container_name: redis
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ require (
github.com/joho/godotenv v1.3.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/logrusorgru/aurora/v3 v3.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@ gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHO
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
10 changes: 10 additions & 0 deletions helios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
helios:
nodeUrl: 'ws://xx.xx.xx:8547'
postgres:
postgres_host: ''
postgres_user: ''
postgres_password: ''
redis:
redis_host: ''
redis_user: ''
redis_password: ''
File renamed without changes.
48 changes: 48 additions & 0 deletions sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CREATE TABLE transactions IF NOT EXISTS
(
hash PRIMARY KEY varchar(66),
nonce bigint,
transaction_index bigint,
from_address varchar(42),
to_address varchar(42),
value numeric(38),
gas bigint,
gas_price bigint,
input text,
receipt_cumulative_gas_used bigint,
receipt_gas_used bigint,
receipt_contract_address varchar(42),
receipt_root varchar(66),
receipt_status bigint,
block_timestamp timestamp,
block_number bigint,
block_hash varchar(66),
max_fee_per_gas bigint,
max_priority_fee_per_gas bigint,
transaction_type bigint,
receipt_effective_gas_price bigint
);

CREATE TABLE liquidation_attempts IF NOT EXISTS
(
hash PRIMARY KEY varchar(66)
liquidator varchar(42)
loan_owner varchar(42)
gas_price bigint,
repayAmount bigint,
time timestamp,
collateralAddress varchar(42)
debtAddress varchar(42)
block_number bigint
isMined boolean
)

CREATE TABLE trade_attempts IF NOT EXISTS
(
hash PRIMARY KEY varchar(66)
from varchar(42)
to varchar(42)
fromAmount bigInt
toAmount bigInt
isMined boolean
)