Patches comment server interface in the SDK

This commit is contained in:
Oleg Silkin 2019-05-24 12:12:27 -04:00 committed by Lex Berezhny
parent 8e857de62a
commit d06a0f876a

View file

@ -3350,27 +3350,20 @@ class Daemon(metaclass=JSONRPCServerType):
retrieve in one request retrieve in one request
Returns: Returns:
(dict) Containing the list, and information about the paginated content: (list) Containing comments stored as dictionary objects:
{ [
"page": "Page number of the current items.", {
"page_size": "Number of items to show on a page.", "comment": (str) The actual string as inputted by the user,
"total_pages": "Total number of pages.", "comment_id": (str) The Comment's unique identifier,
"total_items": "Total number of items.", "channel_name": (str) Name of the channel this was posted under, prepended with a '@',
"items": "A List of dict objects representing comments." "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,
"comment": (str) The actual string as inputted by the user, "parent_id": (str) Comment this is replying to, (None) if this is the root,
"comment_id": (str) The Comment's unique identifier, "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds.
"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.
},
...
]
}
""" """
return await jsonrpc_post( return await jsonrpc_post(
self.conf.comment_server, self.conf.comment_server,
@ -3395,8 +3388,6 @@ class Daemon(metaclass=JSONRPCServerType):
[--parent_id=<parent_id>] [--parent_id=<parent_id>]
Options: Options:
--comment=<comment> : (str) Comment to be made, should be at most 2000 characters.
--claim_id=<claim_id> : (str) The ID of the claim on which the comment should be made on
--parent_id=<parent_id> : (str) The ID of a comment to make a response to --parent_id=<parent_id> : (str) The ID of a comment to make a response to
--channel_id=<channel_id> : (str) The ID of the channel you want to post under --channel_id=<channel_id> : (str) The ID of the channel you want to post under
--channel_name=<channel_name> : (str) The channel you want to post as, prepend with a '@' --channel_name=<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_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, "channel_id": (str) The Channel Claim ID that this comeent was posted under,
"signature": (str) The signature of the comment, "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, "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. "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds.
} }
""" """
if bool(channel_name) ^ bool(channel_id): 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: try:
channel_list = await self.jsonrpc_channel_list() channel: dict = [chan for chan in channel_list if chan[skey] == sval].pop()
if channel_name: channel_name, channel_id = channel['normalized'], channel['claim_id']
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
except IndexError: except IndexError:
raise ValueError('You must enter a valid channel_%s' % ('id' if channel_id else 'name')) raise ValueError('You must enter a valid channel_%s' % ('id' if channel_id else 'name'))
signature = None signature = None
@ -3445,6 +3432,12 @@ class Daemon(metaclass=JSONRPCServerType):
} }
return await jsonrpc_post(self.conf.comment_server, 'create_comment', **comment) 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 @staticmethod
def valid_stream_name_or_error(name: str): def valid_stream_name_or_error(name: str):
try: try: