diff --git a/lbry/db/database.py b/lbry/db/database.py index c65668aab..b989f00bc 100644 --- a/lbry/db/database.py +++ b/lbry/db/database.py @@ -312,6 +312,17 @@ class Database: return await self.fetch_result(q.get_purchases, **constraints) async def search_claims(self, **constraints) -> Result[Output]: + if 'channel' in constraints: + channel_url = constraints.pop('channel') + match = await self.resolve([channel_url]) + if isinstance(match, dict): + for value in match.values(): + if isinstance(value, Output): + constraints['channel_hash'] = value.claim_hash + else: + return Result([], 0) + else: + return Result([], 0) #assert set(constraints).issubset(SEARCH_PARAMS), \ # f"Search query contains invalid arguments: {set(constraints).difference(SEARCH_PARAMS)}" claims, total, censor = await self.run(q.search_claims, **constraints) diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index 28e88956a..019ed3c1a 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -1127,6 +1127,17 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase): self.assertEqual("@Chá#a/Hortelã#c", claim.canonical_url) self.assertEqual("Hortelã#c", claim.short_url) + async def test_claim_search_filters(self): + chan1 = await self.get_claim(await self.create_claim(is_channel=True, name="@one")) + chan2 = await self.get_claim(await self.create_claim(is_channel=True, name="@two")) + claim1 = await self.get_claim(await self.create_claim(sign=chan1)) + await self.get_claim(await self.create_claim(sign=chan2)) + await self.generate(1) + results = await self.db.search_claims(channel="@one") + self.assertEqual([claim1.claim_id], [result.claim_id for result in results]) + results = await self.db.search_claims(channel="@404") + self.assertEqual([], results.rows) + class TestClaimtrieSync(SyncingBlockchainTestCase):