migrate double hex encoded certificates

This commit is contained in:
Jack Robison 2018-11-30 12:46:53 -05:00
parent c34b150794
commit 4826eb9969
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -1,5 +1,6 @@
import json
import logging
import binascii
from lbrynet.schema.validator import validate_claim_id
from torba.client.baseaccount import BaseAccount
@ -43,6 +44,30 @@ class Account(BaseAccount):
'previous-success': 0,
'previous-corrupted': 0
}
double_hex_encoded_to_pop = []
for maybe_claim_id in list(self.certificates):
if ':' not in maybe_claim_id:
try:
validate_claim_id(maybe_claim_id)
continue
except Exception:
try:
maybe_claim_id_bytes = maybe_claim_id
if isinstance(maybe_claim_id_bytes, str):
maybe_claim_id_bytes = maybe_claim_id_bytes.encode()
decoded_double_hex = binascii.unhexlify(maybe_claim_id_bytes).decode()
validate_claim_id(decoded_double_hex)
if decoded_double_hex in self.certificates:
log.warning("don't know how to migrate certificate %s", decoded_double_hex)
else:
log.info("claim id was double hex encoded, fixing it")
double_hex_encoded_to_pop.append((maybe_claim_id, decoded_double_hex))
except Exception:
continue
for double_encoded_claim_id, correct_claim_id in double_hex_encoded_to_pop:
self.certificates[correct_claim_id] = self.certificates.pop(double_encoded_claim_id)
for maybe_claim_id in list(self.certificates):
results['total'] += 1