Skip to content

Commit

Permalink
Align lbry/schema with hub/schema regarding hex encoding/decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyjon committed Nov 21, 2022
1 parent 9b38c7d commit 63fbf39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
19 changes: 9 additions & 10 deletions lbry/schema/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Tuple, List
from string import ascii_letters
from decimal import Decimal, ROUND_UP
from binascii import hexlify, unhexlify
from google.protobuf.json_format import MessageToDict, ParseDict, ParseError

from lbry.crypto.base58 import Base58
Expand All @@ -16,7 +15,7 @@
import lbry.schema.claim as claim
from lbry.schema.mime_types import guess_media_type
from lbry.schema.base import Metadata, BaseMessageList
from lbry.schema.tags import clean_tags, normalize_tag
from lbry.schema.tags import normalize_tag
from google.protobuf.message import Message as ProtobufMessage
from lbry.schema.types.v2.claim_pb2 import (
Claim as ClaimMessage,
Expand Down Expand Up @@ -177,11 +176,11 @@ def media_type(self, media_type: str):

@property
def file_hash(self) -> str:
return hexlify(self.message.hash).decode()
return self.message.hash.hex()

@file_hash.setter
def file_hash(self, file_hash: str):
self.message.hash = unhexlify(file_hash.encode())
self.message.hash = bytes.fromhex(file_hash)

@property
def file_hash_bytes(self) -> bytes:
Expand All @@ -193,11 +192,11 @@ def file_hash_bytes(self, file_hash_bytes: bytes):

@property
def sd_hash(self) -> str:
return hexlify(self.message.sd_hash).decode()
return self.message.sd_hash.hex()

@sd_hash.setter
def sd_hash(self, sd_hash: str):
self.message.sd_hash = unhexlify(sd_hash.encode())
self.message.sd_hash = bytes.fromhex(sd_hash)

@property
def sd_hash_bytes(self) -> bytes:
Expand All @@ -209,11 +208,11 @@ def sd_hash_bytes(self, sd_hash: bytes):

@property
def bt_infohash(self) -> str:
return hexlify(self.message.bt_infohash).decode()
return self.message.bt_infohash.hex()

@bt_infohash.setter
def bt_infohash(self, bt_infohash: str):
self.message.bt_infohash = unhexlify(bt_infohash.encode())
self.message.bt_infohash = bytes.fromhex(bt_infohash)

@property
def bt_infohash_bytes(self) -> bytes:
Expand Down Expand Up @@ -359,11 +358,11 @@ class ClaimReference(Metadata):

@property
def claim_id(self) -> str:
return hexlify(self.claim_hash[::-1]).decode()
return self.claim_hash[::-1].hex()

@claim_id.setter
def claim_id(self, claim_id: str):
self.claim_hash = unhexlify(claim_id)[::-1]
self.claim_hash = bytes.fromhex(claim_id)[::-1]

@property
def claim_hash(self) -> bytes:
Expand Down
1 change: 0 additions & 1 deletion lbry/schema/claim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging
from typing import List
from binascii import hexlify, unhexlify
Expand Down

0 comments on commit 63fbf39

Please sign in to comment.