From d06a0f876ae3a4b55c2df1d2770c9e568f5409cf Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Fri, 24 May 2019 12:12:27 -0400 Subject: [PATCH] Patches comment server interface in the SDK --- lbrynet/extras/daemon/Daemon.py | 57 +++++++++++++++------------------ 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index 7e7e3a5b3..6275c5175 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -3350,27 +3350,20 @@ class Daemon(metaclass=JSONRPCServerType): retrieve in one request Returns: - (dict) Containing the list, and information about the paginated content: - { - "page": "Page number of the current items.", - "page_size": "Number of items to show on a page.", - "total_pages": "Total number of pages.", - "total_items": "Total number of items.", - "items": "A List of dict objects representing comments." - [ - { - "comment": (str) The actual string as inputted by the user, - "comment_id": (str) The Comment's unique identifier, - "channel_name": (str) Name of the channel this was posted under, prepended with a '@', - "channel_id": (str) The Channel Claim ID that this comment was posted under, - "signature": (str) The signature of the comment, - "channel_url": (str) Channel's URI in the ClaimTrie, - "parent_id": (str) Comment this is replying to, (None) if this is the root, - "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds. - }, - ... - ] - } + (list) Containing comments stored as dictionary objects: + [ + { + "comment": (str) The actual string as inputted by the user, + "comment_id": (str) The Comment's unique identifier, + "channel_name": (str) Name of the channel this was posted under, prepended with a '@', + "channel_id": (str) The Channel Claim ID that this comeent was posted under, + "signature": (str) The signature of the comment, + "channel_uri": (str) Channel's URI in the ClaimTrie, + "parent_id": (str) Comment this is replying to, (None) if this is the root, + "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds. + }, + ... + ] """ return await jsonrpc_post( self.conf.comment_server, @@ -3395,8 +3388,6 @@ class Daemon(metaclass=JSONRPCServerType): [--parent_id=] Options: - --comment= : (str) Comment to be made, should be at most 2000 characters. - --claim_id= : (str) The ID of the claim on which the comment should be made on --parent_id= : (str) The ID of a comment to make a response to --channel_id= : (str) The ID of the channel you want to post under --channel_name= : (str) The channel you want to post as, prepend with a '@' @@ -3410,21 +3401,17 @@ class Daemon(metaclass=JSONRPCServerType): "channel_name": (str) Name of the channel this was posted under, prepended with a '@', "channel_id": (str) The Channel Claim ID that this comeent was posted under, "signature": (str) The signature of the comment, - "channel_url": (str) Channel's URI in the ClaimTrie, + "channel_uri": (str) Channel's URI in the ClaimTrie, "parent_id": (str) Comment this is replying to, (None) if this is the root, "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds. } """ if bool(channel_name) ^ bool(channel_id): + skey, sval = ('claim_id', channel_id) if channel_id else ('normalized', channel_name.lower()) + channel_list = await self.jsonrpc_channel_list() try: - channel_list = await self.jsonrpc_channel_list() - if channel_name: - channel_name = channel_name.lower() - channel: Output = [chan for chan in channel_list if chan.normalized_name == channel_name].pop() - channel_id = channel.claim_id - else: - channel: Output = [chan for chan in channel_list if chan.claim_id == channel_id].pop() - channel_name = channel.normalized_name + channel: dict = [chan for chan in channel_list if chan[skey] == sval].pop() + channel_name, channel_id = channel['normalized'], channel['claim_id'] except IndexError: raise ValueError('You must enter a valid channel_%s' % ('id' if channel_id else 'name')) signature = None @@ -3445,6 +3432,12 @@ class Daemon(metaclass=JSONRPCServerType): } return await jsonrpc_post(self.conf.comment_server, 'create_comment', **comment) + def valid_address_or_error(self, address): + try: + assert self.ledger.is_valid_address(address) + except: + raise Exception(f"'{address}' is not a valid address") + @staticmethod def valid_stream_name_or_error(name: str): try: