From 6549a4ebdb477c39a1debb718ecba76f6de66584 Mon Sep 17 00:00:00 2001 From: neocogent Date: Tue, 1 Aug 2017 19:56:46 +0700 Subject: [PATCH] validate contacts on import --- lib/contacts.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/contacts.py b/lib/contacts.py index 90b4d9ae..a7cd9727 100644 --- a/lib/contacts.py +++ b/lib/contacts.py @@ -55,7 +55,7 @@ class Contacts(dict): def import_file(self, path): try: with open(path, 'r') as f: - d = json.loads(f.read()) + d = self._validate(json.loads(f.read())) except: return self.update(d) @@ -116,4 +116,16 @@ class Contacts(dict): return regex.search(haystack).groups()[0] except AttributeError: return None + + def _validate(self, data): + for k,v in data.items(): + if k == 'contacts': + return self._validate(v) + if not bitcoin.is_address(k): + data.pop(k) + else: + _type,_ = v + if _type != 'address': + data.pop(k) + return data