From e110ed5e63ef9d93908d9575ac4ac45098c50012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Thu, 2 Aug 2018 22:44:14 +0200 Subject: [PATCH] Refactor: Move DEFAULT_CHAIN from AVAILABLE_CHAINS.json to env variable --- docker/dev/conf/AVAILABLE_CHAINS.json | 2 -- docker/dev/conf/explorer.env | 2 ++ docker/production/conf/AVAILABLE_CHAINS.json | 2 -- docker/production/conf/explorer.env | 2 ++ docker/staging/conf/AVAILABLE_CHAINS.json | 2 -- docker/staging/conf/explorer.env | 2 ++ docker/test-postgres/conf/AVAILABLE_CHAINS.json | 2 -- docker/test-postgres/conf/explorer.env | 2 ++ explorer/domain/api_domain.py | 4 +--- explorer/env_config.py | 2 ++ explorer/resources/chain.py | 2 +- explorer/test_tools/test_prototypes.py | 2 -- 12 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docker/dev/conf/AVAILABLE_CHAINS.json b/docker/dev/conf/AVAILABLE_CHAINS.json index cb84c82..089b206 100644 --- a/docker/dev/conf/AVAILABLE_CHAINS.json +++ b/docker/dev/conf/AVAILABLE_CHAINS.json @@ -1,6 +1,4 @@ { - "DEFAULT_CHAIN": "elementsregtest", - "elementsregtest": { "proc": { "block_gen": [ diff --git a/docker/dev/conf/explorer.env b/docker/dev/conf/explorer.env index ebaeb61..ea35e03 100644 --- a/docker/dev/conf/explorer.env +++ b/docker/dev/conf/explorer.env @@ -17,6 +17,8 @@ DB_BACKEND_ADR=postgres:5432 ORM_MODEL=/build_docker/explorer/domain/db_domain.py ORM_SCHEMA=/build_docker/target/schema.json +DEFAULT_CHAIN=elementsregtest + REGTEST_ADR=bitcoin:18535 REGTEST_ZMQ=tcp://bitcoin:18537 REGTEST_RPCUSER=user18535 diff --git a/docker/production/conf/AVAILABLE_CHAINS.json b/docker/production/conf/AVAILABLE_CHAINS.json index 164d8b7..e30f7bb 100644 --- a/docker/production/conf/AVAILABLE_CHAINS.json +++ b/docker/production/conf/AVAILABLE_CHAINS.json @@ -1,6 +1,4 @@ { - "DEFAULT_CHAIN": "elementsregtest", - "elementsregtest": { "proc": { "block_gen": [ diff --git a/docker/production/conf/explorer.env b/docker/production/conf/explorer.env index 484896f..8f0434f 100644 --- a/docker/production/conf/explorer.env +++ b/docker/production/conf/explorer.env @@ -17,6 +17,8 @@ DB_BACKEND_ADR=postgres:5432 ORM_MODEL=/build_docker/explorer/domain/db_domain.py ORM_SCHEMA=/build_docker/target/schema.json +DEFAULT_CHAIN=elementsregtest + ELEMENTSREGTEST_ADR=elements:7041 ELEMENTSREGTEST_ZMQ=tcp://elements:7043 ELEMENTSREGTEST_RPCUSER=user7041 diff --git a/docker/staging/conf/AVAILABLE_CHAINS.json b/docker/staging/conf/AVAILABLE_CHAINS.json index 87c0f1d..4121907 100644 --- a/docker/staging/conf/AVAILABLE_CHAINS.json +++ b/docker/staging/conf/AVAILABLE_CHAINS.json @@ -1,6 +1,4 @@ { - "DEFAULT_CHAIN": "bitcoin", - "bitcoin": { "proc": { "greedy_cacher": [ diff --git a/docker/staging/conf/explorer.env b/docker/staging/conf/explorer.env index d82097a..37c0ae9 100644 --- a/docker/staging/conf/explorer.env +++ b/docker/staging/conf/explorer.env @@ -17,6 +17,8 @@ DB_BACKEND_ADR=postgres:5432 ORM_MODEL=/build_docker/explorer/domain/db_domain.py ORM_SCHEMA=/build_docker/target/schema.json +DEFAULT_CHAIN=bitcoin + BITCOIN_ADR=bitcoin:8532 BITCOIN_ZMQ=tcp://bitcoin:8534 BITCOIN_RPCUSER=user8532 diff --git a/docker/test-postgres/conf/AVAILABLE_CHAINS.json b/docker/test-postgres/conf/AVAILABLE_CHAINS.json index cb84c82..089b206 100644 --- a/docker/test-postgres/conf/AVAILABLE_CHAINS.json +++ b/docker/test-postgres/conf/AVAILABLE_CHAINS.json @@ -1,6 +1,4 @@ { - "DEFAULT_CHAIN": "elementsregtest", - "elementsregtest": { "proc": { "block_gen": [ diff --git a/docker/test-postgres/conf/explorer.env b/docker/test-postgres/conf/explorer.env index c074610..1c54180 100644 --- a/docker/test-postgres/conf/explorer.env +++ b/docker/test-postgres/conf/explorer.env @@ -17,6 +17,8 @@ DB_BACKEND_ADR=postgres:5432 ORM_MODEL=/build_docker/explorer/domain/db_domain.py ORM_SCHEMA=/build_docker/target/schema.json +DEFAULT_CHAIN=elementsregtest + REGTEST_ADR=bitcoin:18535 REGTEST_ZMQ=tcp://bitcoin:18537 REGTEST_RPCUSER=user18535 diff --git a/explorer/domain/api_domain.py b/explorer/domain/api_domain.py index d9331a8..accc4fa 100644 --- a/explorer/domain/api_domain.py +++ b/explorer/domain/api_domain.py @@ -19,13 +19,11 @@ from explorer.resources.rpccaller import RpcCallerResource def get_default_chain(**kwargs): - return env_config.AVAILABLE_CHAINS['DEFAULT_CHAIN'] + return env_config.DEFAULT_CHAIN def get_available_chains(**kwargs): available_chains = {} for k, v in env_config.AVAILABLE_CHAINS.iteritems(): - if k == 'DEFAULT_CHAIN': - continue available_chains[k] = v['properties'] return available_chains, 200 diff --git a/explorer/env_config.py b/explorer/env_config.py index 31d5056..3b4e975 100644 --- a/explorer/env_config.py +++ b/explorer/env_config.py @@ -6,6 +6,8 @@ from explorer.services.rpcdaemon import RpcCaller +DEFAULT_CHAIN = os.environ.get('DEFAULT_CHAIN') + file = open('/build_docker/docker/conf/AVAILABLE_CHAINS.json', 'r').read() AVAILABLE_CHAINS = json.loads(file) diff --git a/explorer/resources/chain.py b/explorer/resources/chain.py index 662b4d2..173f484 100644 --- a/explorer/resources/chain.py +++ b/explorer/resources/chain.py @@ -16,7 +16,7 @@ def update_chain(self, request_data): self.chain = request_data['chain'] del request_data['chain'] else: - self.chain = env_config.AVAILABLE_CHAINS['DEFAULT_CHAIN'] + self.chain = env_config.DEFAULT_CHAIN if not self.chain in env_config.AVAILABLE_CHAINS: raise UnknownChainError diff --git a/explorer/test_tools/test_prototypes.py b/explorer/test_tools/test_prototypes.py index 4e68617..a6e52eb 100644 --- a/explorer/test_tools/test_prototypes.py +++ b/explorer/test_tools/test_prototypes.py @@ -40,8 +40,6 @@ def do_101(self, chain): def run_tests(self): for chain, chain_properties in env_config.AVAILABLE_CHAINS.items(): - if chain == 'DEFAULT_CHAIN': - continue print('Running %s for chain %s' % (self.__class__.__name__, chain)) self.init_chrono() self.run_tests_for_chain(chain)