diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..f0047da74 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/docker +/geth+ +/data diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..97e148ad0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/docker/** diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..93f0ab3d7 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 233e80180..d5b6b6987 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config/config.go b/config/config.go new file mode 100644 index 000000000..61cc6fc71 --- /dev/null +++ b/config/config.go @@ -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 +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..13be79055 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/go.mod b/go.mod index a63a892f7..0ec0fcea1 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index e64d08888..3219ecefd 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/helios.yml b/helios.yml new file mode 100644 index 000000000..4902dd023 --- /dev/null +++ b/helios.yml @@ -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: '' \ No newline at end of file diff --git a/helios.go b/main.go similarity index 100% rename from helios.go rename to main.go diff --git a/sql/create_tables.sql b/sql/create_tables.sql new file mode 100644 index 000000000..aa7f2b1f3 --- /dev/null +++ b/sql/create_tables.sql @@ -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 +)