From b9257004dd2fb8abec90e35a4d36c0d8f96beecc Mon Sep 17 00:00:00 2001 From: hackrush Date: Tue, 25 Jul 2017 00:53:23 +0530 Subject: [PATCH 01/11] Resolving a channel returns 'channel_claim_count' Since I couldn't get my lbryum server up for testing this, it is a dry fix based on the review. Goes with lbryio/lbryum#138 --- CHANGELOG.md | 1 + docs/cli.md | 2 +- lbrynet/daemon/Daemon.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7a47888..15ec4614a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ at anytime. * Linux default downloads folder changed from `~/Downloads` to `XDG_DOWNLOAD_DIR` * Linux folders moved from the home directory to `~/.local/share/lbry` * Windows folders moved from `%AppData%/Roaming` to `%AppData%/Local/lbry` + * Changed `claim_list_by_channel` to return the `claims_in_channel` count instead of the `claims_in_channel_pages` count ### Added * Add link to instructions on how to change the default peer port diff --git a/docs/cli.md b/docs/cli.md index a838c683d..29ff1a626 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -191,7 +191,7 @@ Returns: If there was an error: 'error': (str) error message - 'claims_in_channel_pages': total number of pages with results, + 'claims_in_channel': the total number of results for the channel, If a page of results was requested: 'returned_page': page number returned, diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 96f3968fe..7b1d0b964 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2019,7 +2019,7 @@ class Daemon(AuthJSONRPCServer): If there was an error: 'error': (str) error message - 'claims_in_channel_pages': total number of pages with results, + 'claims_in_channel': the total number of results for the channel, If a page of results was requested: 'returned_page': page number returned, @@ -2077,7 +2077,7 @@ class Daemon(AuthJSONRPCServer): results[u] = resolved[u] else: results[u] = { - 'claims_in_channel_pages': resolved[u]['claims_in_channel_pages'] + 'claims_in_channel': resolved[u]['claims_in_channel'] } if page: results[u]['returned_page'] = page From ecd602e5fb0a0f849965c24500bc91791a000c66 Mon Sep 17 00:00:00 2001 From: hackrush Date: Thu, 20 Jul 2017 03:45:07 +0530 Subject: [PATCH 02/11] Added validation for currencies. Now while setting currency via API/CLI it is checked that the user has not entered any currency other that LBC, BTC or USD. Fixes #778 --- CHANGELOG.md | 4 ++++ lbrynet/conf.py | 9 +++++++++ lbrynet/core/Error.py | 6 ++++++ tests/unit/test_conf.py | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7a47888..807e96b49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ at anytime. * * +### Added + * Added validation of currencies. + * + ### Fixed * * diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 22c9662b7..2e168d805 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -8,6 +8,7 @@ import yaml import envparse from appdirs import user_data_dir, user_config_dir from lbrynet.core import utils +from lbrynet.core.Error import InvalidCurrencyError try: from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle @@ -351,6 +352,10 @@ class Config(object): assert name not in self._fixed_defaults, \ ValueError('{} is not an editable setting'.format(name)) + def _validate_currency(self, currency): + if currency not in self._fixed_defaults['CURRENCIES'].keys(): + raise InvalidCurrencyError(currency) + def get(self, name, data_type=None): """Get a config value @@ -388,6 +393,10 @@ class Config(object): data types (e.g. PERSISTED values to save to a file, CLI values from parsed command-line options, etc), you can specify that with the data_types param """ + if name == "max_key_fee": + currency = str(value["currency"]).upper() + self._validate_currency(currency) + self._assert_editable_setting(name) for data_type in data_types: self._assert_valid_data_type(data_type) diff --git a/lbrynet/core/Error.py b/lbrynet/core/Error.py index 02316d6d2..d1e8bb785 100644 --- a/lbrynet/core/Error.py +++ b/lbrynet/core/Error.py @@ -139,3 +139,9 @@ class InvalidAuthenticationToken(Exception): class NegotiationError(Exception): pass + +class InvalidCurrencyError(Exception): + def __init__(self, currency): + self.currency = currency + Exception.__init__( + self, 'Invalid currency: {} is not a supported currency.'.format(currency)) diff --git a/tests/unit/test_conf.py b/tests/unit/test_conf.py index d7adeb174..194d565af 100644 --- a/tests/unit/test_conf.py +++ b/tests/unit/test_conf.py @@ -1,8 +1,9 @@ import os +import json from twisted.trial import unittest from lbrynet import conf - +from lbrynet.core.Error import InvalidCurrencyError class SettingsTest(unittest.TestCase): def setUp(self): @@ -54,6 +55,21 @@ class SettingsTest(unittest.TestCase): settings.set('test', 'runtime_takes_precedence', data_types=(conf.TYPE_RUNTIME,)) self.assertEqual('runtime_takes_precedence', settings['test']) + def test_max_key_fee_set(self): + fixed_default = {'CURRENCIES':{'BTC':{'type':'crypto'}}} + adjustable_settings = {'max_key_fee': (json.loads, {'currency':'USD', 'amount':1})} + env = conf.Env(**adjustable_settings) + settings = conf.Config(fixed_default, adjustable_settings, environment=env) + + with self.assertRaises(InvalidCurrencyError): + settings.set('max_key_fee', {'currency':'USD', 'amount':1}) + + valid_setting= {'currency':'BTC', 'amount':1} + settings.set('max_key_fee', valid_setting ) + out = settings.get('max_key_fee') + self.assertEqual(out, valid_setting) + + def test_data_dir(self): # check if these directories are returned as string and not unicode # otherwise there will be problems when calling os.path.join on From c3a16ad837f05c868168d3ec9cb31c1863df4433 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 27 Jul 2017 09:53:11 -0400 Subject: [PATCH 03/11] Bump version 0.14.2 --> 0.14.3rc1 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index 8c9c80197..072f0ee2c 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.2" +__version__ = "0.14.3rc1" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/requirements.txt b/requirements.txt index c63ea8492..e55f3fcbe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jsonrpc==1.2 jsonrpclib==0.1.7 jsonschema==2.5.1 git+https://github.com/lbryio/lbryschema.git@v0.0.9#egg=lbryschema -git+https://github.com/lbryio/lbryum.git@v3.1.4#egg=lbryum +git+https://github.com/lbryio/lbryum.git@v3.1.5rc1#egg=lbryum miniupnpc==1.9 pbkdf2==1.3 pycrypto==2.6.1 diff --git a/setup.py b/setup.py index 9e20b8d6b..94cdd8f07 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requires = [ 'envparse', 'jsonrpc', 'jsonschema', - 'lbryum==3.1.4', + 'lbryum==3.1.5rc1', 'lbryschema==0.0.9', 'miniupnpc', 'pycrypto', From cc7a3d3dcc1e2576742d47ad081dfcdf199774be Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 27 Jul 2017 09:54:38 -0400 Subject: [PATCH 04/11] Bump version 0.14.3rc1 --> 0.14.3rc2 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index 072f0ee2c..f7bd880a9 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.3rc1" +__version__ = "0.14.3rc2" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) From 2f2b27e87265ce9e7d551ef5385dcc521b673b0f Mon Sep 17 00:00:00 2001 From: Zestyr Date: Tue, 4 Jul 2017 03:20:57 +0200 Subject: [PATCH 05/11] Remove old float formatting --- CHANGELOG.md | 2 +- lbrynet/core/Wallet.py | 4 ++-- lbrynet/daemon/Daemon.py | 20 +------------------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f829d91..d5a4915c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ at anytime. * ### Fixed - * + * Fixed incorrect formatting of "amount" fields * ### Deprecated diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 799ccdc53..c5a0d79bd 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -363,7 +363,7 @@ class SqliteStorage(MetaDataStorage): " last_modified)" "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (claim_sequence, claim_id, claim_address, height, amount, - supports, serialized, channel_name, signature_is_valid, now)) + supports, serialized, channel_name, signature_is_valid, now)) defer.returnValue(None) @rerun_if_locked @@ -376,7 +376,7 @@ class SqliteStorage(MetaDataStorage): if certificate_id: certificate_result = yield self.db.runQuery("SELECT row_id FROM claim_cache " - "WHERE claim_id=?", (certificate_id, )) + "WHERE claim_id=?", (certificate_id, )) if certificate_id is not None and certificate_result is None: log.warning("Certificate is not in cache") elif certificate_result: diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 7b1d0b964..6ff72b6bc 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1338,8 +1338,7 @@ class Daemon(AuthJSONRPCServer): claim_results = yield self.session.wallet.get_claim_by_outpoint(outpoint) else: raise Exception("Must specify either txid/nout, or claim_id") - result = format_json_out_amount_as_float(claim_results) - response = yield self._render_response(result) + response = yield self._render_response(claim_results) defer.returnValue(response) @AuthJSONRPCServer.auth_required @@ -1961,7 +1960,6 @@ class Daemon(AuthJSONRPCServer): """ d = self.session.wallet.get_name_claims() - d.addCallback(format_json_out_amount_as_float) d.addCallback(lambda claims: self._render_response(claims)) return d @@ -2614,19 +2612,3 @@ def get_blob_payment_rate_manager(session, payment_rate_manager=None): payment_rate_manager = rate_managers[payment_rate_manager] log.info("Downloading blob with rate manager: %s", payment_rate_manager) return payment_rate_manager or session.payment_rate_manager - - -# lbryum returns json loadeable object with amounts as decimal encoded string, -# convert them into floats for the daemon -# TODO: daemon should also use decimal encoded string -def format_json_out_amount_as_float(obj): - if isinstance(obj, dict): - for k, v in obj.iteritems(): - if k == 'amount' or k == 'effective_amount': - obj[k] = float(obj[k]) - if isinstance(v, (dict, list)): - obj[k] = format_json_out_amount_as_float(v) - - elif isinstance(obj, list): - obj = [format_json_out_amount_as_float(o) for o in obj] - return obj From c108ef0f836841e07dc31e76134e0069e541412d Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 31 Jul 2017 10:49:20 -0400 Subject: [PATCH 06/11] Bump version 0.14.3rc2 --> 0.14.3rc3 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index f7bd880a9..b9dfb817f 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.3rc2" +__version__ = "0.14.3rc3" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/requirements.txt b/requirements.txt index e55f3fcbe..731941a72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jsonrpc==1.2 jsonrpclib==0.1.7 jsonschema==2.5.1 git+https://github.com/lbryio/lbryschema.git@v0.0.9#egg=lbryschema -git+https://github.com/lbryio/lbryum.git@v3.1.5rc1#egg=lbryum +git+https://github.com/lbryio/lbryum.git@v3.1.5rc2#egg=lbryum miniupnpc==1.9 pbkdf2==1.3 pycrypto==2.6.1 diff --git a/setup.py b/setup.py index 94cdd8f07..c5e191e23 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requires = [ 'envparse', 'jsonrpc', 'jsonschema', - 'lbryum==3.1.5rc1', + 'lbryum==3.1.5rc2', 'lbryschema==0.0.9', 'miniupnpc', 'pycrypto', From 4e05eac8540a9c41e7f6ee5d41cab3ce54129c41 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 21 Jul 2017 14:05:08 -0400 Subject: [PATCH 07/11] add blob_announce API command, to eventually replace blob_announce_all --- lbrynet/daemon/Daemon.py | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 7b1d0b964..e5223e768 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2351,6 +2351,53 @@ class Daemon(AuthJSONRPCServer): d.addCallback(lambda r: self._render_response(r)) return d + @defer.inlineCallbacks + @AuthJSONRPCServer.flags(announce_all="-a") + def jsonrpc_blob_announce(self, announce_all=None, blob_hash=None, + stream_hash=None, sd_hash=None): + """ + Announce blobs to the DHT + + Usage: + blob_announce [-a] [ | --blob_hash=] + [ | --stream_hash=] + [ | --sd_hash=] + + Options: + -a : announce all the blobs possessed by user + , --blob_hash= : announce a blob, specified by blob_hash + , --stream_hash= : announce all blobs associated with + stream_hash + , --sd_hash= : announce all blobs associated with + sd_hash and the sd_hash itself + + Returns: + (bool) true if successful + """ + if announce_all: + yield self.session.blob_manager.immediate_announce_all_blobs() + elif blob_hash: + blob_hashes = [blob_hash] + yield self.session.blob_manager._immediate_announce(blob_hashes) + elif stream_hash: + blobs = yield self.get_blobs_for_stream_hash(stream_hash) + blobs = [blob for blob in blobs if blob.is_validated()] + blob_hashes = [blob.blob_hash for blob in blobs] + yield self.session.blob_manager._immediate_announce(blob_hashes) + elif sd_hash: + blobs = yield self.get_blobs_for_sd_hash(sd_hash) + blobs = [blob for blob in blobs if blob.is_validated()] + blob_hashes = [blob.blob_hash for blob in blobs] + blob_hashes.append(sd_hash) + yield self.session.blob_manager._immediate_announce(blob_hashes) + else: + raise Exception('single argument must be specified') + + + response = yield self._render_response(True) + defer.returnValue(response) + + # TODO: This command should be deprecated in favor of blob_announce def jsonrpc_blob_announce_all(self): """ Announce all blobs to the DHT From 999d223241ffa9d4e7bba85150596c499411266f Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 31 Jul 2017 10:44:01 -0400 Subject: [PATCH 08/11] add changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f829d91..dec16c564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ at anytime. ### Added * Added validation of currencies. - * + * Added blob_announce API command ### Fixed * From e1287c9b66a616651debdbfe241d369f041764c4 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 31 Jul 2017 11:16:33 -0400 Subject: [PATCH 09/11] Bump version 0.14.3rc3 --> 0.14.3rc4 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index b9dfb817f..1de124112 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.3rc3" +__version__ = "0.14.3rc4" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) From 5312b2b988bef0f84bce5817badaf87d843d8315 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 2 Aug 2017 10:41:06 -0400 Subject: [PATCH 10/11] Bump version 0.14.3rc4 --> 0.14.3rc5 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index 1de124112..8ba38bcd8 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.3rc4" +__version__ = "0.14.3rc5" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/requirements.txt b/requirements.txt index 731941a72..56e86cbbb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jsonrpc==1.2 jsonrpclib==0.1.7 jsonschema==2.5.1 git+https://github.com/lbryio/lbryschema.git@v0.0.9#egg=lbryschema -git+https://github.com/lbryio/lbryum.git@v3.1.5rc2#egg=lbryum +git+https://github.com/lbryio/lbryum.git@v3.1.5rc3#egg=lbryum miniupnpc==1.9 pbkdf2==1.3 pycrypto==2.6.1 diff --git a/setup.py b/setup.py index c5e191e23..6588ae14b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requires = [ 'envparse', 'jsonrpc', 'jsonschema', - 'lbryum==3.1.5rc2', + 'lbryum==3.1.5rc3', 'lbryschema==0.0.9', 'miniupnpc', 'pycrypto', From 2aee5f7948568661232a084119c79b1592dab5f7 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 2 Aug 2017 17:09:40 -0400 Subject: [PATCH 11/11] Bump version 0.14.3rc5 --> 0.14.3rc6 Signed-off-by: Jack Robison --- lbrynet/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lbrynet/__init__.py b/lbrynet/__init__.py index 8ba38bcd8..2c5c55a51 100644 --- a/lbrynet/__init__.py +++ b/lbrynet/__init__.py @@ -1,6 +1,6 @@ import logging -__version__ = "0.14.3rc5" +__version__ = "0.14.3rc6" version = tuple(__version__.split('.')) logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/requirements.txt b/requirements.txt index 56e86cbbb..effeda351 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jsonrpc==1.2 jsonrpclib==0.1.7 jsonschema==2.5.1 git+https://github.com/lbryio/lbryschema.git@v0.0.9#egg=lbryschema -git+https://github.com/lbryio/lbryum.git@v3.1.5rc3#egg=lbryum +git+https://github.com/lbryio/lbryum.git@v3.1.5rc4#egg=lbryum miniupnpc==1.9 pbkdf2==1.3 pycrypto==2.6.1 diff --git a/setup.py b/setup.py index 6588ae14b..9b5f6a09f 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requires = [ 'envparse', 'jsonrpc', 'jsonschema', - 'lbryum==3.1.5rc3', + 'lbryum==3.1.5rc4', 'lbryschema==0.0.9', 'miniupnpc', 'pycrypto',