Fixes to_dict/to_json for and some fixes

This commit is contained in:
Sergi Delgado Segura
2019-10-17 19:11:32 +01:00
parent 6735aac094
commit c09becd7fa
2 changed files with 10 additions and 4 deletions

View File

@@ -102,7 +102,7 @@ def get_all_appointments():
if watcher.responder: if watcher.responder:
for uuid, job in watcher.responder.jobs.items(): 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}) response = jsonify({"watcher_appointments": watcher_appointments, "responder_jobs": responder_jobs})

View File

@@ -1,6 +1,7 @@
import json
from queue import Queue from queue import Queue
from threading import Thread
from hashlib import sha256 from hashlib import sha256
from threading import Thread
from binascii import unhexlify from binascii import unhexlify
from pisa.logger import Logger from pisa.logger import Logger
@@ -29,11 +30,14 @@ class Job:
# can be directly got from DB # can be directly got from DB
self.locator = sha256(unhexlify(dispute_txid)).hexdigest() 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} job = {"locator": self.locator, "justice_rawtx": self.justice_rawtx, "appointment_end": self.appointment_end}
return job return job
def to_json(self):
return json.dumps(self.to_dict())
class Responder: class Responder:
def __init__(self): def __init__(self):
@@ -62,6 +66,8 @@ class Responder:
# TODO: Add the missing reasons (e.g. RPC_VERIFY_REJECTED) # TODO: Add the missing reasons (e.g. RPC_VERIFY_REJECTED)
pass pass
return receipt
def create_job(self, uuid, dispute_txid, justice_txid, justice_rawtx, appointment_end, confirmations=0, def create_job(self, uuid, dispute_txid, justice_txid, justice_rawtx, appointment_end, confirmations=0,
retry=False): retry=False):
@@ -155,7 +161,7 @@ class Responder:
for uuid, job in self.jobs.items(): for uuid, job in self.jobs.items():
if job.appointment_end <= height: if job.appointment_end <= height:
tx = Carrier.get_transaction(job.dispute_txid) tx = Carrier.get_transaction(job.justice_txid)
# FIXME: Should be improved with the librarian # FIXME: Should be improved with the librarian
confirmations = tx.get('confirmations') confirmations = tx.get('confirmations')