From 74df4fab8327ec97c61e1acde34d7c9753431fe2 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 12 Mar 2021 18:23:54 -0300 Subject: [PATCH] change column to has_source and document both flags --- lbry/extras/daemon/daemon.py | 5 +++++ lbry/wallet/server/db/reader.py | 2 +- lbry/wallet/server/db/writer.py | 12 ++++++------ tests/integration/blockchain/test_claim_commands.py | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index ad5cf60ed..e1fd4380e 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -2330,6 +2330,7 @@ class Daemon(metaclass=JSONRPCServerType): [--not_locations=...] [--order_by=...] [--no_totals] [--page=] [--page_size=] [--wallet_id=] [--include_purchase_receipt] [--include_is_my_output] + [--has_source | --has_no_source] [--new_sdk_server=] Options: @@ -2438,6 +2439,8 @@ class Daemon(metaclass=JSONRPCServerType): has purchased the claim --include_is_my_output : (bool) lookup and include a boolean indicating if claim being resolved is yours + --has_source : (bool) find claims containing a source field + --has_no_source : (bool) find claims not containing a source field --new_sdk_server= : (str) URL of the new SDK server (EXPERIMENTAL) Returns: {Paginated[Output]} @@ -2449,6 +2452,8 @@ class Daemon(metaclass=JSONRPCServerType): kwargs['signature_valid'] = 1 if kwargs.pop('invalid_channel_signature', False): kwargs['signature_valid'] = 0 + if 'has_no_source' in kwargs: + kwargs['has_source'] = not kwargs.pop('has_no_source') page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', DEFAULT_PAGE_SIZE)), 50) kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size}) txos, blocked, _, total = await self.ledger.claim_search(wallet.accounts, **kwargs) diff --git a/lbry/wallet/server/db/reader.py b/lbry/wallet/server/db/reader.py index f72f0bc30..92bfbe79c 100644 --- a/lbry/wallet/server/db/reader.py +++ b/lbry/wallet/server/db/reader.py @@ -53,7 +53,7 @@ SEARCH_PARAMS = { 'any_locations', 'all_locations', 'not_locations', 'any_languages', 'all_languages', 'not_languages', 'is_controlling', 'limit', 'offset', 'order_by', - 'no_totals', 'no_source' + 'no_totals', 'has_source' } | INTEGER_PARAMS diff --git a/lbry/wallet/server/db/writer.py b/lbry/wallet/server/db/writer.py index ffeddd1d7..86f9e0c12 100644 --- a/lbry/wallet/server/db/writer.py +++ b/lbry/wallet/server/db/writer.py @@ -55,7 +55,7 @@ class SQLDB: description text, claim_type integer, - no_source bool, + has_source bool, reposted integer default 0, -- streams @@ -355,7 +355,7 @@ class SQLDB: 'author': None, 'duration': None, 'claim_type': None, - 'no_source': False, + 'has_source': False, 'stream_type': None, 'media_type': None, 'release_time': None, @@ -373,7 +373,7 @@ class SQLDB: if claim.is_stream: claim_record['claim_type'] = CLAIM_TYPES['stream'] - claim_record['no_source'] = not claim.stream.has_source + claim_record['has_source'] = claim.stream.has_source claim_record['media_type'] = claim.stream.source.media_type claim_record['stream_type'] = STREAM_TYPES[guess_stream_type(claim_record['media_type'])] claim_record['title'] = claim.stream.title @@ -424,12 +424,12 @@ class SQLDB: self.executemany(""" INSERT OR IGNORE INTO claim ( claim_hash, claim_id, claim_name, normalized, txo_hash, tx_position, amount, - claim_type, media_type, stream_type, timestamp, creation_timestamp, no_source, + claim_type, media_type, stream_type, timestamp, creation_timestamp, has_source, fee_currency, fee_amount, title, description, author, duration, height, reposted_claim_hash, creation_height, release_time, activation_height, expiration_height, short_url) VALUES ( :claim_hash, :claim_id, :claim_name, :normalized, :txo_hash, :tx_position, :amount, - :claim_type, :media_type, :stream_type, :timestamp, :timestamp, :no_source, + :claim_type, :media_type, :stream_type, :timestamp, :timestamp, :has_source, :fee_currency, :fee_amount, :title, :description, :author, :duration, :height, :reposted_claim_hash, :height, CASE WHEN :release_time IS NOT NULL THEN :release_time ELSE :timestamp END, CASE WHEN :normalized NOT IN (SELECT normalized FROM claimtrie) THEN :height END, @@ -447,7 +447,7 @@ class SQLDB: UPDATE claim SET txo_hash=:txo_hash, tx_position=:tx_position, amount=:amount, height=:height, claim_type=:claim_type, media_type=:media_type, stream_type=:stream_type, - timestamp=:timestamp, fee_amount=:fee_amount, fee_currency=:fee_currency, no_source=:no_source, + timestamp=:timestamp, fee_amount=:fee_amount, fee_currency=:fee_currency, has_source=:has_source, title=:title, duration=:duration, description=:description, author=:author, reposted_claim_hash=:reposted_claim_hash, release_time=CASE WHEN :release_time IS NOT NULL THEN :release_time ELSE release_time END WHERE claim_hash=:claim_hash; diff --git a/tests/integration/blockchain/test_claim_commands.py b/tests/integration/blockchain/test_claim_commands.py index 9d9da30f4..ac6709729 100644 --- a/tests/integration/blockchain/test_claim_commands.py +++ b/tests/integration/blockchain/test_claim_commands.py @@ -162,8 +162,9 @@ class ClaimSearchCommand(ClaimTestCase): # no source no_source = await self.stream_create('no_source', data=None) normal = await self.stream_create('normal', data=b'normal') - await self.assertFindsClaims([no_source], no_source=True) - await self.assertFindsClaims([normal], no_source=False) + await self.assertFindsClaims([no_source], has_no_source=True) + await self.assertFindsClaims([normal], has_source=True) + await self.assertFindsClaims([normal, no_source]) async def test_pagination(self): await self.create_channel()