diff --git a/lbry/lbry/wallet/server/db/reader.py b/lbry/lbry/wallet/server/db/reader.py index 9aa55e08d..e5d54de34 100644 --- a/lbry/lbry/wallet/server/db/reader.py +++ b/lbry/lbry/wallet/server/db/reader.py @@ -49,7 +49,7 @@ SEARCH_PARAMS = { 'name', 'text', 'claim_id', 'claim_ids', 'txid', 'nout', 'channel', 'channel_ids', 'not_channel_ids', 'public_key_id', 'claim_type', 'stream_types', 'media_types', 'fee_currency', 'has_channel_signature', 'signature_valid', - 'any_tags', 'all_tags', 'not_tags', + 'any_tags', 'all_tags', 'not_tags', 'reposted_claim_id', 'any_locations', 'all_locations', 'not_locations', 'any_languages', 'all_languages', 'not_languages', 'is_controlling', 'limit', 'offset', 'order_by', @@ -230,6 +230,9 @@ def _get_claims(cols, for_count=False, **constraints) -> Tuple[str, Dict]: elif 'claim_ids' in constraints: constraints['claim.claim_id__in'] = constraints.pop('claim_ids') + if 'reposted_claim_id' in constraints: + constraints['claim.reposted_claim_hash'] = sqlite3.Binary(unhexlify(constraints.pop('reposted_claim_id'))[::-1]) + if 'name' in constraints: constraints['claim.normalized'] = normalize_name(constraints.pop('name')) @@ -366,7 +369,7 @@ def _search(**constraints): claim.effective_amount, claim.support_amount, claim.trending_group, claim.trending_mixed, claim.trending_local, claim.trending_global, - claim.short_url, claim.canonical_url, + claim.short_url, claim.canonical_url, claim.reposted_claim_hash, claim.channel_hash, channel.txo_hash AS channel_txo_hash, channel.height AS channel_height, claim.signature_valid """, **constraints diff --git a/lbry/lbry/wallet/server/db/writer.py b/lbry/lbry/wallet/server/db/writer.py index ad9d1382c..aa46a9de6 100644 --- a/lbry/lbry/wallet/server/db/writer.py +++ b/lbry/lbry/wallet/server/db/writer.py @@ -62,6 +62,9 @@ class SQLDB: fee_amount integer default 0, fee_currency text, + -- reposts + reposted_claim_hash bytes, + -- claims which are channels public_key_bytes bytes, public_key_hash bytes, @@ -248,6 +251,7 @@ class SQLDB: 'release_time': None, 'fee_currency': None, 'fee_amount': 0, + 'reposted_claim_hash': None } claims.append(claim_record) @@ -272,6 +276,8 @@ class SQLDB: claim_record['fee_currency'] = fee.currency.lower() if isinstance(fee.amount, Decimal): claim_record['fee_amount'] = int(fee.amount*1000) + elif claim.is_repost: + claim_record['reposted_claim_hash'] = claim.repost.reference.claim_hash elif claim.is_channel: claim_record['claim_type'] = CLAIM_TYPES['channel'] @@ -295,12 +301,12 @@ class SQLDB: 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, - fee_currency, fee_amount, title, description, author, height, + fee_currency, fee_amount, title, description, author, 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, - :fee_currency, :fee_amount, :title, :description, :author, :height, :height, + :fee_currency, :fee_amount, :title, :description, :author, :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, CASE WHEN :height >= 137181 THEN :height+2102400 ELSE :height+262974 END, @@ -318,7 +324,7 @@ class SQLDB: 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, - title=:title, description=:description, author=:author, + title=:title, 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; """, claims) diff --git a/lbry/tests/integration/test_claim_commands.py b/lbry/tests/integration/test_claim_commands.py index f08d0929d..8da6de500 100644 --- a/lbry/tests/integration/test_claim_commands.py +++ b/lbry/tests/integration/test_claim_commands.py @@ -745,7 +745,10 @@ class StreamCommands(ClaimTestCase): # complex case, reverse search (reposts for claim id) reposts = await self.claim_search(reposted_claim_id=claim_id) self.assertEqual(len(reposts), 2) - self.assertEqual(reposts, reposts_on_claim_list) + self.assertSetEqual( + {repost['claim_id'] for repost in reposts}, + {claim['claim_id'] for claim in reposts_on_claim_list} + ) # check that it resolves fine too # todo: should resolve show the repost information? resolved_reposts = await self.resolve(['@reposting-goodies/repost-on-channel', 'newstuff-again'])