bug fixes for lbryschema integration
This commit is contained in:
parent
60d6666abf
commit
931038d478
10 changed files with 39 additions and 36 deletions
|
@ -10,7 +10,7 @@ def get_sd_hash(stream_info):
|
||||||
if not stream_info:
|
if not stream_info:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return stream_info['sources']['lbry_sd_hash']
|
return stream_info['stream']['source']['source']
|
||||||
except (KeyError, TypeError, ValueError):
|
except (KeyError, TypeError, ValueError):
|
||||||
log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True)
|
log.debug('Failed to get sd_hash from %s', stream_info, exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -182,7 +182,7 @@ ADJUSTABLE_SETTINGS = {
|
||||||
#
|
#
|
||||||
# TODO: writing json on the cmd line is a pain, come up with a nicer
|
# TODO: writing json on the cmd line is a pain, come up with a nicer
|
||||||
# parser for this data structure. (maybe MAX_KEY_FEE': USD:25
|
# parser for this data structure. (maybe MAX_KEY_FEE': USD:25
|
||||||
'max_key_fee': (json.loads, {'USD': {'amount': 25.0, 'address': ''}}),
|
'max_key_fee': (json.loads, {'currency':'USD', 'amount': 25.0, 'address':''}),
|
||||||
|
|
||||||
'max_search_results': (int, 25),
|
'max_search_results': (int, 25),
|
||||||
'max_upload': (float, 0.0),
|
'max_upload': (float, 0.0),
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from twisted.internet import threads, reactor, defer, task
|
from twisted.internet import threads, reactor, defer, task
|
||||||
|
@ -19,6 +18,7 @@ from lbryschema.claim import ClaimDict
|
||||||
from lbryschema.decode import smart_decode
|
from lbryschema.decode import smart_decode
|
||||||
from lbryschema.error import DecodeError
|
from lbryschema.error import DecodeError
|
||||||
|
|
||||||
|
from lbrynet.core import utils
|
||||||
from lbrynet.core.sqlite_helpers import rerun_if_locked
|
from lbrynet.core.sqlite_helpers import rerun_if_locked
|
||||||
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
|
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
|
||||||
from lbrynet.core.client.ClientRequest import ClientRequest
|
from lbrynet.core.client.ClientRequest import ClientRequest
|
||||||
|
@ -495,7 +495,7 @@ class Wallet(object):
|
||||||
return Failure(InvalidStreamInfoError(name, result['value']))
|
return Failure(InvalidStreamInfoError(name, result['value']))
|
||||||
#TODO: what if keys don't exist here,
|
#TODO: what if keys don't exist here,
|
||||||
# probablly need get_sd_hash() function fro ClaimDict
|
# probablly need get_sd_hash() function fro ClaimDict
|
||||||
sd_hash = claim_dict.claim_dict['stream']['source']['source']
|
sd_hash = utils.get_sd_hash(claim_dict.claim_dict)
|
||||||
claim_outpoint = ClaimOutpoint(result['txid'], result['nout'])
|
claim_outpoint = ClaimOutpoint(result['txid'], result['nout'])
|
||||||
d = self._save_name_metadata(name, claim_outpoint, sd_hash)
|
d = self._save_name_metadata(name, claim_outpoint, sd_hash)
|
||||||
d.addCallback(lambda _: self.get_claimid(name, result['txid'], result['nout']))
|
d.addCallback(lambda _: self.get_claimid(name, result['txid'], result['nout']))
|
||||||
|
@ -534,7 +534,7 @@ class Wallet(object):
|
||||||
def _get_claim_for_return(claim):
|
def _get_claim_for_return(claim):
|
||||||
if not claim:
|
if not claim:
|
||||||
return False
|
return False
|
||||||
claim['value'] = json.loads(claim['value'])
|
claim['value'] = smart_decode(claim['value'].decode('hex')).claim_dict
|
||||||
return claim
|
return claim
|
||||||
|
|
||||||
def _get_my_unspent_claim(claims):
|
def _get_my_unspent_claim(claims):
|
||||||
|
@ -559,6 +559,7 @@ class Wallet(object):
|
||||||
d.addCallback(lambda r: self._get_claim_info(name, ClaimOutpoint(r['txid'], r['nout'])))
|
d.addCallback(lambda r: self._get_claim_info(name, ClaimOutpoint(r['txid'], r['nout'])))
|
||||||
else:
|
else:
|
||||||
d = self._get_claim_info(name, ClaimOutpoint(txid, nout))
|
d = self._get_claim_info(name, ClaimOutpoint(txid, nout))
|
||||||
|
# TODO: this catches every exception, fix this
|
||||||
d.addErrback(lambda _: False)
|
d.addErrback(lambda _: False)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -579,9 +580,9 @@ class Wallet(object):
|
||||||
def _get_claim_info(self, name, claim_outpoint):
|
def _get_claim_info(self, name, claim_outpoint):
|
||||||
def _build_response(claim):
|
def _build_response(claim):
|
||||||
try:
|
try:
|
||||||
claim_dict = smart_decode(claim['value'].decode('hex'))
|
claim_dict = smart_decode(claim['value'].decode('hex')).claim_dict
|
||||||
meta_ver = claim_dict.claim_dict['stream']['metadata']['version']
|
meta_ver = claim_dict['stream']['metadata']['version']
|
||||||
sd_hash = claim_dict.claim_dict['stream']['source']['source']
|
sd_hash = utils.get_sd_hash(claim_dict)
|
||||||
d = self._save_name_metadata(name, claim_outpoint, sd_hash)
|
d = self._save_name_metadata(name, claim_outpoint, sd_hash)
|
||||||
except (TypeError, ValueError, KeyError, DecodeError):
|
except (TypeError, ValueError, KeyError, DecodeError):
|
||||||
claim_dict = claim['value']
|
claim_dict = claim['value']
|
||||||
|
@ -651,7 +652,7 @@ class Wallet(object):
|
||||||
claim_outpoint = ClaimOutpoint(claim['txid'], claim['nout'])
|
claim_outpoint = ClaimOutpoint(claim['txid'], claim['nout'])
|
||||||
log.info("Saving metadata for claim %s %d", claim['txid'], claim['nout'])
|
log.info("Saving metadata for claim %s %d", claim['txid'], claim['nout'])
|
||||||
yield self._save_name_metadata(name, claim_outpoint,
|
yield self._save_name_metadata(name, claim_outpoint,
|
||||||
claim_dict.claim_dict['stream']['source']['source'])
|
utils.get_sd_hash(claim_dict.claim_dict))
|
||||||
defer.returnValue(claim)
|
defer.returnValue(claim)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -112,7 +112,7 @@ def short_hash(hash_str):
|
||||||
def get_sd_hash(stream_info):
|
def get_sd_hash(stream_info):
|
||||||
if not stream_info:
|
if not stream_info:
|
||||||
return None
|
return None
|
||||||
return stream_info['sources']['lbry_sd_hash']
|
return stream_info['stream']['source']['source']
|
||||||
|
|
||||||
|
|
||||||
def json_dumps_pretty(obj, **kwargs):
|
def json_dumps_pretty(obj, **kwargs):
|
||||||
|
|
|
@ -24,7 +24,8 @@ from lbrynet.conf import LBRYCRD_WALLET, LBRYUM_WALLET, PTC_WALLET
|
||||||
from lbrynet.reflector import reupload
|
from lbrynet.reflector import reupload
|
||||||
from lbrynet.reflector import ServerFactory as reflector_server_factory
|
from lbrynet.reflector import ServerFactory as reflector_server_factory
|
||||||
from lbrynet.metadata.Fee import FeeValidator
|
from lbrynet.metadata.Fee import FeeValidator
|
||||||
from lbrynet.metadata.Metadata import verify_name_characters, Metadata
|
from lbrynet.metadata.Metadata import verify_name_characters
|
||||||
|
from lbryschema.decode import smart_decode
|
||||||
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory
|
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileSaverFactory
|
||||||
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileOpenerFactory
|
from lbrynet.lbryfile.client.EncryptedFileDownloader import EncryptedFileOpenerFactory
|
||||||
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
|
||||||
|
@ -828,7 +829,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _get_est_cost_from_metadata(self, metadata, name):
|
def _get_est_cost_from_metadata(self, metadata, name):
|
||||||
d = self.get_est_cost_from_sd_hash(metadata['sources']['lbry_sd_hash'])
|
d = self.get_est_cost_from_sd_hash(utils.get_sd_hash(metadata))
|
||||||
|
|
||||||
def _handle_err(err):
|
def _handle_err(err):
|
||||||
if isinstance(err, Failure):
|
if isinstance(err, Failure):
|
||||||
|
@ -1426,9 +1427,10 @@ class Daemon(AuthJSONRPCServer):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_claim(_claim_id, _claims):
|
def _get_claim(_claim_id, _claims):
|
||||||
|
#TODO: do this in Wallet class
|
||||||
for claim in _claims['claims']:
|
for claim in _claims['claims']:
|
||||||
if claim['claim_id'] == _claim_id:
|
if claim['claim_id'] == _claim_id:
|
||||||
return Metadata(json.loads(claim['value']))
|
return smart_decode(claim['value']).claim_dict
|
||||||
|
|
||||||
log.info("Received request to get %s", name)
|
log.info("Received request to get %s", name)
|
||||||
|
|
||||||
|
@ -1477,9 +1479,11 @@ class Daemon(AuthJSONRPCServer):
|
||||||
result = yield self._get_lbry_file_dict(self.streams[name].downloader,
|
result = yield self._get_lbry_file_dict(self.streams[name].downloader,
|
||||||
full_status=True)
|
full_status=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# TODO: should reraise here, instead of returning e.message
|
||||||
log.warning('Failed to get %s', name)
|
log.warning('Failed to get %s', name)
|
||||||
self.analytics_manager.send_download_errored(download_id, name, stream_info)
|
self.analytics_manager.send_download_errored(download_id, name, stream_info)
|
||||||
result = e.message
|
result = e.message
|
||||||
|
|
||||||
response = yield self._render_response(result)
|
response = yield self._render_response(result)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import os
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
|
from lbrynet.core import utils
|
||||||
from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
|
from lbrynet.core.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed
|
||||||
from lbrynet.core.StreamDescriptor import download_sd_blob
|
from lbrynet.core.StreamDescriptor import download_sd_blob
|
||||||
from lbrynet.metadata.Fee import FeeValidator
|
from lbrynet.metadata.Fee import FeeValidator
|
||||||
|
@ -158,9 +159,9 @@ class GetStream(object):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def download(self, stream_info, name):
|
def download(self, stream_info, name):
|
||||||
self.set_status(INITIALIZING_CODE, name)
|
self.set_status(INITIALIZING_CODE, name)
|
||||||
self.sd_hash = stream_info['sources']['lbry_sd_hash']
|
self.sd_hash = utils.get_sd_hash(stream_info)
|
||||||
if 'fee' in stream_info:
|
if 'fee' in stream_info['stream']['metadata']:
|
||||||
fee = self.check_fee(stream_info['fee'])
|
fee = self.check_fee(stream_info['stream']['metadata']['fee'])
|
||||||
else:
|
else:
|
||||||
fee = None
|
fee = None
|
||||||
|
|
||||||
|
|
|
@ -193,11 +193,10 @@ class ExchangeRateManager(object):
|
||||||
fee_in = fee
|
fee_in = fee
|
||||||
|
|
||||||
return FeeValidator({
|
return FeeValidator({
|
||||||
fee_in.currency_symbol: {
|
'currency':fee_in.currency_symbol,
|
||||||
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
||||||
'address': fee_in.address
|
'address': fee_in.address
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class DummyBTCLBCFeed(MarketFeed):
|
class DummyBTCLBCFeed(MarketFeed):
|
||||||
|
@ -252,8 +251,7 @@ class DummyExchangeRateManager(object):
|
||||||
fee_in = fee
|
fee_in = fee
|
||||||
|
|
||||||
return FeeValidator({
|
return FeeValidator({
|
||||||
fee_in.currency_symbol: {
|
'currency':fee_in.currency_symbol,
|
||||||
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
'amount': self.convert_currency(fee_in.currency_symbol, "LBC", fee_in.amount),
|
||||||
'address': fee_in.address
|
'address': fee_in.address
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
|
@ -14,12 +14,12 @@ class FeeValidator(StructuredDict):
|
||||||
|
|
||||||
StructuredDict.__init__(self, fee, fee.get('ver', '0.0.1'))
|
StructuredDict.__init__(self, fee, fee.get('ver', '0.0.1'))
|
||||||
|
|
||||||
self.currency_symbol = self.keys()[0]
|
self.currency_symbol = self['currency']
|
||||||
self.amount = self._get_amount()
|
self.amount = self._get_amount()
|
||||||
self.address = self[self.currency_symbol]['address']
|
self.address = self['address']
|
||||||
|
|
||||||
def _get_amount(self):
|
def _get_amount(self):
|
||||||
amt = self[self.currency_symbol]['amount']
|
amt = self['amount']
|
||||||
try:
|
try:
|
||||||
return float(amt)
|
return float(amt)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -80,7 +80,7 @@ def get_test_daemon(data_rate=None, generous=True, with_fee=False):
|
||||||
}
|
}
|
||||||
if with_fee:
|
if with_fee:
|
||||||
metadata.update(
|
metadata.update(
|
||||||
{"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
|
{"fee": {"currency":"USD", "address":"bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}})
|
||||||
daemon._resolve_name = lambda _: defer.succeed(metadata)
|
daemon._resolve_name = lambda _: defer.succeed(metadata)
|
||||||
return daemon
|
return daemon
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,13 @@ from tests import util
|
||||||
class FeeFormatTest(unittest.TestCase):
|
class FeeFormatTest(unittest.TestCase):
|
||||||
def test_fee_created_with_correct_inputs(self):
|
def test_fee_created_with_correct_inputs(self):
|
||||||
fee_dict = {
|
fee_dict = {
|
||||||
'USD': {
|
'currency':'USD',
|
||||||
'amount': 10.0,
|
'amount': 10.0,
|
||||||
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fee = Fee.FeeValidator(fee_dict)
|
fee = Fee.FeeValidator(fee_dict)
|
||||||
self.assertEqual(10.0, fee['USD']['amount'])
|
self.assertEqual(10.0, fee['amount'])
|
||||||
|
self.assertEqual('USD', fee['currency'])
|
||||||
|
|
||||||
class FeeTest(unittest.TestCase):
|
class FeeTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -26,11 +25,11 @@ class FeeTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_fee_converts_to_lbc(self):
|
def test_fee_converts_to_lbc(self):
|
||||||
fee_dict = {
|
fee_dict = {
|
||||||
'USD': {
|
'currency':'USD',
|
||||||
'amount': 10.0,
|
'amount': 10.0,
|
||||||
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rates = {
|
rates = {
|
||||||
'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1},
|
'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1},
|
||||||
'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2}
|
'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2}
|
||||||
|
|
Loading…
Reference in a new issue