diff --git a/.travis.yml b/.travis.yml index a08241f..339b667 100644 --- a/.travis.yml +++ b/.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 diff --git a/server/controller.py b/server/controller.py index 351e777..5d23fa0 100644 --- a/server/controller.py +++ b/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() diff --git a/server/daemon.py b/server/daemon.py index 70ccf54..e0e97b3 100644 --- a/server/daemon.py +++ b/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. @@ -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(' 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)) diff --git a/server/peers.py b/server/peers.py index aa16b05..d7062c4 100644 --- a/server/peers.py +++ b/server/peers.py @@ -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 diff --git a/server/session.py b/server/session.py index e8db1e0..d3fac0c 100644 --- a/server/session.py +++ b/server/session.py @@ -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