Browse Source

Enforce pycodestyle in server/

patch-2
Neil Booth 7 years ago
parent
commit
46adf543fc
  1. 5
      .travis.yml
  2. 4
      server/controller.py
  3. 22
      server/daemon.py
  4. 6
      server/env.py
  5. 7
      server/mempool.py
  6. 21
      server/session.py

5
.travis.yml

@ -17,6 +17,7 @@ install:
- pip install aiorpcX
- pip install ecdsa
- pip install plyvel
- pip install pycodestyle
- pip install pyrocksdb
- pip install tribus-hash
- pip install pytest-cov
@ -25,7 +26,9 @@ install:
- pip install x11_hash
- pip install xevan_hash
# 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
after_success:
- if [[ $(python3 -V 2>&1) == *"Python 3.6"* ]]; then

4
server/controller.py

@ -87,8 +87,8 @@ class Controller(ServerBase):
self.mn_cache = pylru.lrucache(256)
env.max_send = max(350000, env.max_send)
# Set up the RPC request handlers
cmds = ('add_peer daemon_url disconnect getinfo groups log peers reorg '
'sessions stop'.split())
cmds = ('add_peer daemon_url disconnect getinfo groups log peers '
'reorg sessions stop'.split())
self.rpc_handlers = {cmd: getattr(self, 'rpc_' + cmd) for cmd in cmds}
self.loop = asyncio.get_event_loop()

22
server/daemon.py

@ -217,8 +217,8 @@ class Daemon(object):
# probably because we did not provide arguments
available = True
else:
self.logger.warning('unexpected error (code {:d}: {}) when '
'testing RPC availability of method {}'
self.logger.warning('error (code {:d}: {}) when testing '
'RPC availability of method {}'
.format(error_code, err.get("message"),
method))
available = False
@ -264,7 +264,8 @@ class Daemon(object):
async def getrawtransaction(self, hex_hash, verbose=False):
'''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):
'''Return the serialized raw transactions with the given hashes.
@ -350,13 +351,14 @@ class LegacyRPCDaemon(Daemon):
pbh = b.get('previousblockhash')
if pbh is None:
pbh = '0' * 64
header = pack('<L', b.get('version')) \
+ hex_str_to_hash(pbh) \
+ hex_str_to_hash(b.get('merkleroot')) \
+ pack('<L', self.timestamp_safe(b['time'])) \
+ pack('<L', int(b.get('bits'), 16)) \
+ pack('<L', int(b.get('nonce')))
return header
return b''.join([
pack('<L', b.get('version')),
hex_str_to_hash(pbh),
hex_str_to_hash(b.get('merkleroot')),
pack('<L', self.timestamp_safe(b['time'])),
pack('<L', int(b.get('bits'), 16)),
pack('<L', int(b.get('nonce')))
])
async def make_raw_block(self, b):
'''Construct a raw block'''

6
server/env.py

@ -132,8 +132,10 @@ class Env(EnvBase):
result = getattr(clearnet, port_kind)
return result or getattr(self, port_kind)
tcp_port = self.integer('REPORT_TCP_PORT_TOR', port('tcp_port')) or None
ssl_port = self.integer('REPORT_SSL_PORT_TOR', port('ssl_port')) or None
tcp_port = self.integer('REPORT_TCP_PORT_TOR',
port('tcp_port')) or None
ssl_port = self.integer('REPORT_SSL_PORT_TOR',
port('ssl_port')) or None
if tcp_port == ssl_port:
raise self.Error('REPORT_TCP_PORT_TOR and REPORT_SSL_PORT_TOR '
'both resolve to {}'.format(tcp_port))

7
server/mempool.py

@ -176,7 +176,8 @@ class MemPool(object):
txin_pairs, txout_pairs, tx_fee, tx_size = item
fee_rate = tx_fee // 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)
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
# are chosen so as to create tranches that contain at least
# 100kb of transactions
l = list(reversed(sorted(self.fee_histogram.items())))
items = list(reversed(sorted(self.fee_histogram.items())))
out = []
size = 0
r = 0
binsize = 100000
for fee, s in l:
for fee, s in items:
size += s
if size + r > binsize:
out.append((fee, size))

21
server/session.py

@ -511,7 +511,6 @@ class DashElectrumX(ElectrumX):
self.controller.create_task(self.notify_masternodes_async())
return result
# Masternode command handlers
async def masternode_announce_broadcast(self, signmnb):
'''Pass through the masternode announce message to be broadcast
@ -590,9 +589,11 @@ class DashElectrumX(ElectrumX):
break
return position
# Accordingly with the masternode payment queue, a custom list with
# the masternode information including the payment position is returned.
if self.controller.cache_mn_height != self.height() or not self.controller.mn_cache:
# Accordingly with the masternode payment queue, a custom list
# with the masternode information including the payment
# 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.mn_cache.clear()
full_mn_list = await self.daemon.masternode_list(['full'])
@ -611,10 +612,14 @@ class DashElectrumX(ElectrumX):
mn_info['lastpaidtime'] = mn_data[5]
mn_info['lastpaidblock'] = mn_data[6]
mn_info['ip'] = mn_data[7]
mn_info['paymentposition'] = get_payment_position(mn_payment_queue, mn_info['payee'])
mn_info['inselection'] = 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_info['paymentposition'] = get_payment_position(
mn_payment_queue, mn_info['payee'])
mn_info['inselection'] = (
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)
self.controller.mn_cache = mn_list

Loading…
Cancel
Save