From 21c1786dc625e1a6da14017405fe6b3b3f4d0c3e Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 23 Jun 2017 12:03:01 -0400 Subject: [PATCH 1/6] rename Wallet.get_claim() to get_claim_by_claim_id() --- lbrynet/core/Wallet.py | 2 +- lbrynet/daemon/Daemon.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 25f88f608..93e3d1f4c 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -693,7 +693,7 @@ class Wallet(object): defer.returnValue(results) @defer.inlineCallbacks - def get_claim(self, claim_id, check_expire=True): + def get_claim_by_claim_id(self, claim_id, check_expire=True): cached_claim = yield self.get_cached_claim(claim_id, check_expire) if cached_claim: result = cached_claim diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index be1841a25..0037365a1 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -836,7 +836,8 @@ class Daemon(AuthJSONRPCServer): size = None message = None - claim = yield self.session.wallet.get_claim(lbry_file.claim_id, check_expire=False) + claim = yield self.session.wallet.get_claim_by_claim_id(lbry_file.claim_id, + check_expire=False) if claim and 'value' in claim: metadata = claim['value'] @@ -1343,7 +1344,7 @@ class Daemon(AuthJSONRPCServer): """ try: if claim_id: - claim_results = yield self.session.wallet.get_claim(claim_id) + claim_results = yield self.session.wallet.get_claim_by_claim_id(claim_id) elif txid and nout is not None: outpoint = ClaimOutpoint(txid, nout) claim_results = yield self.session.wallet.get_claim_by_outpoint(outpoint) From 24035406d6b47c0f893ba6b018b8c0a20c82a53a Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 23 Jun 2017 12:00:33 -0400 Subject: [PATCH 2/6] have claim_show no longer handle name argument, do not catch exceptions here as they will be caught in Wallet --- lbrynet/core/Wallet.py | 8 ++++---- lbrynet/daemon/Daemon.py | 29 ++++++++++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 93e3d1f4c..c6ab121b6 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -700,11 +700,11 @@ class Wallet(object): else: log.debug("Refreshing cached claim: %s", claim_id) claim = yield self._get_claim_by_claimid(claim_id) - result = None - if claim: + try: result = yield self._handle_claim_result(claim) - else: - log.warning("Claim does not exist: %s", claim_id) + except (UnknownNameError, UnknownClaimID, UnknownURI) as err: + result = {'error': err.message} + defer.returnValue(result) @defer.inlineCallbacks diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 0037365a1..24edba04b 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -44,7 +44,7 @@ from lbrynet.core.looping_call_manager import LoopingCallManager from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash -from lbrynet.core.Error import NoSuchStreamHash, UnknownClaimID, UnknownURI +from lbrynet.core.Error import NoSuchStreamHash from lbrynet.core.Error import NullFundsError, NegativeFundsError log = logging.getLogger(__name__) @@ -1315,13 +1315,13 @@ class Daemon(AuthJSONRPCServer): defer.returnValue(metadata) @defer.inlineCallbacks - def jsonrpc_claim_show(self, name=None, txid=None, nout=None, claim_id=None): + def jsonrpc_claim_show(self, txid=None, nout=None, claim_id=None): """ Resolve claim info from a LBRY name Usage: - claim_show [ | --txid=] [ | --nout=] - [ | --claim_id=] + claim_show [ | --txid=] [ | --nout=] + [ | --claim_id=] Options: , --txid= : look for claim with this txid @@ -1342,19 +1342,14 @@ class Daemon(AuthJSONRPCServer): 'supports': (list) list of supports associated with claim } """ - try: - if claim_id: - claim_results = yield self.session.wallet.get_claim_by_claim_id(claim_id) - elif txid and nout is not None: - outpoint = ClaimOutpoint(txid, nout) - claim_results = yield self.session.wallet.get_claim_by_outpoint(outpoint) - else: - claim_results = yield self.session.wallet.resolve(name) - if claim_results: - claim_results = claim_results[name] - result = format_json_out_amount_as_float(claim_results) - except (TypeError, UnknownNameError, UnknownClaimID, UnknownURI): - result = False + if claim_id is not None and txid is None and nout is None: + claim_results = yield self.session.wallet.get_claim_by_claim_id(claim_id) + elif txid is not None and nout is not None and claim_id is None: + outpoint = ClaimOutpoint(txid, nout) + 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) defer.returnValue(response) From b355e9ed8e20d922f5b37e54bed85c53fc492b7d Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 23 Jun 2017 14:47:28 -0400 Subject: [PATCH 3/6] make accurate docstring of claim_show --- lbrynet/daemon/Daemon.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 24edba04b..6c256f751 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1317,20 +1317,21 @@ class Daemon(AuthJSONRPCServer): @defer.inlineCallbacks def jsonrpc_claim_show(self, txid=None, nout=None, claim_id=None): """ - Resolve claim info from a LBRY name + Resolve claim info from txid/nout or with claim ID Usage: claim_show [ | --txid=] [ | --nout=] [ | --claim_id=] Options: - , --txid= : look for claim with this txid - , --nout= : look for claim with this nout + , --txid= : look for claim with this txid, nout must + also be specified + , --nout= : look for claim with this nout, txid must + also be specified , --claim_id= : look for claim with this claim id Returns: - (dict) Dictionary contaning claim info, (bool) false if claim is not - resolvable + (dict) Dictionary containing claim info as below, { 'txid': (str) txid of claim @@ -1341,6 +1342,13 @@ class Daemon(AuthJSONRPCServer): 'claim_id': (str) claim ID of claim 'supports': (list) list of supports associated with claim } + + if claim cannot be resolved, dictionary as below will be returned + + { + 'error': (str) reason for error + } + """ if claim_id is not None and txid is None and nout is None: claim_results = yield self.session.wallet.get_claim_by_claim_id(claim_id) From 3cd972a4dad80f20e6f0700c3b6907434f82e53d Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 23 Jun 2017 14:25:44 -0400 Subject: [PATCH 4/6] fix UnknownNameError message --- lbrynet/core/Wallet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index c6ab121b6..04f4ce0e5 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -760,7 +760,9 @@ class Wallet(object): @defer.inlineCallbacks def _handle_claim_result(self, results, update_caches=True): if not results: - raise UnknownNameError("No results to return") + #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']: From e4df0bdb5f436e09b245c3ec56ea0a4993b3828f Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 17 Jul 2017 11:55:24 -0400 Subject: [PATCH 5/6] create UnknownOutpoint exception and use it --- lbrynet/core/Error.py | 4 ++++ lbrynet/core/Wallet.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lbrynet/core/Error.py b/lbrynet/core/Error.py index c9a4f84d4..02316d6d2 100644 --- a/lbrynet/core/Error.py +++ b/lbrynet/core/Error.py @@ -62,6 +62,10 @@ class UnknownURI(Exception): Exception.__init__(self, 'URI {} cannot be resolved'.format(uri)) self.name = uri +class UnknownOutpoint(Exception): + def __init__(self, outpoint): + Exception.__init__(self, 'Outpoint {} cannot be resolved'.format(outpoint)) + self.outpoint = outpoint class InvalidName(Exception): def __init__(self, name, invalid_characters): diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 04f4ce0e5..619453740 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -28,7 +28,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet from lbrynet.core.client.ClientRequest import ClientRequest from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError -from lbrynet.core.Error import UnknownClaimID, UnknownURI, NegativeFundsError +from lbrynet.core.Error import UnknownClaimID, UnknownURI, NegativeFundsError, UnknownOutpoint log = logging.getLogger(__name__) @@ -772,6 +772,8 @@ class Wallet(object): 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',...}} @@ -849,7 +851,7 @@ class Wallet(object): claim = yield self._get_claim_by_outpoint(txid, nout) try: result = yield self._handle_claim_result(claim) - except (UnknownNameError, UnknownClaimID, UnknownURI) as err: + except (UnknownOutpoint) as err: result = {'error': err.message} else: result = cached_claim From 7072362fd7328b3e897768ff0f5ee82a0eac4664 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 14 Jul 2017 17:20:26 -0400 Subject: [PATCH 6/6] add changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc31eba74..3f6d9f817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,12 +14,12 @@ at anytime. * Added an option to disable max key fee check. ### Changed - * + * claim_show API command no longer takes name as argument * ### Fixed * Fix for https://github.com/lbryio/lbry/issues/750 - * + * Fixed inconsistencies in claim_show output * Fixed daemon process hanging when started without an internet connection * Fixed https://github.com/lbryio/lbry/issues/774