1
0

store contacts and invoices in wallet file. fix #1482

This commit is contained in:
ThomasV
2017-03-06 17:12:27 +01:00
parent acd70f55c3
commit dcffea150e
13 changed files with 96 additions and 91 deletions

View File

@@ -457,18 +457,13 @@ def make_request(config, req):
class InvoiceStore(object):
def __init__(self, config):
self.config = config
def __init__(self, storage):
self.storage = storage
self.invoices = {}
self.load_invoices()
d = self.storage.get('invoices', {})
self.load(d)
def load_invoices(self):
path = os.path.join(self.config.path, 'invoices')
try:
with open(path, 'r') as f:
d = json.loads(f.read())
except:
return
def load(self, d):
for k, v in d.items():
try:
pr = PaymentRequest(v.get('hex').decode('hex'))
@@ -478,6 +473,15 @@ class InvoiceStore(object):
except:
continue
def import_file(self, path):
try:
with open(path, 'r') as f:
d = json.loads(f.read())
self.load(d)
except:
return
self.save()
def save(self):
l = {}
for k, pr in self.invoices.items():
@@ -486,10 +490,7 @@ class InvoiceStore(object):
'requestor': pr.requestor,
'txid': pr.tx
}
path = os.path.join(self.config.path, 'invoices')
with open(path, 'w') as f:
s = json.dumps(l, indent=4, sort_keys=True)
r = f.write(s)
self.storage.put('invoices', l)
def get_status(self, key):
pr = self.get(key)