Enforce pycodestyle in server/
This commit is contained in:
parent
e29b692b9d
commit
46adf543fc
@ -17,6 +17,7 @@ install:
|
|||||||
- pip install aiorpcX
|
- pip install aiorpcX
|
||||||
- pip install ecdsa
|
- pip install ecdsa
|
||||||
- pip install plyvel
|
- pip install plyvel
|
||||||
|
- pip install pycodestyle
|
||||||
- pip install pyrocksdb
|
- pip install pyrocksdb
|
||||||
- pip install tribus-hash
|
- pip install tribus-hash
|
||||||
- pip install pytest-cov
|
- pip install pytest-cov
|
||||||
@ -25,7 +26,9 @@ install:
|
|||||||
- pip install x11_hash
|
- pip install x11_hash
|
||||||
- pip install xevan_hash
|
- pip install xevan_hash
|
||||||
# command to run tests
|
# command to run tests
|
||||||
script: pytest --cov=server --cov=lib --cov=wallet
|
script:
|
||||||
|
- pytest --cov=server --cov=lib --cov=wallet
|
||||||
|
- pycodestyle server/*.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
|
||||||
|
|||||||
@ -87,8 +87,8 @@ class Controller(ServerBase):
|
|||||||
self.mn_cache = pylru.lrucache(256)
|
self.mn_cache = pylru.lrucache(256)
|
||||||
env.max_send = max(350000, env.max_send)
|
env.max_send = max(350000, env.max_send)
|
||||||
# Set up the RPC request handlers
|
# Set up the RPC request handlers
|
||||||
cmds = ('add_peer daemon_url disconnect getinfo groups log peers reorg '
|
cmds = ('add_peer daemon_url disconnect getinfo groups log peers '
|
||||||
'sessions stop'.split())
|
'reorg sessions stop'.split())
|
||||||
self.rpc_handlers = {cmd: getattr(self, 'rpc_' + cmd) for cmd in cmds}
|
self.rpc_handlers = {cmd: getattr(self, 'rpc_' + cmd) for cmd in cmds}
|
||||||
|
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
|||||||
@ -217,8 +217,8 @@ class Daemon(object):
|
|||||||
# probably because we did not provide arguments
|
# probably because we did not provide arguments
|
||||||
available = True
|
available = True
|
||||||
else:
|
else:
|
||||||
self.logger.warning('unexpected error (code {:d}: {}) when '
|
self.logger.warning('error (code {:d}: {}) when testing '
|
||||||
'testing RPC availability of method {}'
|
'RPC availability of method {}'
|
||||||
.format(error_code, err.get("message"),
|
.format(error_code, err.get("message"),
|
||||||
method))
|
method))
|
||||||
available = False
|
available = False
|
||||||
@ -264,7 +264,8 @@ class Daemon(object):
|
|||||||
|
|
||||||
async def getrawtransaction(self, hex_hash, verbose=False):
|
async def getrawtransaction(self, hex_hash, verbose=False):
|
||||||
'''Return the serialized raw transaction with the given hash.'''
|
'''Return the serialized raw transaction with the given hash.'''
|
||||||
return await self._send_single('getrawtransaction', (hex_hash, int(verbose)))
|
return await self._send_single('getrawtransaction',
|
||||||
|
(hex_hash, int(verbose)))
|
||||||
|
|
||||||
async def getrawtransactions(self, hex_hashes, replace_errs=True):
|
async def getrawtransactions(self, hex_hashes, replace_errs=True):
|
||||||
'''Return the serialized raw transactions with the given hashes.
|
'''Return the serialized raw transactions with the given hashes.
|
||||||
@ -305,7 +306,7 @@ class DashDaemon(Daemon):
|
|||||||
'''Broadcast a transaction to the network.'''
|
'''Broadcast a transaction to the network.'''
|
||||||
return await self._send_single('masternodebroadcast', params)
|
return await self._send_single('masternodebroadcast', params)
|
||||||
|
|
||||||
async def masternode_list(self, params ):
|
async def masternode_list(self, params):
|
||||||
'''Return the masternode status.'''
|
'''Return the masternode status.'''
|
||||||
return await self._send_single('masternodelist', params)
|
return await self._send_single('masternodelist', params)
|
||||||
|
|
||||||
@ -350,13 +351,14 @@ class LegacyRPCDaemon(Daemon):
|
|||||||
pbh = b.get('previousblockhash')
|
pbh = b.get('previousblockhash')
|
||||||
if pbh is None:
|
if pbh is None:
|
||||||
pbh = '0' * 64
|
pbh = '0' * 64
|
||||||
header = pack('<L', b.get('version')) \
|
return b''.join([
|
||||||
+ hex_str_to_hash(pbh) \
|
pack('<L', b.get('version')),
|
||||||
+ hex_str_to_hash(b.get('merkleroot')) \
|
hex_str_to_hash(pbh),
|
||||||
+ pack('<L', self.timestamp_safe(b['time'])) \
|
hex_str_to_hash(b.get('merkleroot')),
|
||||||
+ pack('<L', int(b.get('bits'), 16)) \
|
pack('<L', self.timestamp_safe(b['time'])),
|
||||||
+ pack('<L', int(b.get('nonce')))
|
pack('<L', int(b.get('bits'), 16)),
|
||||||
return header
|
pack('<L', int(b.get('nonce')))
|
||||||
|
])
|
||||||
|
|
||||||
async def make_raw_block(self, b):
|
async def make_raw_block(self, b):
|
||||||
'''Construct a raw block'''
|
'''Construct a raw block'''
|
||||||
|
|||||||
@ -132,8 +132,10 @@ class Env(EnvBase):
|
|||||||
result = getattr(clearnet, port_kind)
|
result = getattr(clearnet, port_kind)
|
||||||
return result or getattr(self, port_kind)
|
return result or getattr(self, port_kind)
|
||||||
|
|
||||||
tcp_port = self.integer('REPORT_TCP_PORT_TOR', port('tcp_port')) or None
|
tcp_port = self.integer('REPORT_TCP_PORT_TOR',
|
||||||
ssl_port = self.integer('REPORT_SSL_PORT_TOR', port('ssl_port')) or None
|
port('tcp_port')) or None
|
||||||
|
ssl_port = self.integer('REPORT_SSL_PORT_TOR',
|
||||||
|
port('ssl_port')) or None
|
||||||
if tcp_port == ssl_port:
|
if tcp_port == ssl_port:
|
||||||
raise self.Error('REPORT_TCP_PORT_TOR and REPORT_SSL_PORT_TOR '
|
raise self.Error('REPORT_TCP_PORT_TOR and REPORT_SSL_PORT_TOR '
|
||||||
'both resolve to {}'.format(tcp_port))
|
'both resolve to {}'.format(tcp_port))
|
||||||
|
|||||||
@ -176,7 +176,8 @@ class MemPool(object):
|
|||||||
txin_pairs, txout_pairs, tx_fee, tx_size = item
|
txin_pairs, txout_pairs, tx_fee, tx_size = item
|
||||||
fee_rate = tx_fee // tx_size
|
fee_rate = tx_fee // tx_size
|
||||||
fee_hist[fee_rate] += tx_size
|
fee_hist[fee_rate] += tx_size
|
||||||
for hashX, value in itertools.chain(txin_pairs, txout_pairs):
|
for hashX, value in itertools.chain(txin_pairs,
|
||||||
|
txout_pairs):
|
||||||
touched.add(hashX)
|
touched.add(hashX)
|
||||||
hashXs[hashX].add(hex_hash)
|
hashXs[hashX].add(hex_hash)
|
||||||
|
|
||||||
@ -380,12 +381,12 @@ class MemPool(object):
|
|||||||
# [fee_(n-1), fee_n)], and fee_(n-1) > fee_n. Fee intervals
|
# [fee_(n-1), fee_n)], and fee_(n-1) > fee_n. Fee intervals
|
||||||
# are chosen so as to create tranches that contain at least
|
# are chosen so as to create tranches that contain at least
|
||||||
# 100kb of transactions
|
# 100kb of transactions
|
||||||
l = list(reversed(sorted(self.fee_histogram.items())))
|
items = list(reversed(sorted(self.fee_histogram.items())))
|
||||||
out = []
|
out = []
|
||||||
size = 0
|
size = 0
|
||||||
r = 0
|
r = 0
|
||||||
binsize = 100000
|
binsize = 100000
|
||||||
for fee, s in l:
|
for fee, s in items:
|
||||||
size += s
|
size += s
|
||||||
if size + r > binsize:
|
if size + r > binsize:
|
||||||
out.append((fee, size))
|
out.append((fee, size))
|
||||||
|
|||||||
@ -232,8 +232,8 @@ class PeerManager(object):
|
|||||||
self.loop = controller.loop
|
self.loop = controller.loop
|
||||||
|
|
||||||
# Our clearnet and Tor Peers, if any
|
# Our clearnet and Tor Peers, if any
|
||||||
self.myselves = [Peer(ident.host, controller.server_features(), 'env')
|
self.myselves = [Peer(ident.host, controller.server_features(), 'env')
|
||||||
for ident in env.identities]
|
for ident in env.identities]
|
||||||
self.retry_event = asyncio.Event()
|
self.retry_event = asyncio.Event()
|
||||||
# Peers have one entry per hostname. Once connected, the
|
# Peers have one entry per hostname. Once connected, the
|
||||||
# ip_addr property is either None, an onion peer, or the
|
# ip_addr property is either None, an onion peer, or the
|
||||||
|
|||||||
@ -294,7 +294,7 @@ class ElectrumX(SessionBase):
|
|||||||
start_height = self.controller.non_negative_integer(start_height)
|
start_height = self.controller.non_negative_integer(start_height)
|
||||||
count = self.controller.non_negative_integer(count)
|
count = self.controller.non_negative_integer(count)
|
||||||
count = min(count, self.MAX_CHUNK_SIZE)
|
count = min(count, self.MAX_CHUNK_SIZE)
|
||||||
hex_str, n = self.controller.block_headers(start_height, count)
|
hex_str, n = self.controller.block_headers(start_height, count)
|
||||||
return {'hex': hex_str, 'count': n, 'max': self.MAX_CHUNK_SIZE}
|
return {'hex': hex_str, 'count': n, 'max': self.MAX_CHUNK_SIZE}
|
||||||
|
|
||||||
def block_get_chunk(self, index):
|
def block_get_chunk(self, index):
|
||||||
@ -304,7 +304,7 @@ class ElectrumX(SessionBase):
|
|||||||
index = self.controller.non_negative_integer(index)
|
index = self.controller.non_negative_integer(index)
|
||||||
chunk_size = self.controller.coin.CHUNK_SIZE
|
chunk_size = self.controller.coin.CHUNK_SIZE
|
||||||
start_height = index * chunk_size
|
start_height = index * chunk_size
|
||||||
hex_str, n = self.controller.block_headers(start_height, chunk_size)
|
hex_str, n = self.controller.block_headers(start_height, chunk_size)
|
||||||
return hex_str
|
return hex_str
|
||||||
|
|
||||||
def is_tor(self):
|
def is_tor(self):
|
||||||
@ -503,7 +503,7 @@ class DashElectrumX(ElectrumX):
|
|||||||
for masternode in self.mns:
|
for masternode in self.mns:
|
||||||
status = await self.daemon.masternode_list(['status', masternode])
|
status = await self.daemon.masternode_list(['status', masternode])
|
||||||
self.send_notification('masternode.subscribe',
|
self.send_notification('masternode.subscribe',
|
||||||
[masternode, status.get(masternode)])
|
[masternode, status.get(masternode)])
|
||||||
|
|
||||||
def notify(self, height, touched):
|
def notify(self, height, touched):
|
||||||
'''Notify the client about changes in masternode list.'''
|
'''Notify the client about changes in masternode list.'''
|
||||||
@ -511,7 +511,6 @@ class DashElectrumX(ElectrumX):
|
|||||||
self.controller.create_task(self.notify_masternodes_async())
|
self.controller.create_task(self.notify_masternodes_async())
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# Masternode command handlers
|
# Masternode command handlers
|
||||||
async def masternode_announce_broadcast(self, signmnb):
|
async def masternode_announce_broadcast(self, signmnb):
|
||||||
'''Pass through the masternode announce message to be broadcast
|
'''Pass through the masternode announce message to be broadcast
|
||||||
@ -553,7 +552,7 @@ class DashElectrumX(ElectrumX):
|
|||||||
mns: a list of masternodes information.
|
mns: a list of masternodes information.
|
||||||
'''
|
'''
|
||||||
now = int(datetime.datetime.utcnow().strftime("%s"))
|
now = int(datetime.datetime.utcnow().strftime("%s"))
|
||||||
mn_queue=[]
|
mn_queue = []
|
||||||
|
|
||||||
# Only ENABLED masternodes are considered for the list.
|
# Only ENABLED masternodes are considered for the list.
|
||||||
for line in mns:
|
for line in mns:
|
||||||
@ -590,9 +589,11 @@ class DashElectrumX(ElectrumX):
|
|||||||
break
|
break
|
||||||
return position
|
return position
|
||||||
|
|
||||||
# Accordingly with the masternode payment queue, a custom list with
|
# Accordingly with the masternode payment queue, a custom list
|
||||||
# the masternode information including the payment position is returned.
|
# with the masternode information including the payment
|
||||||
if self.controller.cache_mn_height != self.height() or not self.controller.mn_cache:
|
# position is returned.
|
||||||
|
if (self.controller.cache_mn_height != self.height()
|
||||||
|
or not self.controller.mn_cache):
|
||||||
self.controller.cache_mn_height = self.height()
|
self.controller.cache_mn_height = self.height()
|
||||||
self.controller.mn_cache.clear()
|
self.controller.mn_cache.clear()
|
||||||
full_mn_list = await self.daemon.masternode_list(['full'])
|
full_mn_list = await self.daemon.masternode_list(['full'])
|
||||||
@ -611,17 +612,21 @@ class DashElectrumX(ElectrumX):
|
|||||||
mn_info['lastpaidtime'] = mn_data[5]
|
mn_info['lastpaidtime'] = mn_data[5]
|
||||||
mn_info['lastpaidblock'] = mn_data[6]
|
mn_info['lastpaidblock'] = mn_data[6]
|
||||||
mn_info['ip'] = mn_data[7]
|
mn_info['ip'] = mn_data[7]
|
||||||
mn_info['paymentposition'] = get_payment_position(mn_payment_queue, mn_info['payee'])
|
mn_info['paymentposition'] = get_payment_position(
|
||||||
mn_info['inselection'] = mn_info['paymentposition'] < mn_payment_count // 10
|
mn_payment_queue, mn_info['payee'])
|
||||||
balance = await self.controller.address_get_balance(mn_info['payee'])
|
mn_info['inselection'] = (
|
||||||
mn_info['balance'] = sum(balance.values()) / self.controller.coin.VALUE_PER_COIN
|
mn_info['paymentposition'] < mn_payment_count // 10)
|
||||||
|
balance = await self.controller.address_get_balance(
|
||||||
|
mn_info['payee'])
|
||||||
|
mn_info['balance'] = (sum(balance.values())
|
||||||
|
/ self.controller.coin.VALUE_PER_COIN)
|
||||||
mn_list.append(mn_info)
|
mn_list.append(mn_info)
|
||||||
self.controller.mn_cache = mn_list
|
self.controller.mn_cache = mn_list
|
||||||
|
|
||||||
# If payees is an empty list the whole masternode list is returned
|
# If payees is an empty list the whole masternode list is returned
|
||||||
if payees:
|
if payees:
|
||||||
result = [mn for mn in self.controller.mn_cache
|
result = [mn for mn in self.controller.mn_cache
|
||||||
for address in payees if mn['payee'] == address]
|
for address in payees if mn['payee'] == address]
|
||||||
else:
|
else:
|
||||||
result = self.controller.mn_cache
|
result = self.controller.mn_cache
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user