protobuf claim_search

This commit is contained in:
Lex Berezhny 2020-08-04 13:49:59 -04:00
parent 0b245aab31
commit 84639cfb2e
4 changed files with 41 additions and 19 deletions

View file

@ -273,6 +273,9 @@ class Database:
claims, total, censor = await self.run(q.search_claims, **constraints) claims, total, censor = await self.run(q.search_claims, **constraints)
return Result(claims, total, censor) return Result(claims, total, censor)
async def protobuf_search_claims(self, **constraints) -> str:
return await self.run(q.protobuf_search_claims, **constraints)
async def search_supports(self, **constraints) -> Result[Output]: async def search_supports(self, **constraints) -> Result[Output]:
return await self.fetch_result(q.search_supports, **constraints) return await self.fetch_result(q.search_supports, **constraints)

View file

@ -8,7 +8,7 @@ from sqlalchemy import func, case
from sqlalchemy.future import select, Select from sqlalchemy.future import select, Select
from lbry.schema.tags import clean_tags from lbry.schema.tags import clean_tags
from lbry.schema.result import Censor from lbry.schema.result import Censor, Outputs as ResultOutput
from lbry.schema.url import normalize_name from lbry.schema.url import normalize_name
from lbry.blockchain.transaction import Output from lbry.blockchain.transaction import Output
@ -219,6 +219,11 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select:
) )
def protobuf_search_claims(**constraints) -> str:
txos, _, censor = search_claims(**constraints)
return ResultOutput.to_base64(txos, [], blocked=censor)
def search_claims(**constraints) -> Tuple[List[Output], Optional[int], Optional[Censor]]: def search_claims(**constraints) -> Tuple[List[Output], Optional[int], Optional[Censor]]:
total = None total = None
if not constraints.pop('no_totals', False): if not constraints.pop('no_totals', False):

View file

@ -1590,6 +1590,7 @@ class API:
# 'height', 'release_time', 'publish_time', 'amount', 'effective_amount', # 'height', 'release_time', 'publish_time', 'amount', 'effective_amount',
# 'support_amount', 'trending_group', 'trending_mixed', 'trending_local', # 'support_amount', 'trending_group', 'trending_mixed', 'trending_local',
# 'trending_global', 'activation_height' # 'trending_global', 'activation_height'
protobuf=False, # protobuf encoded result
**claim_filter_and_signed_filter_and_stream_filter_and_pagination_kwargs **claim_filter_and_signed_filter_and_stream_filter_and_pagination_kwargs
) -> Paginated[Output]: # search results ) -> Paginated[Output]: # search results
""" """
@ -1611,29 +1612,39 @@ class API:
[--reposted_claim_id=<reposted_claim_id>] [--reposted=<reposted>] [--reposted_claim_id=<reposted_claim_id>] [--reposted=<reposted>]
[--claim_type=<claim_type>] [--order_by=<order_by>...] [--claim_type=<claim_type>] [--order_by=<order_by>...]
[--wallet_id=<wallet_id>] [--include_purchase_receipt] [--include_is_my_output] [--wallet_id=<wallet_id>] [--include_purchase_receipt] [--include_is_my_output]
[--protobuf]
{kwargs} {kwargs}
""" """
wallet = self.wallets.get_or_default(kwargs.pop('wallet_id', None)) claim_filter_dict, kwargs = pop_kwargs('claim_filter', claim_filter_kwargs(
if {'claim_id', 'claim_ids'}.issubset(kwargs): **claim_filter_and_signed_filter_and_stream_filter_and_pagination_kwargs
raise ValueError("Only 'claim_id' or 'claim_ids' is allowed, not both.") ))
if kwargs.pop('valid_channel_signature', False): pagination, kwargs = pop_kwargs('pagination', pagination_kwargs(**kwargs))
kwargs['signature_valid'] = 1 wallet = self.wallets.get_or_default(wallet_id)
if kwargs.pop('invalid_channel_signature', False): # if {'claim_id', 'claim_ids'}.issubset(kwargs):
kwargs['signature_valid'] = 0 # raise ValueError("Only 'claim_id' or 'claim_ids' is allowed, not both.")
page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', DEFAULT_PAGE_SIZE)), 50) # if kwargs.pop('valid_channel_signature', False):
kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size}) # kwargs['signature_valid'] = 1
txos, total, censored = await self.service.search_claims(wallet.accounts, **kwargs) # if kwargs.pop('invalid_channel_signature', False):
result = { # kwargs['signature_valid'] = 0
"items": txos, page_num = abs(pagination['page'] or 1)
page_size = min(abs(pagination['page_size'] or DEFAULT_PAGE_SIZE), 50)
claim_filter_dict.update({'offset': page_size * (page_num - 1), 'limit': page_size})
if protobuf:
return await self.service.protobuf_search_claims(**remove_nulls(claim_filter_dict))
result = await self.service.search_claims(
wallet.accounts, **remove_nulls(claim_filter_dict)
)
d = {
"items": result.rows,
#"blocked": censored, #"blocked": censored,
"page": page_num, "page": page_num,
"page_size": page_size "page_size": page_size
} }
if not kwargs.pop('no_totals', False): if not kwargs.pop('no_totals', False):
result['total_pages'] = int((total + (page_size - 1)) / page_size) d['total_pages'] = int((result.total + (page_size - 1)) / page_size)
result['total_items'] = total d['total_items'] = result.total
return result return d
CHANNEL_DOC = """ CHANNEL_DOC = """
Create, update, abandon and list your channel claims. Create, update, abandon and list your channel claims.

View file

@ -45,15 +45,18 @@ class FullNode(Service):
for tx in await self.db.get_transactions(tx_hashes=tx_hashes) for tx in await self.db.get_transactions(tx_hashes=tx_hashes)
} }
async def search_claims(self, accounts, **kwargs):
return await self.db.search_claims(**kwargs)
async def broadcast(self, tx): async def broadcast(self, tx):
return await self.chain.send_raw_transaction(hexlify(tx.raw).decode()) return await self.chain.send_raw_transaction(hexlify(tx.raw).decode())
async def wait(self, tx: Transaction, height=-1, timeout=1): async def wait(self, tx: Transaction, height=-1, timeout=1):
pass pass
async def search_claims(self, accounts, **kwargs):
return await self.db.search_claims(**kwargs)
async def protobuf_search_claims(self, **kwargs):
return await self.db.protobuf_search_claims(**kwargs)
async def resolve(self, urls, **kwargs): async def resolve(self, urls, **kwargs):
return await self.db.resolve(urls, **kwargs) return await self.db.resolve(urls, **kwargs)