From f14c7d159fccb00b5c0df014f8ec0bac0d4b4887 Mon Sep 17 00:00:00 2001 From: Ryan Arthur Date: Mon, 29 Oct 2018 15:28:23 -0400 Subject: [PATCH 01/14] Highlight code tab icon --- .../lib/block_scout_web/templates/address/_tabs.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex index a289b2f8e4..d9c56c6ecc 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex @@ -44,7 +44,7 @@ <%= gettext("Code") %> <%= if smart_contract_verified?(@address) do %> - + <% end %> <% end %> From da47588cb90c44dd4d81fe780892e617eac79a9e Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Thu, 18 Oct 2018 16:36:32 +0200 Subject: [PATCH 02/14] Fix ping/pong from ganache ws implementation --- .../lib/ethereum_jsonrpc/web_socket/web_socket_client.ex | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex index 8878253793..293198ed9a 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex @@ -265,6 +265,11 @@ defmodule EthereumJSONRPC.WebSocket.WebSocketClient do respond_to_registration(registration, response, new_state) end + # Sending pong (Ganache requirement) + defp handle_response({:ping, ""}, %__MODULE__{} = state) do + {:ok, {:pong, ""}, state} + end + defp handle_response(response, %__MODULE__{} = state) do Logger.error(fn -> [ From 802cb2d838cd371c4123926b35c2509cff747631 Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Thu, 18 Oct 2018 16:43:52 +0200 Subject: [PATCH 03/14] Cleanup --- .../lib/ethereum_jsonrpc/web_socket/web_socket_client.ex | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex index 293198ed9a..8878253793 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex @@ -265,11 +265,6 @@ defmodule EthereumJSONRPC.WebSocket.WebSocketClient do respond_to_registration(registration, response, new_state) end - # Sending pong (Ganache requirement) - defp handle_response({:ping, ""}, %__MODULE__{} = state) do - {:ok, {:pong, ""}, state} - end - defp handle_response(response, %__MODULE__{} = state) do Logger.error(fn -> [ From c1d1385abb9b76d8621d79ca8a5eb8bf53d95403 Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Mon, 22 Oct 2018 19:25:59 +0300 Subject: [PATCH 04/14] Added docker files --- .dockerignore | 5 +++++ Dockerfile | 38 ++++++++++++++++++++++++++++++++++++ apps/explorer/config/dev.exs | 4 ++-- apps/indexer/config/dev.exs | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..f2c7590ef7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +_build +deps +apps/block_scout_web/assets/node_modules +apps/explorer/node_modules +test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..e9483c9c76 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM bitwalker/alpine-elixir-phoenix:latest + +RUN apk --no-cache --update add automake libtool inotify-tools autoconf + +EXPOSE 4000 + +ENV PORT=4000 \ + MIX_ENV="prod" \ + ETHEREUM_JSONRPC_VARIANT="ganache" \ + ETHEREUM_JSONRPC_HTTP_URL="http://host.docker.internal:7545" \ + ETHEREUM_JSONRPC_WEB_SOCKET_URL="ws://host.docker.internal:7545" \ + POSTGRES_URL="host.docker.internal" \ + DATABASE_URL="postgresql://postgres:@host.docker.internal:5432/explorer?ssl=false" \ + SECRET_KEY_BASE="RMgI4C1HSkxsEjdhtGMfwAHfyT6CKWXOgzCboJflfSm4jeAlic52io05KB6mqzc5" + +# Cache elixir deps +ADD mix.exs mix.lock ./ +ADD apps/block_scout_web/mix.exs ./apps/block_scout_web/ +ADD apps/explorer/mix.exs ./apps/explorer/ +ADD apps/ethereum_jsonrpc/mix.exs ./apps/ethereum_jsonrpc/ +ADD apps/indexer/mix.exs ./apps/indexer/ + +RUN mix do deps.get, deps.compile + +ADD . . + +# Run forderground build and phoenix digest +RUN mix do compile, phx.digest + +# Add blockscout npm deps +RUN cd apps/block_scout_web/assets/ && npm install && npm run deploy && cd - +RUN cd apps/explorer/ && npm install && cd - + +RUN mix do ecto.drop --force, ecto.create, ecto.migrate + +# USER default + +CMD ["mix", "phx.server"] diff --git a/apps/explorer/config/dev.exs b/apps/explorer/config/dev.exs index d6363c383c..50b0f88f78 100644 --- a/apps/explorer/config/dev.exs +++ b/apps/explorer/config/dev.exs @@ -4,7 +4,7 @@ use Mix.Config config :explorer, Explorer.Repo, adapter: Ecto.Adapters.Postgres, database: "explorer_dev", - hostname: "localhost", + hostname: System.get_env("POSTGRES_URL") || "localhost", pool_size: 20, pool_timeout: 60_000, timeout: 80_000 @@ -17,7 +17,7 @@ import_config "dev.secret.exs" variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" + "ganache" else System.get_env("ETHEREUM_JSONRPC_VARIANT") |> String.split(".") diff --git a/apps/indexer/config/dev.exs b/apps/indexer/config/dev.exs index 2f445c38dc..337e2f9b97 100644 --- a/apps/indexer/config/dev.exs +++ b/apps/indexer/config/dev.exs @@ -11,7 +11,7 @@ config :logger, :indexer_token_balances, variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "parity" + "ganache" else System.get_env("ETHEREUM_JSONRPC_VARIANT") |> String.split(".") From 5af2b83d829de26356ee45f56b25b7b57b4c6f06 Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Tue, 23 Oct 2018 10:47:06 +0300 Subject: [PATCH 05/14] Updated docker integration --- Dockerfile | 1 - docker-compose.yml | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index e9483c9c76..5886275757 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ ENV PORT=4000 \ ETHEREUM_JSONRPC_VARIANT="ganache" \ ETHEREUM_JSONRPC_HTTP_URL="http://host.docker.internal:7545" \ ETHEREUM_JSONRPC_WEB_SOCKET_URL="ws://host.docker.internal:7545" \ - POSTGRES_URL="host.docker.internal" \ DATABASE_URL="postgresql://postgres:@host.docker.internal:5432/explorer?ssl=false" \ SECRET_KEY_BASE="RMgI4C1HSkxsEjdhtGMfwAHfyT6CKWXOgzCboJflfSm4jeAlic52io05KB6mqzc5" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..9c115cb0f8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' +services: + blockscout: + build: . + ports: + - "4000:4000" + environment: + ETHEREUM_JSONRPC_HTTP_URL: "http://host.docker.internal:2000" + ETHEREUM_JSONRPC_WEB_SOCKET_URL: "ws://host.docker.internal:2000" + From ae62c047f619a8aae4e59c777cf4b910d1acdd98 Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Wed, 24 Oct 2018 18:57:03 +0300 Subject: [PATCH 06/14] Updated dockerfile --- Dockerfile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5886275757..8325ad9170 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,14 +24,20 @@ RUN mix do deps.get, deps.compile ADD . . # Run forderground build and phoenix digest -RUN mix do compile, phx.digest +RUN mix compile # Add blockscout npm deps -RUN cd apps/block_scout_web/assets/ && npm install && npm run deploy && cd - -RUN cd apps/explorer/ && npm install && cd - +RUN cd apps/block_scout_web/assets/ && \ + npm install && \ + npm run deploy && \ + cd - -RUN mix do ecto.drop --force, ecto.create, ecto.migrate +RUN cd apps/explorer/ && \ + npm install && \ + cd - + +# RUN mix do ecto.drop --force, ecto.create, ecto.migrate # USER default -CMD ["mix", "phx.server"] +# CMD ["mix", "phx.server"] From d1477f085984f225198eca48afbe62ca27aba98c Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Thu, 25 Oct 2018 15:58:05 +0300 Subject: [PATCH 07/14] Updated makefile --- Makefile | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..3de6a1460a --- /dev/null +++ b/Makefile @@ -0,0 +1,80 @@ +SYSTEM = $(shell uname -s) +HOST = host.docker.internal +DOCKER_IMAGE = blockscout_prod +PG_CONTAINER_NAME = postgres +PG_CONTAINER_IMAGE = postgres:10.4 +THIS_FILE = $(lastword $(MAKEFILE_LIST)) + +ifeq ($(SYSTEM), Linux) + HOST=localhost +endif + +DB_URL = postgresql://postgres:@$(HOST):5432/explorer?ssl=false +BLOCKSCOUT_CONTAINNER_PARAMS = -e 'MIX_ENV=prod' \ + -e 'DATABASE_URL=$(DB_URL)' +ifeq ($(SYSTEM), Linux) + BLOCKSCOUT_CONTAINNER_PARAMS += --network=host +endif +ifdef ETHEREUM_JSONRPC_VARIANT + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_VARIANT=$(ETHEREUM_JSONRPC_VARIANT)' +endif +ifdef ETHEREUM_JSONRPC_HTTP_URL + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_HTTP_URL=$(ETHEREUM_JSONRPC_HTTP_URL)' +endif +ifdef ETHEREUM_JSONRPC_WEB_SOCKET_URL + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_WEB_SOCKET_URL=$(ETHEREUM_JSONRPC_WEB_SOCKET_URL)' +endif + +HAS_BLOCKSCOUT_IMAGE := $(shell docker images | grep ${DOCKER_IMAGE}) +build: + @echo "==> Checking for blockscout image $(DOCKER_IMAGE)" +ifdef HAS_BLOCKSCOUT_IMAGE + @echo "==> Image exist. Using $(DOCKER_IMAGE)" +else + @echo "==> No image found trying to build one..." + # @docker build -t $(DOCKER_IMAGE) . +endif + +migrate: build postgres + @echo "==> Running migrations" + @docker run --rm \ + $(BLOCKSCOUT_CONTAINNER_PARAMS) \ + $(DOCKER_IMAGE) /bin/sh -c "echo $$MIX_ENV && mix do ecto.drop --force, ecto.create, ecto.migrate" + + +PG_EXIST := $(shell docker ps -a | grep ${PG_CONTAINER_NAME}) +PG_STARTED := $(shell docker ps | grep ${PG_CONTAINER_NAME}) +postgres: +ifdef PG_EXIST + @echo "==> Checking PostrgeSQL container" +ifdef PG_STARTED + @echo "==> PostgreSQL Already started" +else + @echo "==> Starting PostgreSQL container" + @docker start $(PG_CONTAINER_NAME) +endif +else + @echo "==> Creating new PostgreSQL container" + @docker run -d --name $(PG_CONTAINER_NAME) \ + -e POSTGRES_PASSWORD="" \ + -e POSTGRES_USER="postgres" \ + -p 5432:5432 \ + $(PG_CONTAINER_IMAGE) + @sleep 1 + @$(MAKE) -f $(THIS_FILE) migrate +endif + +start: build postgres + @echo "==> Starting blockscout" + @docker run --rm \ + $(BLOCKSCOUT_CONTAINNER_PARAMS) \ + -p 4000:4000 \ + $(DOCKER_IMAGE) /bin/sh -c "mix phx.server" + +run: start + +.PHONY: build \ + migrate \ + start \ + postgres \ + run From 99b70a1b65ac654d152289afb082b8e89f399fbd Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Thu, 25 Oct 2018 16:24:16 +0300 Subject: [PATCH 08/14] Revert dev settings --- apps/explorer/config/dev.exs | 4 ++-- apps/indexer/config/dev.exs | 2 +- docker-compose.yml | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 docker-compose.yml diff --git a/apps/explorer/config/dev.exs b/apps/explorer/config/dev.exs index 50b0f88f78..d6363c383c 100644 --- a/apps/explorer/config/dev.exs +++ b/apps/explorer/config/dev.exs @@ -4,7 +4,7 @@ use Mix.Config config :explorer, Explorer.Repo, adapter: Ecto.Adapters.Postgres, database: "explorer_dev", - hostname: System.get_env("POSTGRES_URL") || "localhost", + hostname: "localhost", pool_size: 20, pool_timeout: 60_000, timeout: 80_000 @@ -17,7 +17,7 @@ import_config "dev.secret.exs" variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "ganache" + "parity" else System.get_env("ETHEREUM_JSONRPC_VARIANT") |> String.split(".") diff --git a/apps/indexer/config/dev.exs b/apps/indexer/config/dev.exs index 337e2f9b97..2f445c38dc 100644 --- a/apps/indexer/config/dev.exs +++ b/apps/indexer/config/dev.exs @@ -11,7 +11,7 @@ config :logger, :indexer_token_balances, variant = if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do - "ganache" + "parity" else System.get_env("ETHEREUM_JSONRPC_VARIANT") |> String.split(".") diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 9c115cb0f8..0000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3' -services: - blockscout: - build: . - ports: - - "4000:4000" - environment: - ETHEREUM_JSONRPC_HTTP_URL: "http://host.docker.internal:2000" - ETHEREUM_JSONRPC_WEB_SOCKET_URL: "ws://host.docker.internal:2000" - From b63c22d6f9bf5fe527257c8b99f26e08d5c35cfa Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Fri, 26 Oct 2018 14:12:32 +0300 Subject: [PATCH 09/14] Reworked docker. minified image from 344 -> 15 Mb --- .dockerignore | 4 ++++ Dockerfile => docker/Dockerfile | 4 ---- Makefile => docker/Makefile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename Dockerfile => docker/Dockerfile (76%) rename Makefile => docker/Makefile (97%) diff --git a/.dockerignore b/.dockerignore index f2c7590ef7..b52edd4f47 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,7 @@ deps apps/block_scout_web/assets/node_modules apps/explorer/node_modules test +.git +.circleci +logs +apps/*/test diff --git a/Dockerfile b/docker/Dockerfile similarity index 76% rename from Dockerfile rename to docker/Dockerfile index 8325ad9170..9c1a4809e2 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -6,10 +6,6 @@ EXPOSE 4000 ENV PORT=4000 \ MIX_ENV="prod" \ - ETHEREUM_JSONRPC_VARIANT="ganache" \ - ETHEREUM_JSONRPC_HTTP_URL="http://host.docker.internal:7545" \ - ETHEREUM_JSONRPC_WEB_SOCKET_URL="ws://host.docker.internal:7545" \ - DATABASE_URL="postgresql://postgres:@host.docker.internal:5432/explorer?ssl=false" \ SECRET_KEY_BASE="RMgI4C1HSkxsEjdhtGMfwAHfyT6CKWXOgzCboJflfSm4jeAlic52io05KB6mqzc5" # Cache elixir deps diff --git a/Makefile b/docker/Makefile similarity index 97% rename from Makefile rename to docker/Makefile index 3de6a1460a..56906fcc37 100644 --- a/Makefile +++ b/docker/Makefile @@ -32,7 +32,7 @@ ifdef HAS_BLOCKSCOUT_IMAGE @echo "==> Image exist. Using $(DOCKER_IMAGE)" else @echo "==> No image found trying to build one..." - # @docker build -t $(DOCKER_IMAGE) . + @docker build -f ./Dockerfile -t $(DOCKER_IMAGE) ../ endif migrate: build postgres From 3b66962db694576b1442babe1be6c756ecb188d8 Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Sat, 27 Oct 2018 16:14:42 +0300 Subject: [PATCH 10/14] Added README.md template --- docker/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000..949a926390 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,29 @@ +# BlockScout Docker integration + +For now this integration is not production ready. It made only for local usage only ! + +## How to use ? + +## Env variables + +BlockScout support 3 different JSON RPC Variants. +Vriant could be configured using `ETHEREUM_JSONRPC_VARIANT` environment variable. + +Example: +```bash +ETHEREUM_JSONRPC_VARIANT=ganache make start +``` + +Available options are: + + * `parity` - Parity JSON RPC (**Default one**) + * `geth` - Geth JSON RPC + * `ganache` - Ganache JSON RPC + + +| Variable | Description | Default value | +| -------- | ----------- | ------------- | +| `ETHEREUM_JSONRPC_VARIANT` | Variant of your JSON RPC service: `parity`, `geth` or `ganache` | `parity` | +| `ETHEREUM_JSONRPC_HTTP_URL` | HTTP JSON RPC URL Only for `geth` or `ganache` variant | `http://localhost:7545` | +| `ETHEREUM_JSONRPC_WEB_SOCKET_URL` | WS JSON RPC url **Only for `geth` or `ganache` variant** | `ws://localhost:7545` | + From c9cd84bca7ae61410268035306dac621d0c51d6e Mon Sep 17 00:00:00 2001 From: Konstantin Zolotarev Date: Mon, 29 Oct 2018 17:18:33 +0200 Subject: [PATCH 11/14] Updated docker integration --- docker/Makefile | 25 +++++++++++++++++++++-- docker/README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/docker/Makefile b/docker/Makefile index 56906fcc37..9e37f5e821 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -21,8 +21,29 @@ endif ifdef ETHEREUM_JSONRPC_HTTP_URL BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_HTTP_URL=$(ETHEREUM_JSONRPC_HTTP_URL)' endif -ifdef ETHEREUM_JSONRPC_WEB_SOCKET_URL - BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_WEB_SOCKET_URL=$(ETHEREUM_JSONRPC_WEB_SOCKET_URL)' +ifdef ETHEREUM_JSONRPC_WS_URL + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_WS_URL=$(ETHEREUM_JSONRPC_WS_URL)' +endif +ifdef ETHEREUM_JSONRPC_TRACE_URL + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'ETHEREUM_JSONRPC_TRACE_URL=$(ETHEREUM_JSONRPC_TRACE_URL)' +endif +ifdef COIN + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'COIN=$(COIN)' +endif +ifdef LOGO + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'LOGO=$(LOGO)' +endif +ifdef NETWORK + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'NETWORK=$(NETWORK)' +endif +ifdef SUBNETWORK + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'SUBNETWORK=$(SUBNETWORK)' +endif +ifdef NETWORK_ICON + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'NETWORK_ICON=$(NETWORK_ICON)' +endif +ifdef NETWORK_PATH + BLOCKSCOUT_CONTAINNER_PARAMS += -e 'NETWORK_PATH=$(NETWORK_PATH)' endif HAS_BLOCKSCOUT_IMAGE := $(shell docker images | grep ${DOCKER_IMAGE}) diff --git a/docker/README.md b/docker/README.md index 949a926390..17e142c27f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,6 +3,34 @@ For now this integration is not production ready. It made only for local usage only ! ## How to use ? +First of all blockscout requires `PostgreSQL` server for working. +It will be provided by starting script (new docker image will be created named `postgres`) + +**Starting command** +`make start` - will set everything up and start blockscout in container. +To connect it to your local environment you will have to configure it using [env variables](#env-variables) + +Exmaple connecting to local `ganache` instance running on port `2000` on Mac/Windows: +```bash +COIN=DAI \ +ETHEREUM_JSONRPC_VARIANT=ganache \ +ETHEREUM_JSONRPC_HTTP_URL=http://host.docker.internal:2000 \ +ETHEREUM_JSONRPC_WEB_SOCKET_URL=ws://host.docker.internal:2000 \ +make start +``` + +Blockscout will be available on `localhost:4000` + +**Note** +On mac/Windows Docker provides with a special URL `host.docker.internal` that will be available into container and routed to your local machine. +On Linux docker is starting using `--network=host` and all services should be available on `localhost` + +### Migrations + +By default `Makefile` will do migrations for you on `PostgreSQL` creation. +But you could run migrations manualy using `make migrate` command. + +**WARNING** Migrations will clean up your local database ! ## Env variables @@ -24,6 +52,26 @@ Available options are: | Variable | Description | Default value | | -------- | ----------- | ------------- | | `ETHEREUM_JSONRPC_VARIANT` | Variant of your JSON RPC service: `parity`, `geth` or `ganache` | `parity` | -| `ETHEREUM_JSONRPC_HTTP_URL` | HTTP JSON RPC URL Only for `geth` or `ganache` variant | `http://localhost:7545` | -| `ETHEREUM_JSONRPC_WEB_SOCKET_URL` | WS JSON RPC url **Only for `geth` or `ganache` variant** | `ws://localhost:7545` | +| `ETHEREUM_JSONRPC_HTTP_URL` | HTTP JSON RPC URL Only for `geth` or `ganache` variant | Different per JSONRPC variant | +| `ETHEREUM_JSONRPC_WS_URL` | WS JSON RPC url | Different per JSONRPC variant | +| `ETHEREUM_JSONRPC_TRACE_URL` | Trace URL **Only for `parity` variant** | `https://sokol-trace.poa.network` | +| `COIN` | Default Coin | `POA` | +| `LOGO` | Coin logo | Empty | +| `NETWORK` | Network | Empty | +| `SUBNETWORK` | Subnetwork | Empty | +| `NETWORK_ICON` | Network icon | Empty | +| `NETWORK_PATH` | Network path | `/` | + + +`ETHEREUM_JSONRPC_HTTP_URL` default values: + + * For `parity` - `https://sokol.poa.network` + * For `geth` - `https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY` + * For `ganache` - `http://localhost:7545` + +`ETHEREUM_JSONRPC_WS_URL` default values: + + * For `parity` - `wss://sokol-ws.poa.network/ws` + * For `geth` - `wss://mainnet.infura.io/8lTvJTKmHPCHazkneJsY/ws` + * For `ganache` - `ws://localhost:7545` From acf74e6267294960ca6510f4ed9b636b1dba9296 Mon Sep 17 00:00:00 2001 From: Gustavo Santos Ferreira Date: Mon, 29 Oct 2018 15:58:24 -0300 Subject: [PATCH 12/14] migration to change type of field decimals --- ...ns_table_decimals_from_bigint_to_numeric.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 apps/explorer/priv/repo/migrations/20181029174420_update_tokens_table_decimals_from_bigint_to_numeric.exs diff --git a/apps/explorer/priv/repo/migrations/20181029174420_update_tokens_table_decimals_from_bigint_to_numeric.exs b/apps/explorer/priv/repo/migrations/20181029174420_update_tokens_table_decimals_from_bigint_to_numeric.exs new file mode 100644 index 0000000000..3f4f4df9d6 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20181029174420_update_tokens_table_decimals_from_bigint_to_numeric.exs @@ -0,0 +1,17 @@ +defmodule Explorer.Repo.Migrations.UpdateTokensTableDecimalsFromBigintToNumeric do + use Ecto.Migration + + def up do + alter table("tokens") do + modify(:decimals, :decimal) + end + end + + def down do + execute(""" + ALTER TABLE tokens + ALTER COLUMN decimals TYPE bigint + USING CASE WHEN decimals > 9223372036854775807 THEN NULL ELSE decimals END; + """) + end +end From 965bbb5e75d1a5398851ea5f495a310d2303c452 Mon Sep 17 00:00:00 2001 From: Gustavo Santos Ferreira Date: Mon, 29 Oct 2018 15:57:57 -0300 Subject: [PATCH 13/14] replace decimals from int to decimal --- .../block_scout_web/views/currency_helpers.ex | 18 +++++++++--------- .../block_scout_web/views/tokens/helpers.ex | 2 +- .../views/tokens/holder_view.ex | 2 +- .../views/currency_helpers_test.exs | 12 ++++++------ .../views/tokens/helpers_test.exs | 2 +- .../views/tokens/holder_view_test.exs | 2 +- apps/explorer/lib/explorer/chain/token.ex | 2 +- .../test/explorer/chain/address/token_test.exs | 2 +- apps/explorer/test/explorer/chain_test.exs | 2 +- .../test/indexer/token/fetcher_test.exs | 4 +++- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/currency_helpers.ex b/apps/block_scout_web/lib/block_scout_web/views/currency_helpers.ex index 9d50e68ce4..40ba9bb67a 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/currency_helpers.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/currency_helpers.ex @@ -25,24 +25,24 @@ defmodule BlockScoutWeb.CurrencyHelpers do ## Examples - iex> format_according_to_decimals(Decimal.new(20500000), 5) + iex> format_according_to_decimals(Decimal.new(20500000), Decimal.new(5)) "205" - iex> format_according_to_decimals(Decimal.new(20500000), 7) + iex> format_according_to_decimals(Decimal.new(20500000), Decimal.new(7)) "2.05" - iex> format_according_to_decimals(Decimal.new(205000), 12) + iex> format_according_to_decimals(Decimal.new(205000), Decimal.new(12)) "0.000000205" - iex> format_according_to_decimals(Decimal.new(205000), 2) + iex> format_according_to_decimals(Decimal.new(205000), Decimal.new(2)) "2,050" - iex> format_according_to_decimals(205000, 2) + iex> format_according_to_decimals(205000, Decimal.new(2)) "2,050" """ - @spec format_according_to_decimals(non_neg_integer(), non_neg_integer()) :: String.t() + @spec format_according_to_decimals(non_neg_integer(), nil) :: String.t() def format_according_to_decimals(value, nil) do - format_according_to_decimals(value, 0) + format_according_to_decimals(value, Decimal.new(0)) end def format_according_to_decimals(value, decimals) when is_integer(value) do @@ -51,10 +51,10 @@ defmodule BlockScoutWeb.CurrencyHelpers do |> format_according_to_decimals(decimals) end - @spec format_according_to_decimals(Decimal.t(), non_neg_integer()) :: String.t() + @spec format_according_to_decimals(Decimal.t(), Decimal.t()) :: String.t() def format_according_to_decimals(%Decimal{sign: sign, coef: coef, exp: exp}, decimals) do sign - |> Decimal.new(coef, exp - decimals) + |> Decimal.new(coef, exp - Decimal.to_integer(decimals)) |> Decimal.reduce() |> thousands_separator() end diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex index 7c9413ec77..1ad70179bf 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex @@ -25,7 +25,7 @@ defmodule BlockScoutWeb.Tokens.Helpers do end defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: nil}, amount, _token_id) do - CurrencyHelpers.format_according_to_decimals(amount, 0) + CurrencyHelpers.format_according_to_decimals(amount, Decimal.new(0)) end defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: decimals}, amount, _token_id) do diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex index c6e284ec39..81beb2a149 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex @@ -49,7 +49,7 @@ defmodule BlockScoutWeb.Tokens.HolderView do ## Examples - iex> token = build(:token, type: "ERC-20", decimals: 2) + iex> token = build(:token, type: "ERC-20", decimals: Decimal.new(2)) iex> BlockScoutWeb.Tokens.HolderView.format_token_balance_value(100000, token) "1,000" diff --git a/apps/block_scout_web/test/block_scout_web/views/currency_helpers_test.exs b/apps/block_scout_web/test/block_scout_web/views/currency_helpers_test.exs index fc6e8496de..ac40b35873 100644 --- a/apps/block_scout_web/test/block_scout_web/views/currency_helpers_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/currency_helpers_test.exs @@ -8,42 +8,42 @@ defmodule BlockScoutWeb.CurrencyHelpersTest do describe "format_according_to_decimals/1" do test "formats the amount as value considering the given decimals" do amount = Decimal.new(205_000_000_000_000) - decimals = 12 + decimals = Decimal.new(12) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "205" end test "considers the decimal places according to the given decimals" do amount = Decimal.new(205_000) - decimals = 12 + decimals = Decimal.new(12) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "0.000000205" end test "does not consider right zeros in decimal places" do amount = Decimal.new(90_000_000) - decimals = 6 + decimals = Decimal.new(6) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "90" end test "returns the full number when there is no right zeros in decimal places" do amount = Decimal.new(9_324_876) - decimals = 6 + decimals = Decimal.new(6) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "9.324876" end test "formats the value considering thousands separators" do amount = Decimal.new(1_000_450) - decimals = 2 + decimals = Decimal.new(2) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "10,004.5" end test "supports value as integer" do amount = 1_000_450 - decimals = 2 + decimals = Decimal.new(2) assert CurrencyHelpers.format_according_to_decimals(amount, decimals) == "10,004.5" end diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/helpers_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/helpers_test.exs index dc815eeca3..2cbfd2c0a5 100644 --- a/apps/block_scout_web/test/block_scout_web/views/tokens/helpers_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/tokens/helpers_test.exs @@ -12,7 +12,7 @@ defmodule BlockScoutWeb.Tokens.HelpersTest do end test "returns the formatted amount according to token decimals with ERC-20 token" do - token = build(:token, type: "ERC-20", decimals: 6) + token = build(:token, type: "ERC-20", decimals: Decimal.new(6)) token_transfer = build(:token_transfer, token: token, amount: Decimal.new(1_000_000)) assert Helpers.token_transfer_amount(token_transfer) == "1" diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs index 2ccea92e4e..9541a11eab 100644 --- a/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs @@ -44,7 +44,7 @@ defmodule BlockScoutWeb.Tokens.HolderViewTest do describe "format_token_balance_value/1" do test "formats according to token decimals when it's a ERC-20" do - token = build(:token, type: "ERC-20", decimals: 2) + token = build(:token, type: "ERC-20", decimals: Decimal.new(2)) token_balance = build(:token_balance, value: 2_000_000) assert HolderView.format_token_balance_value(token_balance.value, token) == "20,000" diff --git a/apps/explorer/lib/explorer/chain/token.ex b/apps/explorer/lib/explorer/chain/token.ex index c9de6c4a34..81a4c96ba9 100644 --- a/apps/explorer/lib/explorer/chain/token.ex +++ b/apps/explorer/lib/explorer/chain/token.ex @@ -50,7 +50,7 @@ defmodule Explorer.Chain.Token do field(:name, :string) field(:symbol, :string) field(:total_supply, :decimal) - field(:decimals, :integer) + field(:decimals, :decimal) field(:type, :string) field(:cataloged, :boolean) diff --git a/apps/explorer/test/explorer/chain/address/token_test.exs b/apps/explorer/test/explorer/chain/address/token_test.exs index 0b39873501..d4f307ace2 100644 --- a/apps/explorer/test/explorer/chain/address/token_test.exs +++ b/apps/explorer/test/explorer/chain/address/token_test.exs @@ -48,7 +48,7 @@ defmodule Explorer.Chain.Address.TokenTest do name: "token-c", symbol: "TC", balance: Decimal.new(1000), - decimals: 0, + decimals: Decimal.new(0), type: "ERC-721", transfers_count: 2 } diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 2f4e7c4854..414a54e217 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -2795,7 +2795,7 @@ defmodule Explorer.ChainTest do name: "Hodl Token", symbol: "HT", total_supply: 10, - decimals: 1, + decimals: Decimal.new(1), cataloged: true } diff --git a/apps/indexer/test/indexer/token/fetcher_test.exs b/apps/indexer/test/indexer/token/fetcher_test.exs index dd06562e96..c74342551b 100644 --- a/apps/indexer/test/indexer/token/fetcher_test.exs +++ b/apps/indexer/test/indexer/token/fetcher_test.exs @@ -64,12 +64,14 @@ defmodule Indexer.Token.FetcherTest do expected_supply = Decimal.new(1_000_000_000_000_000_000) + decimals_expected = Decimal.new(18) + assert {:ok, %Token{ name: "Bancor", symbol: "BNT", total_supply: ^expected_supply, - decimals: 18, + decimals: ^decimals_expected, cataloged: true }} = Chain.token_from_address_hash(contract_address_hash) end From cca2e59bd083dca34c4f2a093097bcc706f16d34 Mon Sep 17 00:00:00 2001 From: Ryan Arthur Date: Tue, 30 Oct 2018 13:14:24 -0400 Subject: [PATCH 14/14] Color code internal transactions --- .../assets/css/_typography.scss | 18 ++++++++++++++++-- .../internal_transaction/_tile.html.eex | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/css/_typography.scss b/apps/block_scout_web/assets/css/_typography.scss index 2c901ce69a..3711f781f2 100644 --- a/apps/block_scout_web/assets/css/_typography.scss +++ b/apps/block_scout_web/assets/css/_typography.scss @@ -99,10 +99,24 @@ label, textarea.form-control { } } -[data-transaction-status="Success"] { +[data-transaction-status="Success"], +[data-internal-transaction-type="Reward"] { color: $success; } -[data-transaction-status^="Error"] { +[data-internal-transaction-type="Call"] { + color: $info; +} + +[data-internal-transaction-type="Delegate Call"] { + color: $purple; +} + +[data-internal-transaction-type="Create"] { + color: $pink; +} + +[data-transaction-status^="Error"], +[data-internal-transaction-type="Suicide"] { color: $danger; } diff --git a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex index b2c6940561..9125caf9bf 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex @@ -2,7 +2,7 @@
<%= gettext("Internal Transaction") %> - (<%= type(@internal_transaction) %>) + <%= type(@internal_transaction) %>
<%= render BlockScoutWeb.TransactionView, "_link.html", transaction_hash: @internal_transaction.transaction_hash %>