Merge pull request #730 from lbryio/fix_claim_show_args

Fix claim_show (API change)
This commit is contained in:
Jack Robison 2017-07-17 14:08:08 -04:00 committed by GitHub
commit 9b49d3592e
4 changed files with 45 additions and 33 deletions

View file

@ -14,12 +14,12 @@ at anytime.
* Added an option to disable max key fee check. * Added an option to disable max key fee check.
### Changed ### Changed
* * claim_show API command no longer takes name as argument
* *
### Fixed ### Fixed
* Fix for https://github.com/lbryio/lbry/issues/750 * 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 daemon process hanging when started without an internet connection
* Fixed https://github.com/lbryio/lbry/issues/774 * Fixed https://github.com/lbryio/lbry/issues/774

View file

@ -62,6 +62,10 @@ class UnknownURI(Exception):
Exception.__init__(self, 'URI {} cannot be resolved'.format(uri)) Exception.__init__(self, 'URI {} cannot be resolved'.format(uri))
self.name = 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): class InvalidName(Exception):
def __init__(self, name, invalid_characters): def __init__(self, name, invalid_characters):

View file

@ -28,7 +28,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked
from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet from lbrynet.interfaces import IRequestCreator, IQueryHandlerFactory, IQueryHandler, IWallet
from lbrynet.core.client.ClientRequest import ClientRequest from lbrynet.core.client.ClientRequest import ClientRequest
from lbrynet.core.Error import RequestCanceledError, InsufficientFundsError, UnknownNameError 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__) log = logging.getLogger(__name__)
@ -693,18 +693,18 @@ class Wallet(object):
defer.returnValue(results) defer.returnValue(results)
@defer.inlineCallbacks @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) cached_claim = yield self.get_cached_claim(claim_id, check_expire)
if cached_claim: if cached_claim:
result = cached_claim result = cached_claim
else: else:
log.debug("Refreshing cached claim: %s", claim_id) log.debug("Refreshing cached claim: %s", claim_id)
claim = yield self._get_claim_by_claimid(claim_id) claim = yield self._get_claim_by_claimid(claim_id)
result = None try:
if claim:
result = yield self._handle_claim_result(claim) result = yield self._handle_claim_result(claim)
else: except (UnknownNameError, UnknownClaimID, UnknownURI) as err:
log.warning("Claim does not exist: %s", claim_id) result = {'error': err.message}
defer.returnValue(result) defer.returnValue(result)
@defer.inlineCallbacks @defer.inlineCallbacks
@ -760,7 +760,9 @@ class Wallet(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def _handle_claim_result(self, results, update_caches=True): def _handle_claim_result(self, results, update_caches=True):
if not results: 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 'error' in results:
if results['error'] in ['name is not claimed', 'claim not found']: if results['error'] in ['name is not claimed', 'claim not found']:
@ -770,6 +772,8 @@ class Wallet(object):
raise UnknownNameError(results['name']) raise UnknownNameError(results['name'])
elif 'uri' in results: elif 'uri' in results:
raise UnknownURI(results['uri']) raise UnknownURI(results['uri'])
elif 'outpoint' in results:
raise UnknownOutpoint(results['outpoint'])
raise Exception(results['error']) raise Exception(results['error'])
# case where return value is {'certificate:{'txid', 'value',...}} # case where return value is {'certificate:{'txid', 'value',...}}
@ -847,7 +851,7 @@ class Wallet(object):
claim = yield self._get_claim_by_outpoint(txid, nout) claim = yield self._get_claim_by_outpoint(txid, nout)
try: try:
result = yield self._handle_claim_result(claim) result = yield self._handle_claim_result(claim)
except (UnknownNameError, UnknownClaimID, UnknownURI) as err: except (UnknownOutpoint) as err:
result = {'error': err.message} result = {'error': err.message}
else: else:
result = cached_claim result = cached_claim

View file

@ -44,7 +44,7 @@ from lbrynet.core.looping_call_manager import LoopingCallManager
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.Error import InsufficientFundsError, UnknownNameError, NoSuchSDHash 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 from lbrynet.core.Error import NullFundsError, NegativeFundsError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -836,7 +836,8 @@ class Daemon(AuthJSONRPCServer):
size = None size = None
message = 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: if claim and 'value' in claim:
metadata = claim['value'] metadata = claim['value']
@ -1314,22 +1315,23 @@ class Daemon(AuthJSONRPCServer):
defer.returnValue(metadata) defer.returnValue(metadata)
@defer.inlineCallbacks @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 Resolve claim info from txid/nout or with claim ID
Usage: Usage:
claim_show <name> [<txid> | --txid=<txid>] [<nout> | --nout=<nout>] claim_show [<txid> | --txid=<txid>] [<nout> | --nout=<nout>]
[<claim_id> | --claim_id=<claim_id>] [<claim_id> | --claim_id=<claim_id>]
Options: Options:
<txid>, --txid=<txid> : look for claim with this txid <txid>, --txid=<txid> : look for claim with this txid, nout must
<nout>, --nout=<nout> : look for claim with this nout also be specified
<nout>, --nout=<nout> : look for claim with this nout, txid must
also be specified
<claim_id>, --claim_id=<claim_id> : look for claim with this claim id <claim_id>, --claim_id=<claim_id> : look for claim with this claim id
Returns: Returns:
(dict) Dictionary contaning claim info, (bool) false if claim is not (dict) Dictionary containing claim info as below,
resolvable
{ {
'txid': (str) txid of claim 'txid': (str) txid of claim
@ -1340,20 +1342,22 @@ class Daemon(AuthJSONRPCServer):
'claim_id': (str) claim ID of claim 'claim_id': (str) claim ID of claim
'supports': (list) list of supports associated with 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
}
""" """
try: if claim_id is not None and txid is None and nout is None:
if claim_id: claim_results = yield self.session.wallet.get_claim_by_claim_id(claim_id)
claim_results = yield self.session.wallet.get_claim(claim_id) elif txid is not None and nout is not None and claim_id is None:
elif txid and nout is not None:
outpoint = ClaimOutpoint(txid, nout) outpoint = ClaimOutpoint(txid, nout)
claim_results = yield self.session.wallet.get_claim_by_outpoint(outpoint) claim_results = yield self.session.wallet.get_claim_by_outpoint(outpoint)
else: else:
claim_results = yield self.session.wallet.resolve(name) raise Exception("Must specify either txid/nout, or claim_id")
if claim_results:
claim_results = claim_results[name]
result = format_json_out_amount_as_float(claim_results) result = format_json_out_amount_as_float(claim_results)
except (TypeError, UnknownNameError, UnknownClaimID, UnknownURI):
result = False
response = yield self._render_response(result) response = yield self._render_response(result)
defer.returnValue(response) defer.returnValue(response)