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

View file

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