From 0a0ac3b7c9611bac257f8a76234a6f779fdf178d Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Tue, 13 Oct 2020 15:51:59 -0400 Subject: [PATCH] pass-through for new support_sum api --- .gitignore | 3 ++- lbry/extras/daemon/daemon.py | 33 +++++++++++++++++++++++++++++++++ lbry/wallet/ledger.py | 3 +++ lbry/wallet/network.py | 6 ++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ed178a1ed..e72269ce1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /.coverage* /lbry-venv /venv +/lbry/blockchain lbry.egg-info __pycache__ @@ -17,4 +18,4 @@ _trial_temp/ /lbry/wallet/bin /.vscode -/.gitignore \ No newline at end of file +/.gitignore diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index ae6b42383..ed6018e18 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -2295,6 +2295,39 @@ class Daemon(metaclass=JSONRPCServerType): kwargs['is_not_spent'] = True return self.jsonrpc_txo_list(**kwargs) + async def jsonrpc_support_sum(self, claim_id, new_sdk_server, include_channel_content=False, **kwargs): + """ + List total staked supports for a claim, grouped by the channel that signed the support. ++ ++ If claim_id is a channel claim, you can use --include_channel_content to also include supports for ++ content claims in the channel. + + !!!! NOTE: PAGINATION DOES NOT DO ANYTHING AT THE MOMENT !!!!! + + Usage: + support_sum + [--include_channel_content] + [--page=] [--page_size=] + + Options: + --claim_id= : (str) claim id + --new_sdk_server= : (str) URL of the new SDK server (EXPERIMENTAL) + --include_channel_content : (bool) if claim_id is for a channel, include supports for claims in + that channel + --page= : (int) page to return during paginating + --page_size= : (int) number of items on page during pagination + + Returns: {Paginated[Dict]} + """ + 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}) + support_sums = await self.ledger.sum_supports(new_sdk_server, claim_id=claim_id, include_channel_content=include_channel_content, **kwargs) + return { + "items": support_sums, + "page": page_num, + "page_size": page_size + } + @requires(WALLET_COMPONENT) async def jsonrpc_claim_search(self, **kwargs): """ diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py index 86e3619c3..ed0d954a4 100644 --- a/lbry/wallet/ledger.py +++ b/lbry/wallet/ledger.py @@ -945,6 +945,9 @@ class Ledger(metaclass=LedgerRegistry): result[url] = txo return result + async def sum_supports(self, new_sdk_server, **kwargs) -> List[Dict]: + return await self.network.sum_supports(new_sdk_server, **kwargs) + async def claim_search( self, accounts, include_purchase_receipt=False, include_is_my_output=False, new_sdk_server=None, **kwargs) -> Tuple[List[Output], dict, int, int]: diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py index 76d079895..e3e396e83 100644 --- a/lbry/wallet/network.py +++ b/lbry/wallet/network.py @@ -335,6 +335,12 @@ class Network: result = await r.json() return result['result'] + async def sum_supports(self, server, **kwargs): + message = {"method": "support_sum", "params": kwargs} + async with self.aiohttp_session.post(server, json=message) as r: + result = await r.json() + return result['result'] + class SessionPool: