PEP8 linting

This commit is contained in:
Salvatore Ingala
2019-10-08 18:21:52 +07:00
parent ed0cb4f632
commit 2a5dd48950
9 changed files with 32 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ import pisa.conf as conf
HOST = 'localhost' HOST = 'localhost'
PORT = 9814 PORT = 9814
class StructuredMessage(object): class StructuredMessage(object):
def __init__(self, message, **kwargs): def __init__(self, message, **kwargs):
self.message = message self.message = message
@@ -31,4 +32,3 @@ logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[
# TODO: Check if a long lived connection like this may create problems (timeouts) # TODO: Check if a long lived connection like this may create problems (timeouts)
bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST, bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST,
conf.BTC_RPC_PORT)) conf.BTC_RPC_PORT))

View File

@@ -47,7 +47,8 @@ def add_appointment():
rcode = HTTP_BAD_REQUEST rcode = HTTP_BAD_REQUEST
response = "appointment rejected. Request does not match the standard" response = "appointment rejected. Request does not match the standard"
logging.info(M('[API] sending response and disconnecting', from_addr_port='{}:{}'.format(remote_addr, remote_port), response=response)) logging.info(M('[API] sending response and disconnecting',
from_addr_port='{}:{}'.format(remote_addr, remote_port), response=response))
return Response(response, status=rcode, mimetype='text/plain') return Response(response, status=rcode, mimetype='text/plain')

View File

@@ -75,7 +75,8 @@ class BlockProcessor:
justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid') justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid')
matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx)) matches.append((locator, uuid, dispute_txid, justice_txid, justice_rawtx))
logging.info(M("[BlockProcessor] match found for locator.", locator=locator, uuid=uuid, justice_txid=justice_txid)) logging.info(M("[BlockProcessor] match found for locator.",
locator=locator, uuid=uuid, justice_txid=justice_txid))
except JSONRPCException as e: except JSONRPCException as e:
# Tx decode failed returns error code -22, maybe we should be more strict here. Leaving it simple # Tx decode failed returns error code -22, maybe we should be more strict here. Leaving it simple
@@ -101,7 +102,8 @@ class BlockProcessor:
else: else:
missed_confirmations[tx] = 1 missed_confirmations[tx] = 1
logging.info(M("[Responder] transaction missed a confirmation", tx=tx, missed_confirmations=missed_confirmations[tx])) logging.info(M("[Responder] transaction missed a confirmation",
tx=tx, missed_confirmations=missed_confirmations[tx]))
return unconfirmed_txs, missed_confirmations return unconfirmed_txs, missed_confirmations

View File

@@ -32,7 +32,8 @@ class Carrier:
receipt = self.Receipt(delivered=False, reason=UNKNOWN_JSON_RPC_EXCEPTION) receipt = self.Receipt(delivered=False, reason=UNKNOWN_JSON_RPC_EXCEPTION)
elif errno == RPC_VERIFY_ALREADY_IN_CHAIN: elif errno == RPC_VERIFY_ALREADY_IN_CHAIN:
logging.info(M("[Carrier] Transaction is already in the blockchain. Getting confirmation count", txid=txid)) logging.info(M("[Carrier] Transaction is already in the blockchain. Getting confirmation count",
txid=txid))
# If the transaction is already in the chain, we get the number of confirmations and watch the job # If the transaction is already in the chain, we get the number of confirmations and watch the job
# until the end of the appointment # until the end of the appointment

View File

@@ -18,7 +18,8 @@ class Cleaner:
else: else:
locator_uuid_map[locator].remove(uuid) locator_uuid_map[locator].remove(uuid)
logging.info(M("[Cleaner] end time reached with no match! Deleting appointment.", locator=locator, uuid=uuid)) logging.info(M("[Cleaner] end time reached with no match! Deleting appointment.",
locator=locator, uuid=uuid))
@staticmethod @staticmethod
def delete_completed_jobs(jobs, tx_job_map, completed_jobs, height): def delete_completed_jobs(jobs, tx_job_map, completed_jobs, height):

View File

@@ -26,8 +26,7 @@ class EncryptedBlob:
master_key=hexlify(master_key).decode(), master_key=hexlify(master_key).decode(),
sk=hexlify(sk).decode(), sk=hexlify(sk).decode(),
nonce=hexlify(sk).decode(), nonce=hexlify(sk).decode(),
encrypted_blob=self.data encrypted_blob=self.data))
))
# Decrypt # Decrypt
aesgcm = AESGCM(sk) aesgcm = AESGCM(sk)

View File

@@ -80,7 +80,8 @@ class Responder:
if confirmations == 0: if confirmations == 0:
self.unconfirmed_txs.append(justice_txid) self.unconfirmed_txs.append(justice_txid)
logging.info(M("[Responder] new job added.", dispute_txid=dispute_txid, justice_txid=justice_txid, appointment_end=appointment_end)) logging.info(M("[Responder] new job added.",
dispute_txid=dispute_txid, justice_txid=justice_txid, appointment_end=appointment_end))
if self.asleep: if self.asleep:
self.asleep = False self.asleep = False
@@ -108,7 +109,8 @@ class Responder:
txs = block.get('tx') txs = block.get('tx')
height = block.get('height') height = block.get('height')
logging.info(M("[Responder] new block received", block_hash=block_hash, prev_block_hash=block.get('previousblockhash'), txs=txs)) logging.info(M("[Responder] new block received",
block_hash=block_hash, prev_block_hash=block.get('previousblockhash'), txs=txs))
# ToDo: #9-add-data-persistence # ToDo: #9-add-data-persistence
# change prev_block_hash condition # change prev_block_hash condition
@@ -123,7 +125,8 @@ class Responder:
else: else:
logging.warning(M("[Responder] reorg found!", logging.warning(M("[Responder] reorg found!",
local_prev_block_hash=prev_block_hash, remote_prev_block_hash=block.get('previousblockhash'))) local_prev_block_hash=prev_block_hash,
remote_prev_block_hash=block.get('previousblockhash')))
self.handle_reorgs() self.handle_reorgs()
@@ -170,7 +173,8 @@ class Responder:
self.jobs[uuid].justice_rawtx, self.jobs[uuid].appointment_end, retry=True) self.jobs[uuid].justice_rawtx, self.jobs[uuid].appointment_end, retry=True)
logging.warning(M("[Responder] Transaction has missed many confirmations. Rebroadcasting.", logging.warning(M("[Responder] Transaction has missed many confirmations. Rebroadcasting.",
justice_txid=self.jobs[uuid].justice_txid, confirmations_missed=CONFIRMATIONS_BEFORE_RETRY)) justice_txid=self.jobs[uuid].justice_txid,
confirmations_missed=CONFIRMATIONS_BEFORE_RETRY))
# FIXME: Legacy code, must be checked and updated/fixed # FIXME: Legacy code, must be checked and updated/fixed
def handle_reorgs(self): def handle_reorgs(self):
@@ -187,7 +191,9 @@ class Responder:
# If both transactions are there, we only need to update the justice tx confirmation count # If both transactions are there, we only need to update the justice tx confirmation count
if justice_in_chain: if justice_in_chain:
logging.info(M("[Responder] updating confirmation count for transaction.", logging.info(M("[Responder] updating confirmation count for transaction.",
justice_txid=job.justice_txid, prev_count=job.confirmations, curr_count=justice_confirmations)) justice_txid=job.justice_txid,
prev_count=job.confirmations,
curr_count=justice_confirmations))
job.confirmations = justice_confirmations job.confirmations = justice_confirmations

View File

@@ -29,4 +29,5 @@ class ZMQHandler:
block_hash = binascii.hexlify(body).decode('UTF-8') block_hash = binascii.hexlify(body).decode('UTF-8')
block_queue.put(block_hash) block_queue.put(block_hash)
logging.info(M("[ZMQHandler-{}] new block received via ZMQ".format(self.parent), block_hash=block_hash)) logging.info(M("[ZMQHandler-{}] new block received via ZMQ".format(self.parent),
block_hash=block_hash))

View File

@@ -61,7 +61,8 @@ class Watcher:
else: else:
appointment_added = False appointment_added = False
logging.info(M("[Watcher] maximum appointments reached, appointment rejected.", locator=appointment.locator)) logging.info(M("[Watcher] maximum appointments reached, appointment rejected.",
locator=appointment.locator))
return appointment_added return appointment_added