diff --git a/lbry/extras/daemon/comment_client.py b/lbry/extras/daemon/comment_client.py index 0efbdf105..434e41f75 100644 --- a/lbry/extras/daemon/comment_client.py +++ b/lbry/extras/daemon/comment_client.py @@ -22,10 +22,10 @@ def cid2hash(claim_id: str) -> bytes: return binascii.unhexlify(claim_id.encode())[::-1] -def is_comment_signed_by_channel(comment: dict, channel: Output, abandon=False): +def is_comment_signed_by_channel(comment: dict, channel: Output, sign_comment_id=False): if isinstance(channel, Output): try: - signing_field = comment['comment_id'] if abandon else comment['comment'] + signing_field = comment['comment_id'] if sign_comment_id else comment['comment'] pieces = [ comment['signing_ts'].encode(), cid2hash(comment['channel_id']), @@ -41,9 +41,9 @@ def is_comment_signed_by_channel(comment: dict, channel: Output, abandon=False): return False -def sign_comment(comment: dict, channel: Output, abandon=False): +def sign_comment(comment: dict, channel: Output, sign_comment_id=False): timestamp = str(int(time.time())) - signing_field = comment['comment_id'] if abandon else comment['comment'] + signing_field = comment['comment_id'] if sign_comment_id else comment['comment'] pieces = [timestamp.encode(), channel.claim_hash, signing_field.encode()] digest = sha256(b''.join(pieces)) signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256) diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 8da6812b7..ae6b42383 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -5110,8 +5110,10 @@ class Daemon(metaclass=JSONRPCServerType): { "comment": (str) The actual string as inputted by the user, "comment_id": (str) The Comment's unique identifier, + "claim_id": (str) The claim commented on, "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, + "is_pinned": (boolean) Channel owner has pinned this comment, "signature": (str) The signature of the comment, "signing_ts": (str) The timestamp used to sign the comment, "channel_url": (str) Channel's URI in the ClaimTrie, @@ -5159,11 +5161,13 @@ class Daemon(metaclass=JSONRPCServerType): { "comment": (str) The actual string as inputted by the user, "comment_id": (str) The Comment's unique identifier, + "claim_id": (str) The claim commented on, "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, "signing_ts": (str) Timestamp used to sign the most recent signature, "channel_url": (str) Channel's URI in the ClaimTrie, + "is_pinned": (boolean) Channel owner has pinned this comment, "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. } @@ -5222,7 +5226,7 @@ class Daemon(metaclass=JSONRPCServerType): 'channel_id': channel.claim_id, 'channel_name': channel.claim_name, }) - comment_client.sign_comment(abandon_comment_body, channel, abandon=True) + comment_client.sign_comment(abandon_comment_body, channel, sign_comment_id=True) return await comment_client.jsonrpc_post(self.conf.comment_server, 'comment.Abandon', abandon_comment_body) @requires(WALLET_COMPONENT) @@ -5267,10 +5271,51 @@ class Daemon(metaclass=JSONRPCServerType): for_signing=True ) piece = {'comment_id': comment['comment_id']} - comment_client.sign_comment(piece, channel, abandon=True) + comment_client.sign_comment(piece, channel, sign_comment_id=True) pieces.append(piece) return await comment_client.jsonrpc_post(self.conf.comment_server, 'comment.Hide', pieces=pieces) + @requires(WALLET_COMPONENT) + async def jsonrpc_comment_pin(self, comment_id=None, channel_id=None, channel_name=None, + channel_account_id=None, remove=False, wallet_id=None): + """ + Pin a comment published to a claim you control. + + Usage: + comment_pin ( | --comment_id=) + (--channel_id=) + (--channel_name=) + [--remove] + [--channel_account_id=...] [--wallet_id=] + + Options: + --comment_id= : (str) Hash identifying the comment to pin + --channel_id= : (str) The ID of channel owning the commented claim + --channel_name= : (str) The name of channel owning the commented claim + --remove : (bool) remove the pin + --channel_account_id= : (str) one or more account ids for accounts to look in + --wallet_id=