Skip to content

Commit

Permalink
Refactor: Move DEFAULT_CHAIN from AVAILABLE_CHAINS.json to env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimon committed Aug 2, 2018
1 parent 655fa28 commit e110ed5
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 14 deletions.
2 changes: 0 additions & 2 deletions docker/dev/conf/AVAILABLE_CHAINS.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"DEFAULT_CHAIN": "elementsregtest",

"elementsregtest": {
"proc": {
"block_gen": [
Expand Down
2 changes: 2 additions & 0 deletions docker/dev/conf/explorer.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker/production/conf/AVAILABLE_CHAINS.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"DEFAULT_CHAIN": "elementsregtest",

"elementsregtest": {
"proc": {
"block_gen": [
Expand Down
2 changes: 2 additions & 0 deletions docker/production/conf/explorer.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker/staging/conf/AVAILABLE_CHAINS.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"DEFAULT_CHAIN": "bitcoin",

"bitcoin": {
"proc": {
"greedy_cacher": [
Expand Down
2 changes: 2 additions & 0 deletions docker/staging/conf/explorer.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docker/test-postgres/conf/AVAILABLE_CHAINS.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"DEFAULT_CHAIN": "elementsregtest",

"elementsregtest": {
"proc": {
"block_gen": [
Expand Down
2 changes: 2 additions & 0 deletions docker/test-postgres/conf/explorer.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions explorer/domain/api_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions explorer/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion explorer/resources/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions explorer/test_tools/test_prototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e110ed5

Please sign in to comment.