added support_search to api

This commit is contained in:
Lex Berezhny 2020-08-10 18:37:21 -04:00
parent 51a0f7ddc8
commit 23723f8041
4 changed files with 62 additions and 1 deletions

View file

@ -41,7 +41,7 @@ def select_supports(cols: List = None, **constraints) -> Select:
def search_supports(**constraints) -> Tuple[List[Output], Optional[int]]: def search_supports(**constraints) -> Tuple[List[Output], Optional[int]]:
total = None total = None
if not constraints.pop('no_totals', False): if constraints.pop('include_total', False):
total = search_support_count(**constraints) total = search_support_count(**constraints)
rows = context().fetchall(select_supports(**constraints)) rows = context().fetchall(select_supports(**constraints))
txos = rows_to_txos(rows, include_tx=False) txos = rows_to_txos(rows, include_tx=False)

View file

@ -367,6 +367,18 @@ def txo_filter_kwargs(
pass pass
@expander
def support_filter_kwargs(
claim_id: StrOrList = None, # full claim id
txid: str = None, # transaction id
nout: int = None, # position in the transaction
height: int = None, # last updated block height (supports equality constraints)
timestamp: int = None, # last updated timestamp (supports equality constraints)
amount: str = None, # claim amount (supports equality constraints)
):
pass
class API: class API:
def __init__(self, service: Service): def __init__(self, service: Service):
@ -2514,6 +2526,49 @@ class API:
kwargs['is_my_output'] = True kwargs['is_my_output'] = True
return await self.txo_list(*args, **kwargs) return await self.txo_list(*args, **kwargs)
async def support_search(
self,
wallet_id: str = None, # wallet to check if support is owned by user
order_by: StrOrList = None, # field to order by
**support_filter_and_pagination_kwargs
) -> Paginated[Output]: # search results
"""
Search for supports on the blockchain.
Arguments marked with "supports equality constraints" allow prepending the
value with an equality constraint such as '>', '>=', '<' and '<='
eg. --height=">400000" would limit results to only supports above 400k block height.
Usage:
support search [--wallet_id=<wallet_id>] [--order_by=<order_by>...]
{kwargs}
"""
support_filter_dict, kwargs = pop_kwargs('support_filter', support_filter_kwargs(
**support_filter_and_pagination_kwargs
))
pagination, kwargs = pop_kwargs('pagination', pagination_kwargs(**kwargs))
wallet = self.wallets.get_or_default(wallet_id)
page_num = abs(pagination['page'] or 1)
page_size = min(abs(pagination['page_size'] or DEFAULT_PAGE_SIZE), 50)
support_filter_dict.update({
'offset': page_size * (page_num - 1), 'limit': page_size,
'include_total': pagination['include_total'],
'order_by': order_by
})
result = await self.service.search_supports(
wallet.accounts, **remove_nulls(support_filter_dict)
)
d = {
"items": result.rows,
"page": page_num,
"page_size": page_size
}
if pagination['include_total']:
d['total_pages'] = int((result.total + (page_size - 1)) / page_size)
d['total_items'] = result.total
return d
async def support_abandon( async def support_abandon(
self, self,
keep: str = None, # amount of lbc to keep as support keep: str = None, # amount of lbc to keep as support

View file

@ -194,6 +194,9 @@ class Service:
async def search_claims(self, accounts, **kwargs) -> Tuple[List[Output], Optional[int], Censor]: async def search_claims(self, accounts, **kwargs) -> Tuple[List[Output], Optional[int], Censor]:
raise NotImplementedError raise NotImplementedError
async def search_supports(self, accounts, **kwargs) -> Tuple[List[Output], Optional[int]]:
raise NotImplementedError
async def get_claim_by_claim_id(self, accounts, claim_id, **kwargs) -> Output: async def get_claim_by_claim_id(self, accounts, claim_id, **kwargs) -> Output:
for claim in (await self.search_claims(accounts, claim_id=claim_id, **kwargs))[0]: for claim in (await self.search_claims(accounts, claim_id=claim_id, **kwargs))[0]:
return claim return claim

View file

@ -57,6 +57,9 @@ class FullNode(Service):
async def protobuf_search_claims(self, **kwargs): async def protobuf_search_claims(self, **kwargs):
return await self.db.protobuf_search_claims(**kwargs) return await self.db.protobuf_search_claims(**kwargs)
async def search_supports(self, accounts, **kwargs):
return await self.db.search_supports(**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)