add get_claim_info, clean up _get_stream_info_from_value
This commit is contained in:
parent
881168dc7a
commit
5dd68a7ed4
2 changed files with 57 additions and 15 deletions
|
@ -320,26 +320,57 @@ class LBRYWallet(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _get_stream_info_from_value(self, result, name):
|
def _get_stream_info_from_value(self, result, name):
|
||||||
if 'value' in result:
|
def _check_result_fields(r):
|
||||||
value = result['value']
|
for k in ['value', 'txid', 'n', 'height', 'amount']:
|
||||||
|
assert k in r, "getvalueforname response missing field %s" % k
|
||||||
|
|
||||||
try:
|
if 'error' in result:
|
||||||
value_dict = json.loads(value)
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
return Failure(InvalidStreamInfoError(name))
|
|
||||||
m = Metadata(value_dict)
|
|
||||||
if 'txid' in result:
|
|
||||||
d = self._save_name_metadata(name, str(result['txid']), m['sources']['lbry_sd_hash'])
|
|
||||||
d.addCallback(lambda _: log.info("lbry://%s complies with %s" % (name, m.meta_version)))
|
|
||||||
d.addCallback(lambda _: m)
|
|
||||||
return d
|
|
||||||
elif 'error' in result:
|
|
||||||
log.warning("Got an error looking up a name: %s", result['error'])
|
log.warning("Got an error looking up a name: %s", result['error'])
|
||||||
return Failure(UnknownNameError(name))
|
return Failure(UnknownNameError(name))
|
||||||
else:
|
|
||||||
log.warning("Got an error looking up a name: %s", json.dumps(result))
|
_check_result_fields(result)
|
||||||
|
|
||||||
|
try:
|
||||||
|
metadata = Metadata(json.loads(result['value']))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return Failure(InvalidStreamInfoError(name))
|
||||||
|
|
||||||
|
d = self._save_name_metadata(name, str(result['txid']), metadata['sources']['lbry_sd_hash'])
|
||||||
|
d.addCallback(lambda _: log.info("lbry://%s complies with %s" % (name, metadata.meta_version)))
|
||||||
|
d.addCallback(lambda _: metadata)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def _get_claim_info(self, result, name):
|
||||||
|
def _check_result_fields(r):
|
||||||
|
for k in ['value', 'txid', 'n', 'height', 'amount']:
|
||||||
|
assert k in r, "getvalueforname response missing field %s" % k
|
||||||
|
|
||||||
|
def _build_response(m, result):
|
||||||
|
result['value'] = m
|
||||||
|
return result
|
||||||
|
|
||||||
|
if 'error' in result:
|
||||||
|
log.warning("Got an error looking up a name: %s", result['error'])
|
||||||
return Failure(UnknownNameError(name))
|
return Failure(UnknownNameError(name))
|
||||||
|
|
||||||
|
_check_result_fields(result)
|
||||||
|
|
||||||
|
try:
|
||||||
|
metadata = Metadata(json.loads(result['value']))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return Failure(InvalidStreamInfoError(name))
|
||||||
|
|
||||||
|
d = self._save_name_metadata(name, str(result['txid']), metadata['sources']['lbry_sd_hash'])
|
||||||
|
d.addCallback(lambda _: log.info("lbry://%s complies with %s" % (name, metadata.meta_version)))
|
||||||
|
d.addCallback(lambda _: _build_response(metadata, result))
|
||||||
|
return d
|
||||||
|
|
||||||
|
def get_claim_info(self, name):
|
||||||
|
d = self._get_value_for_name(name)
|
||||||
|
d.addCallback(lambda r: self._get_claim_info(r, name))
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def claim_name(self, name, bid, m):
|
def claim_name(self, name, bid, m):
|
||||||
|
|
||||||
metadata = Metadata(m)
|
metadata = Metadata(m)
|
||||||
|
|
|
@ -1718,6 +1718,17 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
d.addCallbacks(lambda info: self._render_response(info, OK_CODE), lambda _: server.failure)
|
d.addCallbacks(lambda info: self._render_response(info, OK_CODE), lambda _: server.failure)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def jsonrpc_get_claim_info(self, p):
|
||||||
|
def _convert_amount_to_float(r):
|
||||||
|
r['amount'] = float(r['amount']) / 10**8
|
||||||
|
return r
|
||||||
|
|
||||||
|
name = p['name']
|
||||||
|
d = self.session.wallet.get_claim_info(name)
|
||||||
|
d.addCallback(_convert_amount_to_float)
|
||||||
|
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||||
|
return d
|
||||||
|
|
||||||
def jsonrpc_get(self, p):
|
def jsonrpc_get(self, p):
|
||||||
"""
|
"""
|
||||||
Download stream from a LBRY uri
|
Download stream from a LBRY uri
|
||||||
|
|
Loading…
Reference in a new issue