Enforce pycodestyle in lib/
This commit is contained in:
parent
46adf543fc
commit
23e484b1d9
@ -28,7 +28,7 @@ install:
|
|||||||
# command to run tests
|
# command to run tests
|
||||||
script:
|
script:
|
||||||
- pytest --cov=server --cov=lib --cov=wallet
|
- pytest --cov=server --cov=lib --cov=wallet
|
||||||
- pycodestyle server/*.py
|
- pycodestyle server/*.py lib/*.py
|
||||||
# Dont report coverage from nightly
|
# Dont report coverage from nightly
|
||||||
after_success:
|
after_success:
|
||||||
- if [[ $(python3 -V 2>&1) == *"Python 3.6"* ]]; then
|
- if [[ $(python3 -V 2>&1) == *"Python 3.6"* ]]; then
|
||||||
|
|||||||
47
lib/coins.py
47
lib/coins.py
@ -60,7 +60,7 @@ class Coin(object):
|
|||||||
|
|
||||||
REORG_LIMIT = 200
|
REORG_LIMIT = 200
|
||||||
# Not sure if these are coin-specific
|
# Not sure if these are coin-specific
|
||||||
RPC_URL_REGEX = re.compile('.+@(\[[0-9a-fA-F:]+\]|[^:]+)(:[0-9]+)?')
|
RPC_URL_REGEX = re.compile('.+@(\\[[0-9a-fA-F:]+\\]|[^:]+)(:[0-9]+)?')
|
||||||
VALUE_PER_COIN = 100000000
|
VALUE_PER_COIN = 100000000
|
||||||
CHUNK_SIZE = 2016
|
CHUNK_SIZE = 2016
|
||||||
BASIC_HEADER_SIZE = 80
|
BASIC_HEADER_SIZE = 80
|
||||||
@ -260,8 +260,8 @@ class Coin(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def static_header_len(cls, height):
|
def static_header_len(cls, height):
|
||||||
'''Given a header height return its length.'''
|
'''Given a header height return its length.'''
|
||||||
return cls.static_header_offset(height + 1) \
|
return (cls.static_header_offset(height + 1)
|
||||||
- cls.static_header_offset(height)
|
- cls.static_header_offset(height))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def block_header(cls, block, height):
|
def block_header(cls, block, height):
|
||||||
@ -383,6 +383,7 @@ class BitcoinMixin(object):
|
|||||||
'4ff763ae46a2a6c172b3f1b60a8ce26f')
|
'4ff763ae46a2a6c172b3f1b60a8ce26f')
|
||||||
RPC_PORT = 8332
|
RPC_PORT = 8332
|
||||||
|
|
||||||
|
|
||||||
class HOdlcoin(Coin):
|
class HOdlcoin(Coin):
|
||||||
NAME = "HOdlcoin"
|
NAME = "HOdlcoin"
|
||||||
SHORTNAME = "HODLC"
|
SHORTNAME = "HODLC"
|
||||||
@ -573,7 +574,8 @@ class BitcoinCashTestnet(BitcoinTestnetMixin, Coin):
|
|||||||
PEERS = [
|
PEERS = [
|
||||||
'electrum-testnet-abc.criptolayer.net s50112',
|
'electrum-testnet-abc.criptolayer.net s50112',
|
||||||
'bchtestnet.arihanc.com t53001 s53002',
|
'bchtestnet.arihanc.com t53001 s53002',
|
||||||
'ciiattqkgzebpp6jofjbrkhvhwmgnsfoayljdcrve2p3qmkbv3duaoyd.onion t53001 s53002',
|
'ciiattqkgzebpp6jofjbrkhvhwmgnsfoayljdcrve2p3qmkbv3duaoyd.onion '
|
||||||
|
't53001 s53002',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -932,6 +934,7 @@ class Zcash(EquihashMixin, Coin):
|
|||||||
RPC_PORT = 8232
|
RPC_PORT = 8232
|
||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
|
|
||||||
|
|
||||||
class ZcashTestnet(Zcash):
|
class ZcashTestnet(Zcash):
|
||||||
SHORTNAME = "TAZ"
|
SHORTNAME = "TAZ"
|
||||||
NET = "testnet"
|
NET = "testnet"
|
||||||
@ -945,6 +948,7 @@ class ZcashTestnet(Zcash):
|
|||||||
TX_PER_BLOCK = 2
|
TX_PER_BLOCK = 2
|
||||||
RPC_PORT = 18232
|
RPC_PORT = 18232
|
||||||
|
|
||||||
|
|
||||||
class SnowGem(EquihashMixin, Coin):
|
class SnowGem(EquihashMixin, Coin):
|
||||||
NAME = "SnowGem"
|
NAME = "SnowGem"
|
||||||
SHORTNAME = "SNG"
|
SHORTNAME = "SNG"
|
||||||
@ -976,9 +980,11 @@ class SnowGem(EquihashMixin, Coin):
|
|||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'bits': bits,
|
'bits': bits,
|
||||||
'nonce': hash_to_str(header[108:140]),
|
'nonce': hash_to_str(header[108:140]),
|
||||||
'n_solution': base64.b64encode(lib_tx.Deserializer(header, start=140)._read_varbytes()).decode('utf8')
|
'n_solution': base64.b64encode(lib_tx.Deserializer(
|
||||||
|
header, start=140)._read_varbytes()).decode('utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BitcoinZ(EquihashMixin, Coin):
|
class BitcoinZ(EquihashMixin, Coin):
|
||||||
NAME = "BitcoinZ"
|
NAME = "BitcoinZ"
|
||||||
SHORTNAME = "BTCZ"
|
SHORTNAME = "BTCZ"
|
||||||
@ -995,6 +1001,7 @@ class BitcoinZ(EquihashMixin, Coin):
|
|||||||
RPC_PORT = 1979
|
RPC_PORT = 1979
|
||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
|
|
||||||
|
|
||||||
class Hush(EquihashMixin, Coin):
|
class Hush(EquihashMixin, Coin):
|
||||||
NAME = "Hush"
|
NAME = "Hush"
|
||||||
SHORTNAME = "HUSH"
|
SHORTNAME = "HUSH"
|
||||||
@ -1011,6 +1018,7 @@ class Hush(EquihashMixin, Coin):
|
|||||||
RPC_PORT = 8822
|
RPC_PORT = 8822
|
||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
|
|
||||||
|
|
||||||
class Zclassic(EquihashMixin, Coin):
|
class Zclassic(EquihashMixin, Coin):
|
||||||
NAME = "Zclassic"
|
NAME = "Zclassic"
|
||||||
SHORTNAME = "ZCL"
|
SHORTNAME = "ZCL"
|
||||||
@ -1027,6 +1035,7 @@ class Zclassic(EquihashMixin, Coin):
|
|||||||
RPC_PORT = 8023
|
RPC_PORT = 8023
|
||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
|
|
||||||
|
|
||||||
class Koto(Coin):
|
class Koto(Coin):
|
||||||
NAME = "Koto"
|
NAME = "Koto"
|
||||||
SHORTNAME = "KOTO"
|
SHORTNAME = "KOTO"
|
||||||
@ -1047,6 +1056,7 @@ class Koto(Coin):
|
|||||||
'electrum.kotocoin.info s t',
|
'electrum.kotocoin.info s t',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class KotoTestnet(Koto):
|
class KotoTestnet(Koto):
|
||||||
SHORTNAME = "TOKO"
|
SHORTNAME = "TOKO"
|
||||||
NET = "testnet"
|
NET = "testnet"
|
||||||
@ -1064,6 +1074,7 @@ class KotoTestnet(Koto):
|
|||||||
'testnet.kotocoin.info s t',
|
'testnet.kotocoin.info s t',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class Komodo(KomodoMixin, EquihashMixin, Coin):
|
class Komodo(KomodoMixin, EquihashMixin, Coin):
|
||||||
NAME = "Komodo"
|
NAME = "Komodo"
|
||||||
SHORTNAME = "KMD"
|
SHORTNAME = "KMD"
|
||||||
@ -1075,6 +1086,7 @@ class Komodo(KomodoMixin, EquihashMixin, Coin):
|
|||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
PEERS = []
|
PEERS = []
|
||||||
|
|
||||||
|
|
||||||
class Monaize(KomodoMixin, EquihashMixin, Coin):
|
class Monaize(KomodoMixin, EquihashMixin, Coin):
|
||||||
NAME = "Monaize"
|
NAME = "Monaize"
|
||||||
SHORTNAME = "MNZ"
|
SHORTNAME = "MNZ"
|
||||||
@ -1220,6 +1232,7 @@ class Monacoin(Coin):
|
|||||||
'electrum-mona.bitbank.cc s t',
|
'electrum-mona.bitbank.cc s t',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class MonacoinTestnet(Monacoin):
|
class MonacoinTestnet(Monacoin):
|
||||||
SHORTNAME = "XMN"
|
SHORTNAME = "XMN"
|
||||||
NET = "testnet"
|
NET = "testnet"
|
||||||
@ -1354,6 +1367,7 @@ class CanadaeCoin(AuxPowMixin, Coin):
|
|||||||
RPC_PORT = 34330
|
RPC_PORT = 34330
|
||||||
REORG_LIMIT = 1000
|
REORG_LIMIT = 1000
|
||||||
|
|
||||||
|
|
||||||
class Denarius(Coin):
|
class Denarius(Coin):
|
||||||
NAME = "Denarius"
|
NAME = "Denarius"
|
||||||
SHORTNAME = "DNR"
|
SHORTNAME = "DNR"
|
||||||
@ -1462,6 +1476,7 @@ class Feathercoin(Coin):
|
|||||||
'electrumx-ch-1.feathercoin.ch s t',
|
'electrumx-ch-1.feathercoin.ch s t',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class UFO(Coin):
|
class UFO(Coin):
|
||||||
NAME = "UniformFiscalObject"
|
NAME = "UniformFiscalObject"
|
||||||
SHORTNAME = "UFO"
|
SHORTNAME = "UFO"
|
||||||
@ -1483,6 +1498,7 @@ class UFO(Coin):
|
|||||||
'electrumx1.ufobject.com s t',
|
'electrumx1.ufobject.com s t',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class Newyorkcoin(AuxPowMixin, Coin):
|
class Newyorkcoin(AuxPowMixin, Coin):
|
||||||
NAME = "Newyorkcoin"
|
NAME = "Newyorkcoin"
|
||||||
SHORTNAME = "NYC"
|
SHORTNAME = "NYC"
|
||||||
@ -1498,6 +1514,7 @@ class Newyorkcoin(AuxPowMixin, Coin):
|
|||||||
TX_PER_BLOCK = 2
|
TX_PER_BLOCK = 2
|
||||||
REORG_LIMIT = 2000
|
REORG_LIMIT = 2000
|
||||||
|
|
||||||
|
|
||||||
class NewyorkcoinTestnet(Newyorkcoin):
|
class NewyorkcoinTestnet(Newyorkcoin):
|
||||||
SHORTNAME = "tNYC"
|
SHORTNAME = "tNYC"
|
||||||
NET = "testnet"
|
NET = "testnet"
|
||||||
@ -1512,6 +1529,7 @@ class NewyorkcoinTestnet(Newyorkcoin):
|
|||||||
TX_PER_BLOCK = 2
|
TX_PER_BLOCK = 2
|
||||||
REORG_LIMIT = 2000
|
REORG_LIMIT = 2000
|
||||||
|
|
||||||
|
|
||||||
class Bitcore(BitcoinMixin, Coin):
|
class Bitcore(BitcoinMixin, Coin):
|
||||||
NAME = "Bitcore"
|
NAME = "Bitcore"
|
||||||
SHORTNAME = "BTX"
|
SHORTNAME = "BTX"
|
||||||
@ -1540,6 +1558,7 @@ class GameCredits(Coin):
|
|||||||
RPC_PORT = 40001
|
RPC_PORT = 40001
|
||||||
REORG_LIMIT = 1000
|
REORG_LIMIT = 1000
|
||||||
|
|
||||||
|
|
||||||
class Machinecoin(Coin):
|
class Machinecoin(Coin):
|
||||||
NAME = "Machinecoin"
|
NAME = "Machinecoin"
|
||||||
SHORTNAME = "MAC"
|
SHORTNAME = "MAC"
|
||||||
@ -1558,6 +1577,7 @@ class Machinecoin(Coin):
|
|||||||
RPC_PORT = 40332
|
RPC_PORT = 40332
|
||||||
REORG_LIMIT = 800
|
REORG_LIMIT = 800
|
||||||
|
|
||||||
|
|
||||||
class BitcoinAtom(Coin):
|
class BitcoinAtom(Coin):
|
||||||
NAME = "BitcoinAtom"
|
NAME = "BitcoinAtom"
|
||||||
SHORTNAME = "BCA"
|
SHORTNAME = "BCA"
|
||||||
@ -1607,10 +1627,13 @@ class Decred(Coin):
|
|||||||
P2PKH_VERBYTE = bytes('Ds', 'utf-8')
|
P2PKH_VERBYTE = bytes('Ds', 'utf-8')
|
||||||
P2SH_VERBYTES = [bytes('Dc', 'utf-8')]
|
P2SH_VERBYTES = [bytes('Dc', 'utf-8')]
|
||||||
WIF_BYTE = bytes('Pm', 'utf-8')
|
WIF_BYTE = bytes('Pm', 'utf-8')
|
||||||
GENESIS_HASH = ('298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980')
|
GENESIS_HASH = ('298e5cc3d985bfe7f81dc135f360abe089ed'
|
||||||
|
'd4396b86d2de66b0cef42b21d980')
|
||||||
DESERIALIZER = lib_tx.DeserializerDecred
|
DESERIALIZER = lib_tx.DeserializerDecred
|
||||||
ENCODE_CHECK = partial(Base58.encode_check, hash_fn=lib_tx.DeserializerDecred.blake256)
|
ENCODE_CHECK = partial(Base58.encode_check,
|
||||||
DECODE_CHECK = partial(Base58.decode_check, hash_fn=lib_tx.DeserializerDecred.blake256)
|
hash_fn=lib_tx.DeserializerDecred.blake256)
|
||||||
|
DECODE_CHECK = partial(Base58.decode_check,
|
||||||
|
hash_fn=lib_tx.DeserializerDecred.blake256)
|
||||||
HEADER_HASH = lib_tx.DeserializerDecred.blake256
|
HEADER_HASH = lib_tx.DeserializerDecred.blake256
|
||||||
BASIC_HEADER_SIZE = 180
|
BASIC_HEADER_SIZE = 180
|
||||||
ALLOW_ADVANCING_ERRORS = True
|
ALLOW_ADVANCING_ERRORS = True
|
||||||
@ -1641,7 +1664,8 @@ class DecredTestnet(Decred):
|
|||||||
P2PKH_VERBYTE = bytes('Ts', 'utf-8')
|
P2PKH_VERBYTE = bytes('Ts', 'utf-8')
|
||||||
P2SH_VERBYTES = [bytes('Tc', 'utf-8')]
|
P2SH_VERBYTES = [bytes('Tc', 'utf-8')]
|
||||||
WIF_BYTE = bytes('Pt', 'utf-8')
|
WIF_BYTE = bytes('Pt', 'utf-8')
|
||||||
GENESIS_HASH = ('4261602a9d07d80ad47621a64ba6a07754902e496777edc4ff581946bd7bc29c')
|
GENESIS_HASH = ('4261602a9d07d80ad47621a64ba6a0'
|
||||||
|
'7754902e496777edc4ff581946bd7bc29c')
|
||||||
TX_COUNT = 3176305
|
TX_COUNT = 3176305
|
||||||
TX_COUNT_HEIGHT = 254198
|
TX_COUNT_HEIGHT = 254198
|
||||||
TX_PER_BLOCK = 1000
|
TX_PER_BLOCK = 1000
|
||||||
@ -1677,6 +1701,7 @@ class Axe(Dash):
|
|||||||
import x11_hash
|
import x11_hash
|
||||||
return x11_hash.getPoWHash(header)
|
return x11_hash.getPoWHash(header)
|
||||||
|
|
||||||
|
|
||||||
class Xuez(Coin):
|
class Xuez(Coin):
|
||||||
NAME = "Xuez"
|
NAME = "Xuez"
|
||||||
SHORTNAME = "XUEZ"
|
SHORTNAME = "XUEZ"
|
||||||
@ -1688,8 +1713,6 @@ class Xuez(Coin):
|
|||||||
WIF_BYTE = bytes.fromhex("d4")
|
WIF_BYTE = bytes.fromhex("d4")
|
||||||
GENESIS_HASH = ('000000e1febc39965b055e8e0117179a'
|
GENESIS_HASH = ('000000e1febc39965b055e8e0117179a'
|
||||||
'4d18e24e7aaa0c69864c4054b4f29445')
|
'4d18e24e7aaa0c69864c4054b4f29445')
|
||||||
|
|
||||||
|
|
||||||
TX_COUNT = 30000
|
TX_COUNT = 30000
|
||||||
TX_COUNT_HEIGHT = 15000
|
TX_COUNT_HEIGHT = 15000
|
||||||
TX_PER_BLOCK = 1
|
TX_PER_BLOCK = 1
|
||||||
@ -1740,6 +1763,7 @@ class Xuez(Coin):
|
|||||||
'nAccumulatorCheckpoint': hash_to_str(header[80:112]),
|
'nAccumulatorCheckpoint': hash_to_str(header[80:112]),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Pac(Coin):
|
class Pac(Coin):
|
||||||
NAME = "PAC"
|
NAME = "PAC"
|
||||||
SHORTNAME = "PAC"
|
SHORTNAME = "PAC"
|
||||||
@ -1770,6 +1794,7 @@ class Pac(Coin):
|
|||||||
import x11_hash
|
import x11_hash
|
||||||
return x11_hash.getPoWHash(header)
|
return x11_hash.getPoWHash(header)
|
||||||
|
|
||||||
|
|
||||||
class PacTestnet(Pac):
|
class PacTestnet(Pac):
|
||||||
SHORTNAME = "tPAC"
|
SHORTNAME = "tPAC"
|
||||||
NET = "testnet"
|
NET = "testnet"
|
||||||
|
|||||||
@ -74,8 +74,9 @@ def hash_to_hex_str(x):
|
|||||||
'''
|
'''
|
||||||
return bytes(reversed(x)).hex()
|
return bytes(reversed(x)).hex()
|
||||||
|
|
||||||
# Temporary
|
|
||||||
hash_to_str = hash_to_hex_str
|
hash_to_str = hash_to_hex_str # Temporary
|
||||||
|
|
||||||
|
|
||||||
def hex_str_to_hash(x):
|
def hex_str_to_hash(x):
|
||||||
'''Convert a displayed hex string to a binary hash.'''
|
'''Convert a displayed hex string to a binary hash.'''
|
||||||
|
|||||||
10
lib/util.py
10
lib/util.py
@ -249,7 +249,11 @@ def address_string(address):
|
|||||||
# See http://stackoverflow.com/questions/2532053/validate-a-hostname-string
|
# See http://stackoverflow.com/questions/2532053/validate-a-hostname-string
|
||||||
# Note underscores are valid in domain names, but strictly invalid in host
|
# Note underscores are valid in domain names, but strictly invalid in host
|
||||||
# names. We ignore that distinction.
|
# names. We ignore that distinction.
|
||||||
SEGMENT_REGEX = re.compile("(?!-)[A-Z_\d-]{1,63}(?<!-)$", re.IGNORECASE)
|
|
||||||
|
|
||||||
|
SEGMENT_REGEX = re.compile("(?!-)[A-Z_\\d-]{1,63}(?<!-)$", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
def is_valid_hostname(hostname):
|
def is_valid_hostname(hostname):
|
||||||
if len(hostname) > 255:
|
if len(hostname) > 255:
|
||||||
return False
|
return False
|
||||||
@ -258,6 +262,7 @@ def is_valid_hostname(hostname):
|
|||||||
hostname = hostname[:-1]
|
hostname = hostname[:-1]
|
||||||
return all(SEGMENT_REGEX.match(x) for x in hostname.split("."))
|
return all(SEGMENT_REGEX.match(x) for x in hostname.split("."))
|
||||||
|
|
||||||
|
|
||||||
def protocol_tuple(s):
|
def protocol_tuple(s):
|
||||||
'''Converts a protocol version number, such as "1.0" to a tuple (1, 0).
|
'''Converts a protocol version number, such as "1.0" to a tuple (1, 0).
|
||||||
|
|
||||||
@ -267,6 +272,7 @@ def protocol_tuple(s):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return (0, )
|
return (0, )
|
||||||
|
|
||||||
|
|
||||||
def version_string(ptuple):
|
def version_string(ptuple):
|
||||||
'''Convert a version tuple such as (1, 2) to "1.2".
|
'''Convert a version tuple such as (1, 2) to "1.2".
|
||||||
There is always at least one dot, so (1, ) becomes "1.0".'''
|
There is always at least one dot, so (1, ) becomes "1.0".'''
|
||||||
@ -274,6 +280,7 @@ def version_string(ptuple):
|
|||||||
ptuple += (0, )
|
ptuple += (0, )
|
||||||
return '.'.join(str(p) for p in ptuple)
|
return '.'.join(str(p) for p in ptuple)
|
||||||
|
|
||||||
|
|
||||||
def protocol_version(client_req, server_min, server_max):
|
def protocol_version(client_req, server_min, server_max):
|
||||||
'''Given a client protocol request, return the protocol version
|
'''Given a client protocol request, return the protocol version
|
||||||
to use as a tuple.
|
to use as a tuple.
|
||||||
@ -298,6 +305,7 @@ def protocol_version(client_req, server_min, server_max):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
unpack_int32_from = Struct('<i').unpack_from
|
unpack_int32_from = Struct('<i').unpack_from
|
||||||
unpack_int64_from = Struct('<q').unpack_from
|
unpack_int64_from = Struct('<q').unpack_from
|
||||||
unpack_uint16_from = Struct('<H').unpack_from
|
unpack_uint16_from = Struct('<H').unpack_from
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user