From 8f826098f9d446a516cb64de217b3feb373ec09d Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sun, 25 Nov 2018 18:42:25 -0300 Subject: [PATCH] validate claim id before resolving --- lbrynet/extras/wallet/ledger.py | 12 +++++++++--- lbrynet/extras/wallet/manager.py | 7 ++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lbrynet/extras/wallet/ledger.py b/lbrynet/extras/wallet/ledger.py index 48016a9e4..40bbe295e 100644 --- a/lbrynet/extras/wallet/ledger.py +++ b/lbrynet/extras/wallet/ledger.py @@ -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, {}) diff --git a/lbrynet/extras/wallet/manager.py b/lbrynet/extras/wallet/manager.py index d482fe580..da57fa614 100644 --- a/lbrynet/extras/wallet/manager.py +++ b/lbrynet/extras/wallet/manager.py @@ -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):