Changed to_json to to_dict in Appointment and Job; added to_json to Appointment to actually return a string

This commit is contained in:
Salvatore Ingala
2019-10-11 10:48:35 +07:00
parent e4e83167b7
commit 7c1d8b69c7
6 changed files with 28 additions and 14 deletions

View File

@@ -68,7 +68,7 @@ def get_appointment():
if appointment_in_watcher:
for uuid in appointment_in_watcher:
appointment_data = watcher.appointments[uuid].to_json()
appointment_data = watcher.appointments[uuid].to_dict()
appointment_data['status'] = "being_watched"
response.append(appointment_data)
@@ -77,7 +77,7 @@ def get_appointment():
for job in responder_jobs.values():
if job.locator == locator:
job_data = job.to_json()
job_data = job.to_dict()
job_data['status'] = "dispute_responded"
response.append(job_data)
@@ -98,11 +98,11 @@ def get_all_appointments():
if request.remote_addr in request.host or request.remote_addr == '127.0.0.1':
for uuid, appointment in watcher.appointments.items():
watcher_appointments[uuid] = appointment.to_json()
watcher_appointments[uuid] = appointment.to_dict()
if watcher.responder:
for uuid, job in watcher.responder.jobs.items():
responder_jobs[uuid] = job.to_json()
responder_jobs[uuid] = job.to_dict()
response = jsonify({"watcher_appointments": watcher_appointments, "responder_jobs": responder_jobs})

View File

@@ -15,7 +15,7 @@ class Appointment:
self.cipher = cipher
self.hash_function = hash_function
def to_json(self):
def to_dict(self):
appointment = {"locator": self.locator, "start_time": self.start_time, "end_time": self.end_time,
"dispute_delta": self.dispute_delta, "encrypted_blob": self.encrypted_blob.data,
"cipher": self.cipher, "hash_function": self.hash_function}
@@ -24,5 +24,5 @@ class Appointment:
# ToDO: #3-improve-appointment-structure
def serialize(self):
return json.dumps(self.to_json())
def to_json(self):
return json.dumps(self.to_dict())

View File

@@ -29,7 +29,7 @@ class Job:
# can be directly got from DB
self.locator = sha256(unhexlify(dispute_txid)).hexdigest()
def to_json(self):
def to_dict(self):
job = {"locator": self.locator, "justice_rawtx": self.justice_rawtx, "appointment_end": self.appointment_end}
return job

View File

@@ -64,7 +64,7 @@ class Watcher:
logger.info("New appointment accepted.", locator=appointment.locator)
if (self.signing_key is not None):
signature = self.signing_key.sign(appointment.serialize().encode('utf8'))
signature = self.signing_key.sign(appointment.to_json().encode('utf8'))
else:
appointment_added = False