Skip to content

Commit 3962977

Browse files
committed
Align lbry/schema with hub/schema regarding hex encoding/decoding.
1 parent 76e31b8 commit 3962977

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lbry/schema/attrs.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Tuple, List
77
from string import ascii_letters
88
from decimal import Decimal, ROUND_UP
9-
from binascii import hexlify, unhexlify
109
from google.protobuf.json_format import MessageToDict, ParseDict, ParseError
1110

1211
from lbry.crypto.base58 import Base58
@@ -16,7 +15,7 @@
1615
import lbry.schema.claim as claim
1716
from lbry.schema.mime_types import guess_media_type
1817
from lbry.schema.base import Metadata, BaseMessageList
19-
from lbry.schema.tags import clean_tags, normalize_tag
18+
from lbry.schema.tags import normalize_tag
2019
from google.protobuf.message import Message as ProtobufMessage
2120
from lbry.schema.types.v2.claim_pb2 import (
2221
Claim as ClaimMessage,
@@ -177,11 +176,11 @@ def media_type(self, media_type: str):
177176

178177
@property
179178
def file_hash(self) -> str:
180-
return hexlify(self.message.hash).decode()
179+
return self.message.hash.hex()
181180

182181
@file_hash.setter
183182
def file_hash(self, file_hash: str):
184-
self.message.hash = unhexlify(file_hash.encode())
183+
self.message.hash = bytes.fromhex(file_hash)
185184

186185
@property
187186
def file_hash_bytes(self) -> bytes:
@@ -193,11 +192,11 @@ def file_hash_bytes(self, file_hash_bytes: bytes):
193192

194193
@property
195194
def sd_hash(self) -> str:
196-
return hexlify(self.message.sd_hash).decode()
195+
return self.message.sd_hash.hex()
197196

198197
@sd_hash.setter
199198
def sd_hash(self, sd_hash: str):
200-
self.message.sd_hash = unhexlify(sd_hash.encode())
199+
self.message.sd_hash = bytes.fromhex(sd_hash)
201200

202201
@property
203202
def sd_hash_bytes(self) -> bytes:
@@ -209,11 +208,11 @@ def sd_hash_bytes(self, sd_hash: bytes):
209208

210209
@property
211210
def bt_infohash(self) -> str:
212-
return hexlify(self.message.bt_infohash).decode()
211+
return self.message.bt_infohash.hex()
213212

214213
@bt_infohash.setter
215214
def bt_infohash(self, bt_infohash: str):
216-
self.message.bt_infohash = unhexlify(bt_infohash.encode())
215+
self.message.bt_infohash = bytes.fromhex(bt_infohash)
217216

218217
@property
219218
def bt_infohash_bytes(self) -> bytes:
@@ -359,11 +358,11 @@ class ClaimReference(Metadata):
359358

360359
@property
361360
def claim_id(self) -> str:
362-
return hexlify(self.claim_hash[::-1]).decode()
361+
return self.claim_hash[::-1].hex()
363362

364363
@claim_id.setter
365364
def claim_id(self, claim_id: str):
366-
self.claim_hash = unhexlify(claim_id)[::-1]
365+
self.claim_hash = bytes.fromhex(claim_id)[::-1]
367366

368367
@property
369368
def claim_hash(self) -> bytes:

lbry/schema/claim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import logging
32
from typing import List
43
from binascii import hexlify, unhexlify

0 commit comments

Comments
 (0)