From 33175fbbe674015b28c2b4c1ebb62ac85bfdef6c Mon Sep 17 00:00:00 2001 From: thepiwo Date: Mon, 13 Nov 2017 20:15:27 +0200 Subject: [PATCH 1/3] [GH-#119] start node with port specified in environment --- apps/aehttpserver/config/dev.exs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/aehttpserver/config/dev.exs b/apps/aehttpserver/config/dev.exs index 3d2fdb9d..92d9addd 100644 --- a/apps/aehttpserver/config/dev.exs +++ b/apps/aehttpserver/config/dev.exs @@ -19,8 +19,14 @@ use Mix.Config # If desired, both `http:` and `https:` keys can be # configured to run both http and https servers on # different ports. + +port = case System.get_env("PORT") do + nil -> 4000 + env -> env +end + config :aehttpserver, Aehttpserver.Endpoint, - http: [port: 4000], + http: [port: port], debug_errors: true, code_reloader: true, check_origin: false, From 649ff25731f0c7384f00359582585f4049a2c9e1 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Thu, 16 Nov 2017 11:43:24 +0100 Subject: [PATCH 2/3] Made pesistance table path configurable --- apps/aecore/config/dev.exs | 8 +++++++- apps/aecore/config/prod.exs | 9 +++++++++ apps/aecore/config/test.exs | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/aecore/config/dev.exs b/apps/aecore/config/dev.exs index ede8d3bb..a71511a5 100644 --- a/apps/aecore/config/dev.exs +++ b/apps/aecore/config/dev.exs @@ -27,8 +27,14 @@ use Mix.Config # Configuration from the imported file will override the ones defined # here (which is why it is important to import them last). # + +persistence_path = case System.get_env("PERSISTENCE_PATH") do + nil -> "apps/aecore/priv/persistence_table" + env -> env +end + config :aecore, :persistence, - table: Path.absname("apps/aecore/priv/persistence_table") + table: Path.absname(persistence_path) config :aecore, :pow, nif_path: Path.absname("apps/aecore/priv/aec_pow_cuckoo20_nif"), diff --git a/apps/aecore/config/prod.exs b/apps/aecore/config/prod.exs index 11dc49d2..ac279fe8 100644 --- a/apps/aecore/config/prod.exs +++ b/apps/aecore/config/prod.exs @@ -27,6 +27,15 @@ use Mix.Config # Configuration from the imported file will override the ones defined # here (which is why it is important to import them last). # + +persistence_path = case System.get_env("PERSISTENCE_PATH") do + nil -> "apps/aecore/priv/persistence_table" + env -> env +end + +config :aecore, :persistence, + table: Path.absname(persistence_path) + config :aecore, :pow, nif_path: Path.absname("apps/aecore/priv/aec_pow_cuckoo26_nif"), genesis_header: %{ diff --git a/apps/aecore/config/test.exs b/apps/aecore/config/test.exs index 79603cc3..008caf91 100644 --- a/apps/aecore/config/test.exs +++ b/apps/aecore/config/test.exs @@ -28,6 +28,14 @@ use Mix.Config # here (which is why it is important to import them last). # +persistence_path = case System.get_env("PERSISTENCE_PATH") do + nil -> "apps/aecore/priv/persistence_table" + env -> env +end + +config :aecore, :persistence, + table: Path.absname(persistence_path) + config :aecore, :pow, nif_path: Path.absname("apps/aecore/priv/aec_pow_cuckoo20_nif"), genesis_header: %{ From 950943113c15842ff9256d348553a1a3d75df562 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Thu, 16 Nov 2017 11:52:53 +0100 Subject: [PATCH 3/3] Calculate path on runtime instead of buildtime --- apps/aecore/lib/aecore/persistence/worker.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/aecore/lib/aecore/persistence/worker.ex b/apps/aecore/lib/aecore/persistence/worker.ex index 6e529882..c6603f2e 100644 --- a/apps/aecore/lib/aecore/persistence/worker.ex +++ b/apps/aecore/lib/aecore/persistence/worker.ex @@ -2,8 +2,7 @@ defmodule Aecore.Persistence.Worker do @moduledoc """ Store/Restore latest blockchain and chainstate """ - - @persistence_table Application.get_env(:aecore, :persistence)[:table] + @blockchain_key :block_chain_state_key use GenServer @@ -49,7 +48,7 @@ defmodule Aecore.Persistence.Worker do ## Internal functions defp setup do - {:ok, table} = :dets.open_file(@persistence_table , [type: :set]) + {:ok, table} = :dets.open_file(persistance_table_path(), [type: :set]) %{table: table} end @@ -61,4 +60,7 @@ defmodule Aecore.Persistence.Worker do end end + defp persistance_table_path() do + Application.get_env(:aecore, :persistence)[:table] + end end