validate claim id before resolving

This commit is contained in:
Victor Shyba 2018-11-25 18:42:25 -03:00 committed by Lex Berezhny
parent 0a765e6207
commit 8f826098f9
2 changed files with 13 additions and 6 deletions

View file

@ -2,6 +2,7 @@ import asyncio
import logging
from binascii import unhexlify
from lbrynet.schema.validator import validate_claim_id
from torba.client.baseledger import BaseLedger
from lbrynet.schema.error import URIParseError
from lbrynet.schema.uri import parse_lbry_uri
@ -56,13 +57,18 @@ class MainNetLedger(BaseLedger):
async def resolve(self, page, page_size, *uris):
for uri in uris:
try:
parse_lbry_uri(uri)
resolutions = await self.network.get_values_for_uris(self.headers.hash().decode(), *uris)
parsed_uri = parse_lbry_uri(uri)
if parsed_uri.claim_id:
validate_claim_id(parsed_uri.claim_id)
except URIParseError as err:
return {'error': err.args[0]}
except Exception as e:
return {'error': str(e)}
return await self.resolver._handle_resolutions(resolutions, uris, page, page_size)
try:
resolutions = await self.network.get_values_for_uris(self.headers.hash().decode(), *uris)
return await self.resolver._handle_resolutions(resolutions, uris, page, page_size)
except Exception as e:
return {'error': str(e)}
async def get_claim_by_claim_id(self, claim_id):
result = (await self.network.get_claims_by_ids(claim_id)).pop(claim_id, {})

View file

@ -272,9 +272,10 @@ class LbryWalletManager(BaseWalletManager):
check_cache = kwargs.get('check_cache', False) # TODO: put caching back (was force_refresh parameter)
ledger: MainNetLedger = self.default_account.ledger
results = await ledger.resolve(page, page_size, *uris)
await self.old_db.save_claims_for_resolve(
(value for value in results.values() if 'error' not in value)
).asFuture(asyncio.get_event_loop())
if 'error' not in results:
await self.old_db.save_claims_for_resolve(
(value for value in results.values() if 'error' not in value)
).asFuture(asyncio.get_event_loop())
return results
def get_claims_for_name(self, name: str):