Merge pull request #730 from lbryio/fix_claim_show_args
Fix claim_show (API change)
This commit is contained in:
commit
9b49d3592e
4 changed files with 45 additions and 33 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
@ -693,18 +693,18 @@ 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
|
||||
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
|
||||
|
@ -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']:
|
||||
|
@ -770,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',...}}
|
||||
|
@ -847,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
|
||||
|
|
|
@ -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__)
|
||||
|
@ -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']
|
||||
|
@ -1314,22 +1315,23 @@ 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
|
||||
Resolve claim info from txid/nout or with claim ID
|
||||
|
||||
Usage:
|
||||
claim_show <name> [<txid> | --txid=<txid>] [<nout> | --nout=<nout>]
|
||||
[<claim_id> | --claim_id=<claim_id>]
|
||||
claim_show [<txid> | --txid=<txid>] [<nout> | --nout=<nout>]
|
||||
[<claim_id> | --claim_id=<claim_id>]
|
||||
|
||||
Options:
|
||||
<txid>, --txid=<txid> : look for claim with this txid
|
||||
<nout>, --nout=<nout> : look for claim with this nout
|
||||
<txid>, --txid=<txid> : look for claim with this txid, nout must
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -1340,20 +1342,22 @@ 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
|
||||
}
|
||||
|
||||
"""
|
||||
try:
|
||||
if claim_id:
|
||||
claim_results = yield self.session.wallet.get_claim(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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue