forked from LBRYCommunity/lbry-sdk
handle invalid data
This commit is contained in:
parent
89c80cedfd
commit
d16e2716c8
2 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
||||||
import json
|
import json
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from google.protobuf.message import DecodeError
|
||||||
|
|
||||||
from lbrynet.schema.types.v1.legacy_claim_pb2 import Claim as OldClaimMessage
|
from lbrynet.schema.types.v1.legacy_claim_pb2 import Claim as OldClaimMessage
|
||||||
from lbrynet.schema.types.v1.certificate_pb2 import KeyType
|
from lbrynet.schema.types.v1.certificate_pb2 import KeyType
|
||||||
from lbrynet.schema.types.v1.fee_pb2 import Fee as FeeMessage
|
from lbrynet.schema.types.v1.fee_pb2 import Fee as FeeMessage
|
||||||
|
@ -37,7 +39,7 @@ def from_old_json_schema(claim, payload: bytes):
|
||||||
elif currency == 'BTC':
|
elif currency == 'BTC':
|
||||||
stream.fee.btc = Decimal(fee[currency]['amount'])
|
stream.fee.btc = Decimal(fee[currency]['amount'])
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unknown currency: {currency}')
|
raise DecodeError(f'Unknown currency: {currency}')
|
||||||
stream.fee.address = fee[currency]['address']
|
stream.fee.address = fee[currency]['address']
|
||||||
return claim
|
return claim
|
||||||
|
|
||||||
|
@ -70,7 +72,7 @@ def from_types_v1(claim, payload: bytes):
|
||||||
elif currency == 'BTC':
|
elif currency == 'BTC':
|
||||||
stream.fee.btc = Decimal(fee.amount)
|
stream.fee.btc = Decimal(fee.amount)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unsupported currency: {currency}')
|
raise DecodeError(f'Unsupported currency: {currency}')
|
||||||
if old.HasField('publisherSignature'):
|
if old.HasField('publisherSignature'):
|
||||||
sig = old.publisherSignature
|
sig = old.publisherSignature
|
||||||
claim.signature = sig.signature
|
claim.signature = sig.signature
|
||||||
|
@ -82,5 +84,5 @@ def from_types_v1(claim, payload: bytes):
|
||||||
channel = claim.channel
|
channel = claim.channel
|
||||||
channel.public_key_bytes = old.certificate.publicKey
|
channel.public_key_bytes = old.certificate.publicKey
|
||||||
else:
|
else:
|
||||||
raise ValueError('claimType must be 1 for Streams and 2 for Channel')
|
raise DecodeError('claimType must be 1 for Streams and 2 for Channel')
|
||||||
return claim
|
return claim
|
||||||
|
|
|
@ -420,7 +420,7 @@ def _decode_claim_result(claim):
|
||||||
return claim
|
return claim
|
||||||
try:
|
try:
|
||||||
if not isinstance(claim['value'], Claim):
|
if not isinstance(claim['value'], Claim):
|
||||||
claim['value'] = Claim.from_bytes(claim['value'])
|
claim['value'] = Claim.from_bytes(unhexlify(claim['value']))
|
||||||
claim['hex'] = hexlify(claim['value'].to_bytes())
|
claim['hex'] = hexlify(claim['value'].to_bytes())
|
||||||
except DecodeError:
|
except DecodeError:
|
||||||
claim['hex'] = claim['value']
|
claim['hex'] = claim['value']
|
||||||
|
|
Loading…
Reference in a new issue