forked from LBRYCommunity/lbry-sdk
pylint
This commit is contained in:
parent
1d68bef6f2
commit
2bea0f697a
5 changed files with 26 additions and 34 deletions
|
@ -8,6 +8,7 @@ import typing
|
|||
import aiohttp
|
||||
import base58
|
||||
import random
|
||||
from decimal import Decimal
|
||||
from urllib.parse import urlencode, quote
|
||||
from typing import Callable, Optional, List
|
||||
from binascii import hexlify, unhexlify
|
||||
|
@ -2023,19 +2024,14 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
# check for original deprecated format {'currency':{'address','amount'}}
|
||||
# add address, version to fee if unspecified
|
||||
if fee is not None:
|
||||
if len(metadata['fee'].keys()) == 1 and isinstance(metadata['fee'].values()[0], dict):
|
||||
raise Exception('Old format for fee no longer supported. '
|
||||
'Fee must be specified as {"currency":,"address":,"amount":}')
|
||||
|
||||
if 'amount' in metadata['fee'] and 'currency' in metadata['fee']:
|
||||
if not metadata['fee']['amount']:
|
||||
log.warning("Stripping empty fee from published metadata")
|
||||
del metadata['fee']
|
||||
elif 'address' not in metadata['fee']:
|
||||
address = await account.receiving.get_or_create_usable_address()
|
||||
metadata['fee']['address'] = address
|
||||
if 'fee' in metadata and 'version' not in metadata['fee']:
|
||||
metadata['fee']['version'] = '_0_0_1'
|
||||
if fee['currency'] == 'LBC':
|
||||
stream.fee.lbc = Decimal(fee['amount'])
|
||||
elif fee['currency'] == 'USD':
|
||||
stream.fee.usd = Decimal(fee['amount'])
|
||||
if 'address' in fee:
|
||||
stream.fee.address = fee['address']
|
||||
else:
|
||||
stream.fee.address = await account.receiving.get_or_create_usable_address()
|
||||
|
||||
sd_to_delete = None
|
||||
|
||||
|
@ -2079,7 +2075,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
else:
|
||||
log.info("generated stream from %s for claim", file_path)
|
||||
else:
|
||||
log.info("updating claim with stream %s from previous", claim_dict['stream']['source']['source'][:8])
|
||||
log.info("updating claim with stream %s from previous", claim.stream.hash[:8])
|
||||
|
||||
sd_hash = claim.stream.hash
|
||||
log.info("Publish: %s", {
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import json
|
||||
import logging
|
||||
from binascii import hexlify
|
||||
from lbrynet.schema.decode import smart_decode
|
||||
from lbrynet.schema.claim import Claim
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -260,7 +260,7 @@ def do_migration(conf):
|
|||
(
|
||||
"%s:%i" % (claim_arg_tup[0], claim_arg_tup[1]), claim_arg_tup[2], claim_arg_tup[3],
|
||||
claim_arg_tup[7], claim_arg_tup[6], claim_arg_tup[8],
|
||||
smart_decode(claim_arg_tup[8]).certificate_id, claim_arg_tup[5], claim_arg_tup[4]
|
||||
Claim.from_bytes(claim_arg_tup[8]).signing_channel_id, claim_arg_tup[5], claim_arg_tup[4]
|
||||
)
|
||||
for sd_hash, claim_arg_tup in claim_queries.items() if claim_arg_tup
|
||||
] # sd_hash, (txid, nout, claim_id, name, sequence, address, height, amount, serialized)
|
||||
|
|
|
@ -10,7 +10,7 @@ from lbrynet.stream.descriptor import StreamDescriptor
|
|||
from lbrynet.stream.reflector.client import StreamReflectorClient
|
||||
from lbrynet.extras.daemon.storage import StoredStreamClaim
|
||||
if typing.TYPE_CHECKING:
|
||||
from lbrynet.schema.claim import ClaimDict
|
||||
from lbrynet.schema.claim import Claim
|
||||
from lbrynet.blob.blob_manager import BlobFileManager
|
||||
from lbrynet.dht.node import Node
|
||||
|
||||
|
@ -222,7 +222,7 @@ class ManagedStream:
|
|||
await self.blob_manager.storage.update_reflected_stream(self.sd_hash, f"{host}:{port}")
|
||||
return sent
|
||||
|
||||
def set_claim(self, claim_info: typing.Dict, claim: 'ClaimDict'):
|
||||
def set_claim(self, claim_info: typing.Dict, claim: 'Claim'):
|
||||
self.stream_claim_info = StoredStreamClaim(
|
||||
self.stream_hash, f"{claim_info['txid']}:{claim_info['nout']}", claim_info['claim_id'],
|
||||
claim_info['name'], claim_info['amount'], claim_info['height'],
|
||||
|
|
|
@ -20,7 +20,7 @@ if typing.TYPE_CHECKING:
|
|||
from lbrynet.dht.node import Node
|
||||
from lbrynet.extras.daemon.analytics import AnalyticsManager
|
||||
from lbrynet.extras.daemon.storage import SQLiteStorage, StoredStreamClaim
|
||||
from lbrynet.extras.wallet import LbryWalletManager
|
||||
from lbrynet.wallet import LbryWalletManager
|
||||
from lbrynet.extras.daemon.exchange_rate_manager import ExchangeRateManager
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
@ -151,7 +151,7 @@ class Resolver:
|
|||
if not claim_result or 'value' not in claim_result:
|
||||
return claim_result
|
||||
certificate = None
|
||||
certificate_id = smart_decode(claim_result['value']).certificate_id
|
||||
certificate_id = Claim.from_bytes(claim_result['value']).signing_channel_id
|
||||
if certificate_id:
|
||||
certificate = await self.network.get_claims_by_ids(certificate_id)
|
||||
certificate = certificate.pop(certificate_id) if certificate else None
|
||||
|
@ -167,20 +167,19 @@ class Resolver:
|
|||
if not raw:
|
||||
claim_value = claim_result['value']
|
||||
try:
|
||||
decoded = smart_decode(claim_value)
|
||||
claim_result['value'] = decoded.claim_dict
|
||||
decoded = claim_result['value'] = Claim.from_bytes(claim_value)
|
||||
claim_result['decoded_claim'] = True
|
||||
except DecodeError:
|
||||
pass
|
||||
|
||||
if decoded:
|
||||
claim_result['has_signature'] = False
|
||||
if decoded.has_signature:
|
||||
if decoded.is_signed:
|
||||
if certificate is None:
|
||||
log.info("fetching certificate to check claim signature")
|
||||
certificate = await self.network.get_claims_by_ids(decoded.certificate_id)
|
||||
certificate = await self.network.get_claims_by_ids(decoded.signing_channel_id)
|
||||
if not certificate:
|
||||
log.warning('Certificate %s not found', decoded.certificate_id)
|
||||
log.warning('Certificate %s not found', decoded.signing_channel_id)
|
||||
claim_result['has_signature'] = True
|
||||
claim_result['signature_is_valid'] = False
|
||||
validated, channel_name = validate_claim_signature_and_get_channel_name(
|
||||
|
@ -195,7 +194,8 @@ class Resolver:
|
|||
if 'amount' in claim_result:
|
||||
claim_result = format_amount_value(claim_result)
|
||||
|
||||
claim_result['permanent_url'] = _get_permanent_url(claim_result, decoded.certificate_id if decoded else None)
|
||||
claim_result['permanent_url'] = _get_permanent_url(
|
||||
claim_result, decoded.signing_channel_id if decoded else None)
|
||||
|
||||
return claim_result
|
||||
|
||||
|
@ -389,8 +389,8 @@ def validate_claim_signature_and_get_channel_name(claim, certificate_claim,
|
|||
if 'value' not in certificate_claim:
|
||||
log.warning('Got an invalid claim while parsing certificates, please report: %s', certificate_claim)
|
||||
return False, None
|
||||
certificate = decoded_certificate or smart_decode(certificate_claim['value'])
|
||||
if not isinstance(certificate, ClaimDict):
|
||||
certificate = decoded_certificate or Claim.from_bytes(certificate_claim['value'])
|
||||
if not isinstance(certificate, Claim):
|
||||
raise TypeError("Certificate is not a ClaimDict: %s" % str(type(certificate)))
|
||||
if _validate_signed_claim(claim, claim_address, name, certificate):
|
||||
return True, certificate_claim['name']
|
||||
|
@ -400,8 +400,6 @@ def validate_claim_signature_and_get_channel_name(claim, certificate_claim,
|
|||
def _validate_signed_claim(claim, claim_address, name, certificate):
|
||||
if not claim.has_signature:
|
||||
raise Exception("Claim is not signed")
|
||||
if not is_address(claim_address):
|
||||
raise Exception("Not given a valid claim address")
|
||||
try:
|
||||
if claim.validate_signature(claim_address, certificate.protobuf, name):
|
||||
return True
|
||||
|
@ -429,10 +427,8 @@ def _decode_claim_result(claim):
|
|||
claim['error'] = "Failed to parse: missing value." + backend_message
|
||||
return claim
|
||||
try:
|
||||
decoded = smart_decode(claim['value'])
|
||||
claim_dict = decoded.claim_dict
|
||||
claim['value'] = claim_dict
|
||||
claim['hex'] = hexlify(decoded.serialized)
|
||||
claim['value'] = Claim.from_bytes(claim['value'])
|
||||
claim['hex'] = hexlify(claim['value'].to_bytes())
|
||||
except DecodeError:
|
||||
claim['hex'] = claim['value']
|
||||
claim['value'] = None
|
||||
|
|
Loading…
Add table
Reference in a new issue