This commit is contained in:
Lex Berezhny 2019-03-20 02:00:03 -04:00
parent 1d68bef6f2
commit 2bea0f697a
5 changed files with 26 additions and 34 deletions

View file

@ -8,6 +8,7 @@ import typing
import aiohttp import aiohttp
import base58 import base58
import random import random
from decimal import Decimal
from urllib.parse import urlencode, quote from urllib.parse import urlencode, quote
from typing import Callable, Optional, List from typing import Callable, Optional, List
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
@ -2023,19 +2024,14 @@ class Daemon(metaclass=JSONRPCServerType):
# check for original deprecated format {'currency':{'address','amount'}} # check for original deprecated format {'currency':{'address','amount'}}
# add address, version to fee if unspecified # add address, version to fee if unspecified
if fee is not None: if fee is not None:
if len(metadata['fee'].keys()) == 1 and isinstance(metadata['fee'].values()[0], dict): if fee['currency'] == 'LBC':
raise Exception('Old format for fee no longer supported. ' stream.fee.lbc = Decimal(fee['amount'])
'Fee must be specified as {"currency":,"address":,"amount":}') elif fee['currency'] == 'USD':
stream.fee.usd = Decimal(fee['amount'])
if 'amount' in metadata['fee'] and 'currency' in metadata['fee']: if 'address' in fee:
if not metadata['fee']['amount']: stream.fee.address = fee['address']
log.warning("Stripping empty fee from published metadata") else:
del metadata['fee'] stream.fee.address = await account.receiving.get_or_create_usable_address()
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'
sd_to_delete = None sd_to_delete = None
@ -2079,7 +2075,7 @@ class Daemon(metaclass=JSONRPCServerType):
else: else:
log.info("generated stream from %s for claim", file_path) log.info("generated stream from %s for claim", file_path)
else: 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 sd_hash = claim.stream.hash
log.info("Publish: %s", { log.info("Publish: %s", {

View file

@ -3,7 +3,7 @@ import os
import json import json
import logging import logging
from binascii import hexlify from binascii import hexlify
from lbrynet.schema.decode import smart_decode from lbrynet.schema.claim import Claim
log = logging.getLogger(__name__) 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], "%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], 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 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) ] # sd_hash, (txid, nout, claim_id, name, sequence, address, height, amount, serialized)

View file

@ -10,7 +10,7 @@ from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.reflector.client import StreamReflectorClient from lbrynet.stream.reflector.client import StreamReflectorClient
from lbrynet.extras.daemon.storage import StoredStreamClaim from lbrynet.extras.daemon.storage import StoredStreamClaim
if typing.TYPE_CHECKING: 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.blob.blob_manager import BlobFileManager
from lbrynet.dht.node import Node 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}") await self.blob_manager.storage.update_reflected_stream(self.sd_hash, f"{host}:{port}")
return sent 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_claim_info = StoredStreamClaim(
self.stream_hash, f"{claim_info['txid']}:{claim_info['nout']}", claim_info['claim_id'], self.stream_hash, f"{claim_info['txid']}:{claim_info['nout']}", claim_info['claim_id'],
claim_info['name'], claim_info['amount'], claim_info['height'], claim_info['name'], claim_info['amount'], claim_info['height'],

View file

@ -20,7 +20,7 @@ if typing.TYPE_CHECKING:
from lbrynet.dht.node import Node from lbrynet.dht.node import Node
from lbrynet.extras.daemon.analytics import AnalyticsManager from lbrynet.extras.daemon.analytics import AnalyticsManager
from lbrynet.extras.daemon.storage import SQLiteStorage, StoredStreamClaim 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 from lbrynet.extras.daemon.exchange_rate_manager import ExchangeRateManager
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -151,7 +151,7 @@ class Resolver:
if not claim_result or 'value' not in claim_result: if not claim_result or 'value' not in claim_result:
return claim_result return claim_result
certificate = None 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: if certificate_id:
certificate = await self.network.get_claims_by_ids(certificate_id) certificate = await self.network.get_claims_by_ids(certificate_id)
certificate = certificate.pop(certificate_id) if certificate else None certificate = certificate.pop(certificate_id) if certificate else None
@ -167,20 +167,19 @@ class Resolver:
if not raw: if not raw:
claim_value = claim_result['value'] claim_value = claim_result['value']
try: try:
decoded = smart_decode(claim_value) decoded = claim_result['value'] = Claim.from_bytes(claim_value)
claim_result['value'] = decoded.claim_dict
claim_result['decoded_claim'] = True claim_result['decoded_claim'] = True
except DecodeError: except DecodeError:
pass pass
if decoded: if decoded:
claim_result['has_signature'] = False claim_result['has_signature'] = False
if decoded.has_signature: if decoded.is_signed:
if certificate is None: if certificate is None:
log.info("fetching certificate to check claim signature") 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: 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['has_signature'] = True
claim_result['signature_is_valid'] = False claim_result['signature_is_valid'] = False
validated, channel_name = validate_claim_signature_and_get_channel_name( validated, channel_name = validate_claim_signature_and_get_channel_name(
@ -195,7 +194,8 @@ class Resolver:
if 'amount' in claim_result: if 'amount' in claim_result:
claim_result = format_amount_value(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 return claim_result
@ -389,8 +389,8 @@ def validate_claim_signature_and_get_channel_name(claim, certificate_claim,
if 'value' not in certificate_claim: if 'value' not in certificate_claim:
log.warning('Got an invalid claim while parsing certificates, please report: %s', certificate_claim) log.warning('Got an invalid claim while parsing certificates, please report: %s', certificate_claim)
return False, None return False, None
certificate = decoded_certificate or smart_decode(certificate_claim['value']) certificate = decoded_certificate or Claim.from_bytes(certificate_claim['value'])
if not isinstance(certificate, ClaimDict): if not isinstance(certificate, Claim):
raise TypeError("Certificate is not a ClaimDict: %s" % str(type(certificate))) raise TypeError("Certificate is not a ClaimDict: %s" % str(type(certificate)))
if _validate_signed_claim(claim, claim_address, name, certificate): if _validate_signed_claim(claim, claim_address, name, certificate):
return True, certificate_claim['name'] 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): def _validate_signed_claim(claim, claim_address, name, certificate):
if not claim.has_signature: if not claim.has_signature:
raise Exception("Claim is not signed") raise Exception("Claim is not signed")
if not is_address(claim_address):
raise Exception("Not given a valid claim address")
try: try:
if claim.validate_signature(claim_address, certificate.protobuf, name): if claim.validate_signature(claim_address, certificate.protobuf, name):
return True return True
@ -429,10 +427,8 @@ def _decode_claim_result(claim):
claim['error'] = "Failed to parse: missing value." + backend_message claim['error'] = "Failed to parse: missing value." + backend_message
return claim return claim
try: try:
decoded = smart_decode(claim['value']) claim['value'] = Claim.from_bytes(claim['value'])
claim_dict = decoded.claim_dict claim['hex'] = hexlify(claim['value'].to_bytes())
claim['value'] = claim_dict
claim['hex'] = hexlify(decoded.serialized)
except DecodeError: except DecodeError:
claim['hex'] = claim['value'] claim['hex'] = claim['value']
claim['value'] = None claim['value'] = None