Browse Source

Make COIN env variable mandatory.

- make a clean split between the  Cash and Segwit flavours of bitcoin
  by giving them their own COIN names.  They can then both have a NET
  of mainnet.
- The previous Bitcoin COIN names no longer exist, and the env var is
  now mandatory, so everyone will need to set COIN and NET appropriately
  for their flavour of bitcoin and mainnet or testnet.
master
Neil Booth 8 years ago
parent
commit
3cc5b5ea43
  1. 10
      docs/ENVIRONMENT.rst
  2. 51
      lib/coins.py
  3. 2
      server/env.py

10
docs/ENVIRONMENT.rst

@ -13,6 +13,11 @@ Required
These environment variables are always required: These environment variables are always required:
* **COIN**
Must be a *NAME* from one of the **Coin** classes in
`lib/coins.py`_.
* **DB_DIRECTORY** * **DB_DIRECTORY**
The path to the database directory. Relative paths should be The path to the database directory. Relative paths should be
@ -53,11 +58,6 @@ Miscellaneous
These environment variables are optional: These environment variables are optional:
* **COIN**
Must be a *NAME* from one of the **Coin** classes in
`lib/coins.py`_. Defaults to `Bitcoin`.
* **NET** * **NET**
Must be a *NET* from one of the **Coin** classes in `lib/coins.py`_. Must be a *NET* from one of the **Coin** classes in `lib/coins.py`_.

51
lib/coins.py

@ -317,8 +317,7 @@ class AuxPowMixin(object):
return deserializer.read_header(height, cls.BASIC_HEADER_SIZE) return deserializer.read_header(height, cls.BASIC_HEADER_SIZE)
class Bitcoin(Coin): class BitcoinMixin(object):
NAME = "Bitcoin"
SHORTNAME = "BTC" SHORTNAME = "BTC"
NET = "mainnet" NET = "mainnet"
XPUB_VERBYTES = bytes.fromhex("0488b21e") XPUB_VERBYTES = bytes.fromhex("0488b21e")
@ -332,6 +331,11 @@ class Bitcoin(Coin):
TX_COUNT_HEIGHT = 464000 TX_COUNT_HEIGHT = 464000
TX_PER_BLOCK = 1800 TX_PER_BLOCK = 1800
RPC_PORT = 8332 RPC_PORT = 8332
class BitcoinCash(BitcoinMixin, Coin):
NAME = "BitcoinCash"
SHORTNAME = "BCC"
PEERS = [ PEERS = [
'electroncash.bitcoinplug.com s t', 'electroncash.bitcoinplug.com s t',
'electrum-abc.criptolayer.net s50012', 'electrum-abc.criptolayer.net s50012',
@ -344,10 +348,9 @@ class Bitcoin(Coin):
] ]
class BitcoinSegwit(Bitcoin): class BitcoinSegwit(BitcoinMixin, Coin):
NET = "bitcoin-segwit" NAME = "BitcoinSegwit"
DESERIALIZER = DeserializerSegWit DESERIALIZER = DeserializerSegWit
PEERS = [ PEERS = [
'btc.smsys.me s995', 'btc.smsys.me s995',
'electrum.be s t', 'electrum.be s t',
@ -365,7 +368,8 @@ class BitcoinSegwit(Bitcoin):
'ELEX01.blackpole.online s t', 'ELEX01.blackpole.online s t',
] ]
class BitcoinTestnet(Bitcoin):
class BitcoinTestnetMixin(object):
SHORTNAME = "XTN" SHORTNAME = "XTN"
NET = "testnet" NET = "testnet"
XPUB_VERBYTES = bytes.fromhex("043587cf") XPUB_VERBYTES = bytes.fromhex("043587cf")
@ -381,6 +385,11 @@ class BitcoinTestnet(Bitcoin):
TX_PER_BLOCK = 21 TX_PER_BLOCK = 21
RPC_PORT = 18332 RPC_PORT = 18332
PEER_DEFAULT_PORTS = {'t': '51001', 's': '51002'} PEER_DEFAULT_PORTS = {'t': '51001', 's': '51002'}
class BitcoinCashTestnet(BitcoinTestnetMixin, Coin):
'''Bitcoin Testnet for Bitcoin Cash daemons.'''
NAME = "BitcoinCash"
PEERS = [ PEERS = [
'electrum.akinbo.org s t', 'electrum.akinbo.org s t',
'he36kyperp3kbuxu.onion s t', 'he36kyperp3kbuxu.onion s t',
@ -391,44 +400,34 @@ class BitcoinTestnet(Bitcoin):
] ]
class BitcoinRegtest(BitcoinTestnet): class BitcoinSegwitTestnet(BitcoinTestnetMixin, Coin):
'''Bitcoin Testnet for Core bitcoind >= 0.13.1.'''
NAME = "BitcoinSegwit"
DESERIALIZER = DeserializerSegWit
class BitcoinSegwitRegtest(BitcoinSegwitTestnet):
NAME = "BitcoinSegwit"
NET = "regtest" NET = "regtest"
GENESIS_HASH = ('0f9188f13cb7b2c71f2a335e3a4fc328' GENESIS_HASH = ('0f9188f13cb7b2c71f2a335e3a4fc328'
'bf5beb436012afca590b1a11466e2206') 'bf5beb436012afca590b1a11466e2206')
PEERS= [] PEERS= []
TX_COUNT = 1 TX_COUNT = 1
TX_COUNT_HEIGHT = 1 TX_COUNT_HEIGHT = 1
DESERIALIZER = DeserializerSegWit
class BitcoinTestnetSegWit(BitcoinTestnet): class BitcoinNolnet(BitcoinCash):
'''Bitcoin Testnet for Core bitcoind >= 0.13.1.
Unfortunately 0.13.1 broke backwards compatibility of the RPC
interface's TX serialization, SegWit transactions serialize
differently than with earlier versions. If you are using such a
bitcoind on testnet, you must use this class as your "COIN".
'''
NET = "testnet-segwit"
DESERIALIZER = DeserializerSegWit
class BitcoinNolnet(Bitcoin):
'''Bitcoin Unlimited nolimit testnet.''' '''Bitcoin Unlimited nolimit testnet.'''
NET = "nolnet" NET = "nolnet"
GENESIS_HASH = ('0000000057e31bd2066c939a63b7b862' GENESIS_HASH = ('0000000057e31bd2066c939a63b7b862'
'3bd0f10d8c001304bdfc1a7902ae6d35') '3bd0f10d8c001304bdfc1a7902ae6d35')
PEERS = []
REORG_LIMIT = 8000 REORG_LIMIT = 8000
TX_COUNT = 583589 TX_COUNT = 583589
TX_COUNT_HEIGHT = 8617 TX_COUNT_HEIGHT = 8617
TX_PER_BLOCK = 50 TX_PER_BLOCK = 50
IRC_PREFIX = "EN_"
RPC_PORT = 28332 RPC_PORT = 28332
PEER_DEFAULT_PORTS = {'t': '52001', 's': '52002'} PEER_DEFAULT_PORTS = {'t': '52001', 's': '52002'}
PEERS = [
'14.3.140.101 s t',
]
class Litecoin(Coin): class Litecoin(Coin):

2
server/env.py

@ -31,7 +31,7 @@ class Env(lib_util.LoggedClass):
self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK'])
self.db_dir = self.required('DB_DIRECTORY') self.db_dir = self.required('DB_DIRECTORY')
self.daemon_url = self.required('DAEMON_URL') self.daemon_url = self.required('DAEMON_URL')
coin_name = self.default('COIN', 'Bitcoin') coin_name = self.required('COIN')
network = self.default('NET', 'mainnet') network = self.default('NET', 'mainnet')
self.coin = Coin.lookup_coin_class(coin_name, network) self.coin = Coin.lookup_coin_class(coin_name, network)
self.cache_MB = self.integer('CACHE_MB', 1200) self.cache_MB = self.integer('CACHE_MB', 1200)

Loading…
Cancel
Save