mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
Merge pull request #2669 from neocogent/contacts-validate
Validate and extract contacts on import
This commit is contained in:
commit
f956363d88
1 changed files with 13 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue