def _get_stream_info_from_value(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 _log_success(claim_id): log.debug("lbry://%s complies with %s, claimid: %s", name, metadata.version, claim_id) return defer.succeed(None) if 'error' in result: log.warning("Got an error looking up a name: %s", result['error']) return Failure(UnknownNameError(name)) _check_result_fields(result) try: metadata = Metadata(json.loads(result['value'])) except (TypeError, ValueError, ValidationError): return Failure(InvalidStreamInfoError(name, result['value'])) sd_hash = metadata['sources']['lbry_sd_hash'] claim_outpoint = ClaimOutpoint(result['txid'], result['n']) d = self._save_name_metadata(name, claim_outpoint, sd_hash) d.addCallback( lambda _: self.get_claimid(name, result['txid'], result['n'])) d.addCallback(lambda cid: _log_success(cid)) d.addCallback(lambda _: metadata) return d
def _handle_claim_result(results): if not results: #TODO: cannot determine what name we searched for here # we should fix lbryum commands that return None raise UnknownNameError("") if 'error' in results: if results['error'] in ['name is not claimed', 'claim not found']: if 'claim_id' in results: raise UnknownClaimID(results['claim_id']) elif 'name' in results: raise UnknownNameError(results['name']) elif 'uri' in results: raise UnknownURI(results['uri']) elif 'outpoint' in results: raise UnknownOutpoint(results['outpoint']) raise Exception(results['error']) # case where return value is {'certificate':{'txid', 'value',...},...} if 'certificate' in results: results['certificate'] = _decode_claim_result(results['certificate']) # case where return value is {'claim':{'txid','value',...},...} if 'claim' in results: results['claim'] = _decode_claim_result(results['claim']) # case where return value is {'txid','value',...} # returned by queries that are not name resolve related # (getclaimbyoutpoint, getclaimbyid, getclaimsfromtx) elif 'value' in results: results = _decode_claim_result(results) # case where there is no 'certificate', 'value', or 'claim' key elif 'certificate' not in results: msg = 'result in unexpected format:{}'.format(results) assert False, msg return results
def get_claim_for_name(claims): for claim in claims: if claim_outpoint == claim: claim['txid'] = txid return claim return Failure(UnknownNameError(name))
def _handle_claim_result(self, results): if not results: raise UnknownNameError("No results to return") if 'error' in results: if results['error'] == 'name is not claimed': raise UnknownNameError(results['error']) else: raise Exception(results['error']) if 'claim' in results: claim = results['claim'] if 'has_signature' in claim and claim['has_signature']: if not claim['signature_is_valid']: log.warning("lbry://%s#%s has an invalid signature", claim['name'], claim['claim_id']) decoded = ClaimDict.load_dict(claim['value']) claim_dict = decoded.claim_dict claim['value'] = claim_dict defer.returnValue(claim) try: decoded = smart_decode(claim['value']) claim_dict = decoded.claim_dict outpoint = ClaimOutpoint(claim['txid'], claim['nout']) name = claim['name'] claim['value'] = claim_dict claim['hex'] = decoded.serialized.encode('hex') yield self._save_name_metadata(name, outpoint, decoded.source_hash) yield self._update_claimid(claim['claim_id'], name, outpoint) except DecodeError: claim['hex'] = claim['value'] claim['value'] = None claim['error'] = "Failed to decode value" results = claim elif 'value' in results: if 'has_signature' in results and results['has_signature']: if not results['signature_is_valid']: log.warning("lbry://%s#%s has an invalid signature", results['name'], results['claim_id']) decoded = ClaimDict.load_dict(results['value']) claim_dict = decoded.claim_dict results['value'] = claim_dict defer.returnValue(results) try: decoded = ClaimDict.load_dict(results['value']) claim_dict = decoded.claim_dict claim_hex = decoded.serialized.encode('hex') claim_err = None outpoint = ClaimOutpoint(results['txid'], results['nout']) name = results['name'] yield self._save_name_metadata(name, outpoint, decoded.source_hash) yield self._update_claimid(results['claim_id'], name, outpoint) except DecodeError: claim_dict = None claim_hex = results['value'] claim_err = "Failed to decode value" if claim_err: results['error'] = claim_err results['hex'] = claim_hex results['value'] = claim_dict log.info("get claim info lbry://%s#%s", results['name'], results['claim_id']) defer.returnValue(results)