From 3cc5b5ea43f64dc3b3bffd4e42def0ef8b3bfb54 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 7 Sep 2017 13:53:44 +0900 Subject: [PATCH] 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. --- docs/ENVIRONMENT.rst | 10 ++++----- lib/coins.py | 51 ++++++++++++++++++++++---------------------- server/env.py | 2 +- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst index cd7872c..c489b9f 100644 --- a/docs/ENVIRONMENT.rst +++ b/docs/ENVIRONMENT.rst @@ -13,6 +13,11 @@ Required These environment variables are always required: +* **COIN** + + Must be a *NAME* from one of the **Coin** classes in + `lib/coins.py`_. + * **DB_DIRECTORY** The path to the database directory. Relative paths should be @@ -53,11 +58,6 @@ Miscellaneous These environment variables are optional: -* **COIN** - - Must be a *NAME* from one of the **Coin** classes in - `lib/coins.py`_. Defaults to `Bitcoin`. - * **NET** Must be a *NET* from one of the **Coin** classes in `lib/coins.py`_. diff --git a/lib/coins.py b/lib/coins.py index 94344bb..4f9be0e 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -317,8 +317,7 @@ class AuxPowMixin(object): return deserializer.read_header(height, cls.BASIC_HEADER_SIZE) -class Bitcoin(Coin): - NAME = "Bitcoin" +class BitcoinMixin(object): SHORTNAME = "BTC" NET = "mainnet" XPUB_VERBYTES = bytes.fromhex("0488b21e") @@ -332,6 +331,11 @@ class Bitcoin(Coin): TX_COUNT_HEIGHT = 464000 TX_PER_BLOCK = 1800 RPC_PORT = 8332 + + +class BitcoinCash(BitcoinMixin, Coin): + NAME = "BitcoinCash" + SHORTNAME = "BCC" PEERS = [ 'electroncash.bitcoinplug.com s t', 'electrum-abc.criptolayer.net s50012', @@ -344,10 +348,9 @@ class Bitcoin(Coin): ] -class BitcoinSegwit(Bitcoin): - NET = "bitcoin-segwit" +class BitcoinSegwit(BitcoinMixin, Coin): + NAME = "BitcoinSegwit" DESERIALIZER = DeserializerSegWit - PEERS = [ 'btc.smsys.me s995', 'electrum.be s t', @@ -365,7 +368,8 @@ class BitcoinSegwit(Bitcoin): 'ELEX01.blackpole.online s t', ] -class BitcoinTestnet(Bitcoin): + +class BitcoinTestnetMixin(object): SHORTNAME = "XTN" NET = "testnet" XPUB_VERBYTES = bytes.fromhex("043587cf") @@ -381,6 +385,11 @@ class BitcoinTestnet(Bitcoin): TX_PER_BLOCK = 21 RPC_PORT = 18332 PEER_DEFAULT_PORTS = {'t': '51001', 's': '51002'} + + +class BitcoinCashTestnet(BitcoinTestnetMixin, Coin): + '''Bitcoin Testnet for Bitcoin Cash daemons.''' + NAME = "BitcoinCash" PEERS = [ 'electrum.akinbo.org 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" GENESIS_HASH = ('0f9188f13cb7b2c71f2a335e3a4fc328' 'bf5beb436012afca590b1a11466e2206') PEERS= [] TX_COUNT = 1 TX_COUNT_HEIGHT = 1 - DESERIALIZER = DeserializerSegWit -class BitcoinTestnetSegWit(BitcoinTestnet): - '''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): +class BitcoinNolnet(BitcoinCash): '''Bitcoin Unlimited nolimit testnet.''' - NET = "nolnet" GENESIS_HASH = ('0000000057e31bd2066c939a63b7b862' '3bd0f10d8c001304bdfc1a7902ae6d35') + PEERS = [] REORG_LIMIT = 8000 TX_COUNT = 583589 TX_COUNT_HEIGHT = 8617 TX_PER_BLOCK = 50 - IRC_PREFIX = "EN_" RPC_PORT = 28332 PEER_DEFAULT_PORTS = {'t': '52001', 's': '52002'} - PEERS = [ - '14.3.140.101 s t', - ] class Litecoin(Coin): diff --git a/server/env.py b/server/env.py index cd2d0e9..f5a6c3d 100644 --- a/server/env.py +++ b/server/env.py @@ -31,7 +31,7 @@ class Env(lib_util.LoggedClass): self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) self.db_dir = self.required('DB_DIRECTORY') self.daemon_url = self.required('DAEMON_URL') - coin_name = self.default('COIN', 'Bitcoin') + coin_name = self.required('COIN') network = self.default('NET', 'mainnet') self.coin = Coin.lookup_coin_class(coin_name, network) self.cache_MB = self.integer('CACHE_MB', 1200)