From e91f34f09b5cb30e65c11630e798c8dd432997ab Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:25:46 -0500 Subject: [PATCH 1/2] change metadata structure to use sources key --- lbrynet/core/LBRYcrdWallet.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index 09bc1e7bc..ef7c95baf 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -297,10 +297,19 @@ class LBRYWallet(object): except (ValueError, TypeError): return Failure(InvalidStreamInfoError(name)) known_fields = ['stream_hash', 'name', 'description', 'key_fee', 'key_fee_address', 'thumbnail', - 'content_license'] + 'content_license', 'sources'] + known_sources = ['lbry_sd_hash'] for field in known_fields: if field in value_dict: - r_dict[field] = value_dict[field] + if field == 'sources': + for source in known_sources: + if source in value_dict[field]: + if source == 'lbry_sd_hash': + r_dict['stream_hash'] = value_dict[field][source] + else: + r_dict[source] = value_dict[field][source] + else: + r_dict[field] = value_dict[field] if 'stream_hash' in r_dict and 'txid' in result: d = self._save_name_metadata(name, r_dict['stream_hash'], str(result['txid'])) else: @@ -312,8 +321,8 @@ class LBRYWallet(object): return Failure(UnknownNameError(name)) def claim_name(self, name, sd_hash, amount, description=None, key_fee=None, - key_fee_address=None, thumbnail=None, content_license=None): - value = {"stream_hash": sd_hash} + key_fee_address=None, thumbnail=None, content_license=None): + value = {"sources": {'lbry_sd_hash': sd_hash}} if description is not None: value['description'] = description if key_fee is not None: @@ -397,7 +406,12 @@ class LBRYWallet(object): value_dict = json.loads(claim['value']) except (ValueError, TypeError): return None - if 'stream_hash' in value_dict and str(value_dict['stream_hash']) == sd_hash: + claim_sd_hash = None + if 'stream_hash' in value_dict: + claim_sd_hash = str(value_dict['stream_hash']) + if 'sources' in value_dict and 'lbrynet_sd_hash' in value_dict['sources']: + claim_sd_hash = str(value_dict['sources']['lbry_sd_hash']) + if claim_sd_hash is not None and claim_sd_hash == sd_hash: if 'is controlling' in claim and claim['is controlling']: return name, "valid" if claim['in claim trie']: From 14ab2b52e94afc9c1a81b0932db224b25c52289a Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Sat, 12 Mar 2016 14:42:57 -0500 Subject: [PATCH 2/2] create fee field in metadata --- lbrynet/core/LBRYcrdWallet.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index ef7c95baf..153b27e56 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -297,8 +297,9 @@ class LBRYWallet(object): except (ValueError, TypeError): return Failure(InvalidStreamInfoError(name)) known_fields = ['stream_hash', 'name', 'description', 'key_fee', 'key_fee_address', 'thumbnail', - 'content_license', 'sources'] + 'content_license', 'sources', 'fee'] known_sources = ['lbry_sd_hash'] + known_fee_types = {'LBC': ['amount', 'address']} for field in known_fields: if field in value_dict: if field == 'sources': @@ -308,6 +309,18 @@ class LBRYWallet(object): r_dict['stream_hash'] = value_dict[field][source] else: r_dict[source] = value_dict[field][source] + elif field == 'fee': + fee = value_dict['fee'] + if 'type' in fee: + if fee['type'] in known_fee_types: + fee_fields = known_fee_types[fee['type']] + if all([f in fee for f in fee_fields]): + r_dict['key_fee'] = fee['amount'] + r_dict['key_fee_address'] = fee['address'] + else: + for f in ['key_fee', 'key_fee_address']: + if f in r_dict: + del r_dict[f] else: r_dict[field] = value_dict[field] if 'stream_hash' in r_dict and 'txid' in result: @@ -325,10 +338,8 @@ class LBRYWallet(object): value = {"sources": {'lbry_sd_hash': sd_hash}} if description is not None: value['description'] = description - if key_fee is not None: - value['key_fee'] = key_fee - if key_fee_address is not None: - value['key_fee_address'] = key_fee_address + if key_fee is not None and key_fee_address is not None: + value['fee'] = {'type': 'LBC', 'amount': key_fee, 'address': key_fee_address} if thumbnail is not None: value['thumbnail'] = thumbnail if content_license is not None: