diff --git a/pisa/__init__.py b/pisa/__init__.py index 7fa2901..9ba1a28 100644 --- a/pisa/__init__.py +++ b/pisa/__init__.py @@ -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)) - diff --git a/pisa/api.py b/pisa/api.py index df98cd0..b437d80 100644 --- a/pisa/api.py +++ b/pisa/api.py @@ -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') diff --git a/pisa/block_processor.py b/pisa/block_processor.py index 4343bb9..08bd1c9 100644 --- a/pisa/block_processor.py +++ b/pisa/block_processor.py @@ -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 diff --git a/pisa/carrier.py b/pisa/carrier.py index 946af01..6efa58f 100644 --- a/pisa/carrier.py +++ b/pisa/carrier.py @@ -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 diff --git a/pisa/cleaner.py b/pisa/cleaner.py index 68ad5e2..f9d748b 100644 --- a/pisa/cleaner.py +++ b/pisa/cleaner.py @@ -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 diff --git a/pisa/encrypted_blob.py b/pisa/encrypted_blob.py index 3aeee13..1dcf644 100644 --- a/pisa/encrypted_blob.py +++ b/pisa/encrypted_blob.py @@ -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) diff --git a/pisa/responder.py b/pisa/responder.py index e44ee61..ae1859e 100644 --- a/pisa/responder.py +++ b/pisa/responder.py @@ -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 diff --git a/pisa/utils/zmq_subscriber.py b/pisa/utils/zmq_subscriber.py index 0545d9c..4fbc63b 100644 --- a/pisa/utils/zmq_subscriber.py +++ b/pisa/utils/zmq_subscriber.py @@ -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)) diff --git a/pisa/watcher.py b/pisa/watcher.py index a70bb43..3e62f06 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -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