Enforce pycodestyle in server/
This commit is contained in:
parent
e29b692b9d
commit
46adf543fc
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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.
|
||||
@ -305,7 +306,7 @@ class DashDaemon(Daemon):
|
||||
'''Broadcast a transaction to the network.'''
|
||||
return await self._send_single('masternodebroadcast', params)
|
||||
|
||||
async def masternode_list(self, params ):
|
||||
async def masternode_list(self, params):
|
||||
'''Return the masternode status.'''
|
||||
return await self._send_single('masternodelist', params)
|
||||
|
||||
@ -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'''
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -232,8 +232,8 @@ class PeerManager(object):
|
||||
self.loop = controller.loop
|
||||
|
||||
# Our clearnet and Tor Peers, if any
|
||||
self.myselves = [Peer(ident.host, controller.server_features(), 'env')
|
||||
for ident in env.identities]
|
||||
self.myselves = [Peer(ident.host, controller.server_features(), 'env')
|
||||
for ident in env.identities]
|
||||
self.retry_event = asyncio.Event()
|
||||
# Peers have one entry per hostname. Once connected, 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)
|
||||
count = self.controller.non_negative_integer(count)
|
||||
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}
|
||||
|
||||
def block_get_chunk(self, index):
|
||||
@ -304,7 +304,7 @@ class ElectrumX(SessionBase):
|
||||
index = self.controller.non_negative_integer(index)
|
||||
chunk_size = self.controller.coin.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
|
||||
|
||||
def is_tor(self):
|
||||
@ -503,7 +503,7 @@ class DashElectrumX(ElectrumX):
|
||||
for masternode in self.mns:
|
||||
status = await self.daemon.masternode_list(['status', masternode])
|
||||
self.send_notification('masternode.subscribe',
|
||||
[masternode, status.get(masternode)])
|
||||
[masternode, status.get(masternode)])
|
||||
|
||||
def notify(self, height, touched):
|
||||
'''Notify the client about changes in masternode list.'''
|
||||
@ -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
|
||||
@ -553,7 +552,7 @@ class DashElectrumX(ElectrumX):
|
||||
mns: a list of masternodes information.
|
||||
'''
|
||||
now = int(datetime.datetime.utcnow().strftime("%s"))
|
||||
mn_queue=[]
|
||||
mn_queue = []
|
||||
|
||||
# Only ENABLED masternodes are considered for the list.
|
||||
for line in mns:
|
||||
@ -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,17 +612,21 @@ 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
|
||||
|
||||
# If payees is an empty list the whole masternode list is returned
|
||||
if payees:
|
||||
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:
|
||||
result = self.controller.mn_cache
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user