diff --git a/lbry/db/queries/resolve.py b/lbry/db/queries/resolve.py index 5139f18ea..9b4f36c4b 100644 --- a/lbry/db/queries/resolve.py +++ b/lbry/db/queries/resolve.py @@ -1,6 +1,5 @@ import logging import itertools -from operator import itemgetter from typing import List, Dict from lbry.schema.url import URL @@ -15,29 +14,37 @@ from .search import search_claims log = logging.getLogger(__name__) -def _get_referenced_rows(txo_rows: List[dict], censor_channels: List[bytes]): +def _get_referenced_rows(txo_rows: List[Output], censor_channels: List[bytes]): # censor = context().get_resolve_censor() - repost_hashes = set(filter(None, map(itemgetter('reposted_claim_hash'), txo_rows))) + repost_hashes = set(txo.reposted_claim.claim_hash for txo in txo_rows if txo.reposted_claim) channel_hashes = set(itertools.chain( - filter(None, map(itemgetter('channel_hash'), txo_rows)), + (txo.channel.claim_hash for txo in txo_rows if txo.channel), censor_channels )) reposted_txos = [] if repost_hashes: reposted_txos = search_claims(**{'claim.claim_hash__in': repost_hashes}) - channel_hashes |= set(filter(None, map(itemgetter('channel_hash'), reposted_txos))) + if reposted_txos: + reposted_txos = reposted_txos[0] + channel_hashes |= set(txo.channel.claim_hash for txo in reposted_txos if txo.channel) channel_txos = [] if channel_hashes: channel_txos = search_claims(**{'claim.claim_hash__in': channel_hashes}) + channel_txos = channel_txos[0] if channel_txos else [] # channels must come first for client side inflation to work properly return channel_txos + reposted_txos def protobuf_resolve(urls, **kwargs) -> str: - return ResultOutput.to_base64([resolve_url(raw_url) for raw_url in urls], []) + txo_rows = [resolve_url(raw_url) for raw_url in urls] + extra_txo_rows = _get_referenced_rows( + txo_rows, + [txo.censor_hash for txo in txo_rows if isinstance(txo, ResolveCensoredError)] + ) + return ResultOutput.to_base64(txo_rows, extra_txo_rows) def resolve(urls, **kwargs) -> Dict[str, Output]: @@ -86,7 +93,10 @@ def resolve_url(raw_url): # matches = search_claims(censor, **q, limit=1) matches = search_claims(**q, limit=1)[0] if matches: - return matches[0] + stream = matches[0] + if channel: + stream.channel = channel + return stream elif censor.censored: return ResolveCensoredError(raw_url, next(iter(censor.censored))) else: diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 2a8ffcdcc..ebdd404a2 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -206,5 +206,10 @@ class Outputs: #txo_message.claim.trending_mixed = txo['trending_mixed'] #txo_message.claim.trending_local = txo['trending_local'] #txo_message.claim.trending_global = txo['trending_global'] - #set_reference(txo_message.claim.channel, txo['channel_hash'], extra_txo_rows) + if txo.channel: + reference = txo_message.claim.channel + hash = txo.channel.hash + reference.tx_hash = hash[:32] + reference.nout = struct.unpack('