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'
PORT = 9814
class StructuredMessage(object):
def __init__(self, message, **kwargs):
self.message = message
@@ -15,7 +16,7 @@ class StructuredMessage(object):
self.kwargs = kwargs
def __str__(self):
return json.dumps({ **self.kwargs, "message": self.message, "time": self.time })
return json.dumps({**self.kwargs, "message": self.message, "time": self.time})
M = StructuredMessage # to improve readability
@@ -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)
bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST,
conf.BTC_RPC_PORT))

View File

@@ -47,7 +47,8 @@ def add_appointment():
rcode = HTTP_BAD_REQUEST
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')

View File

@@ -75,7 +75,8 @@ class BlockProcessor:
justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid')
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:
# Tx decode failed returns error code -22, maybe we should be more strict here. Leaving it simple
@@ -101,7 +102,8 @@ class BlockProcessor:
else:
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

View File

@@ -32,7 +32,8 @@ class Carrier:
receipt = self.Receipt(delivered=False, reason=UNKNOWN_JSON_RPC_EXCEPTION)
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
# until the end of the appointment

View File

@@ -18,13 +18,14 @@ class Cleaner:
else:
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
def delete_completed_jobs(jobs, tx_job_map, completed_jobs, height):
for uuid, confirmations in completed_jobs:
logging.info(M("[Cleaner] job completed. Appointment ended after reaching enough confirmations.",
uuid=uuid, height=height, confirmations=confirmations))
uuid=uuid, height=height, confirmations=confirmations))
# ToDo: #9-add-data-persistence
justice_txid = jobs[uuid].justice_txid

View File

@@ -23,11 +23,10 @@ class EncryptedBlob:
nonce = master_key[16:]
logging.info(M("[Watcher] creating new blob.",
master_key=hexlify(master_key).decode(),
sk=hexlify(sk).decode(),
nonce=hexlify(sk).decode(),
encrypted_blob=self.data
))
master_key=hexlify(master_key).decode(),
sk=hexlify(sk).decode(),
nonce=hexlify(sk).decode(),
encrypted_blob=self.data))
# Decrypt
aesgcm = AESGCM(sk)

View File

@@ -80,7 +80,8 @@ class Responder:
if confirmations == 0:
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:
self.asleep = False
@@ -108,7 +109,8 @@ class Responder:
txs = block.get('tx')
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
# change prev_block_hash condition
@@ -123,7 +125,8 @@ class Responder:
else:
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()
@@ -170,7 +173,8 @@ class Responder:
self.jobs[uuid].justice_rawtx, self.jobs[uuid].appointment_end, retry=True)
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
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 justice_in_chain:
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

View File

@@ -29,4 +29,5 @@ class ZMQHandler:
block_hash = binascii.hexlify(body).decode('UTF-8')
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:
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