Browse Source

Env accepts custom Coin class (#517)

* + support for passing an actual coin class to Env()

* unit test for Env() accept coin class

* doc string explaining optional Coin argument to Env and assert to make sure a coin is a Coin
patch-2
Lex Berezhny 7 years ago
committed by Neil
parent
commit
f8ebcf35b4
  1. 17
      electrumx/server/env.py
  2. 4
      tests/server/test_env.py

17
electrumx/server/env.py

@ -22,20 +22,27 @@ NetIdentity = namedtuple('NetIdentity', 'host tcp_port ssl_port nick_suffix')
class Env(EnvBase):
'''Wraps environment configuration.'''
'''Wraps environment configuration. Optionally, accepts a Coin class
as first argument to have ElectrumX serve custom coins not part of
the standard distribution.
'''
# Peer discovery
PD_OFF, PD_SELF, PD_ON = range(3)
def __init__(self):
def __init__(self, coin=None):
super().__init__()
self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK'])
self.db_dir = self.required('DB_DIRECTORY')
self.db_engine = self.default('DB_ENGINE', 'leveldb')
self.daemon_url = self.required('DAEMON_URL')
coin_name = self.required('COIN').strip()
network = self.default('NET', 'mainnet').strip()
self.coin = Coin.lookup_coin_class(coin_name, network)
if coin is not None:
assert issubclass(coin, Coin)
self.coin = coin
else:
coin_name = self.required('COIN').strip()
network = self.default('NET', 'mainnet').strip()
self.coin = Coin.lookup_coin_class(coin_name, network)
self.cache_MB = self.integer('CACHE_MB', 1200)
self.host = self.default('HOST', 'localhost')
self.reorg_limit = self.integer('REORG_LIMIT', self.coin.REORG_LIMIT)

4
tests/server/test_env.py

@ -351,3 +351,7 @@ def test_ban_versions():
assert e.drop_client == re.compile(ban_re)
assert e.drop_client.match("1.2.3_buggy_client")
assert e.drop_client.match("1.3.0_good_client") is None
def test_coin_class_provided():
e = Env(lib_coins.BitcoinCash)
assert e.coin == lib_coins.BitcoinCash
Loading…
Cancel
Save