From e79f8d58ca03c7fddd442ddfa31bfa3250b3e181 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 12 Nov 2019 14:23:11 -0500 Subject: [PATCH] expose bt_infohash in Claim --- lbry/lbry/schema/attrs.py | 16 ++++++++++++++++ lbry/lbry/schema/claim.py | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/lbry/lbry/schema/attrs.py b/lbry/lbry/schema/attrs.py index 7586a7039..eed77505f 100644 --- a/lbry/lbry/schema/attrs.py +++ b/lbry/lbry/schema/attrs.py @@ -191,6 +191,22 @@ class Source(Metadata): def sd_hash_bytes(self, sd_hash: bytes): self.message.sd_hash = sd_hash + @property + def bt_infohash(self) -> str: + return hexlify(self.message.bt_infohash).decode() + + @bt_infohash.setter + def bt_infohash(self, bt_infohash: str): + self.message.bt_infohash = unhexlify(bt_infohash.encode()) + + @property + def bt_infohash_bytes(self) -> bytes: + return self.message.bt_infohash.decode() + + @bt_infohash_bytes.setter + def bt_infohash_bytes(self, bt_infohash: bytes): + self.message.bt_infohash = bt_infohash + @property def url(self) -> str: return self.message.url diff --git a/lbry/lbry/schema/claim.py b/lbry/lbry/schema/claim.py index 7150a547a..d845b4658 100644 --- a/lbry/lbry/schema/claim.py +++ b/lbry/lbry/schema/claim.py @@ -195,6 +195,8 @@ class Stream(BaseClaim): claim['source']['hash'] = self.source.file_hash if 'sd_hash' in claim['source']: claim['source']['sd_hash'] = self.source.sd_hash + elif 'bt_infohash' in claim['source']: + claim['source']['bt_infohash'] = self.source.bt_infohash if 'media_type' in claim['source']: claim['stream_type'] = guess_stream_type(claim['source']['media_type']) fee = claim.get('fee', {}) @@ -216,6 +218,8 @@ class Stream(BaseClaim): if 'sd_hash' in kwargs: self.source.sd_hash = kwargs.pop('sd_hash') + elif 'bt_infohash' in kwargs: + self.source.bt_infohash = kwargs.pop('bt_infohash') if 'file_name' in kwargs: self.source.name = kwargs.pop('file_name') if 'file_hash' in kwargs: