Expose abandon by txid/nout in Daemon

This commit is contained in:
Kay Kurokawa 2017-08-08 12:37:28 -04:00
parent c7ba901819
commit 4e8d8dfc23
3 changed files with 20 additions and 12 deletions

View file

@ -951,11 +951,12 @@ class Wallet(object):
defer.returnValue(claim) defer.returnValue(claim)
@defer.inlineCallbacks @defer.inlineCallbacks
def abandon_claim(self, claim_id): def abandon_claim(self, claim_id, txid, nout):
claim_out = yield self._abandon_claim(claim_id) claim_out = yield self._abandon_claim(claim_id, txid, nout)
if not claim_out['success']: if not claim_out['success']:
msg = 'Abandon of {} failed: {}'.format(claim_id, claim_out['reason']) msg = 'Abandon of {}/{}:{} failed: {}'.format(
claim_id, txid, nout, claim_out['reason'])
raise Exception(msg) raise Exception(msg)
claim_out = self._process_claim_out(claim_out) claim_out = self._process_claim_out(claim_out)
@ -1088,7 +1089,7 @@ class Wallet(object):
change_address=None): change_address=None):
return defer.fail(NotImplementedError()) return defer.fail(NotImplementedError())
def _abandon_claim(self, claim_id): def _abandon_claim(self, claim_id, txid, nout):
return defer.fail(NotImplementedError()) return defer.fail(NotImplementedError())
def _support_claim(self, name, claim_id, amount): def _support_claim(self, name, claim_id, amount):
@ -1371,9 +1372,9 @@ class LBRYumWallet(Wallet):
defer.returnValue(claim_out) defer.returnValue(claim_out)
@defer.inlineCallbacks @defer.inlineCallbacks
def _abandon_claim(self, claim_id): def _abandon_claim(self, claim_id, txid, nout):
log.debug("Abandon %s" % claim_id) log.debug("Abandon %s" % claim_id)
tx_out = yield self._run_cmd_as_defer_succeed('abandon', claim_id) tx_out = yield self._run_cmd_as_defer_succeed('abandon', claim_id, txid, nout)
defer.returnValue(tx_out) defer.returnValue(tx_out)
@defer.inlineCallbacks @defer.inlineCallbacks

View file

@ -1858,12 +1858,13 @@ class Daemon(AuthJSONRPCServer):
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
@defer.inlineCallbacks @defer.inlineCallbacks
def jsonrpc_claim_abandon(self, claim_id): def jsonrpc_claim_abandon(self, claim_id=None, txid=None, nout=None):
""" """
Abandon a name and reclaim credits from the claim Abandon a name and reclaim credits from the claim
Usage: Usage:
claim_abandon (<claim_id> | --claim_id=<claim_id>) claim_abandon [<claim_id> | --claim_id=<claim_id>]
[<txid> | --txid=<txid>] [<nout> | --nout=<nout>]
Return: Return:
(dict) Dictionary containing result of the claim (dict) Dictionary containing result of the claim
@ -1872,9 +1873,15 @@ class Daemon(AuthJSONRPCServer):
fee : (float) fee paid for the transaction fee : (float) fee paid for the transaction
} }
""" """
if claim_id is None and txid is None and nout is None:
raise Exception('Must specify claim_id, or txid and nout')
if txid is None and nout is not None:
raise Exception('Must specify txid')
if nout is None and txid is not None:
raise Exception('Must specify nout')
try: try:
abandon_claim_tx = yield self.session.wallet.abandon_claim(claim_id) abandon_claim_tx = yield self.session.wallet.abandon_claim(claim_id, txid, nout)
self.analytics_manager.send_claim_action('abandon') self.analytics_manager.send_claim_action('abandon')
response = yield self._render_response(abandon_claim_tx) response = yield self._render_response(abandon_claim_tx)
except BaseException as err: except BaseException as err:

View file

@ -115,7 +115,7 @@ class WalletTest(unittest.TestCase):
return threads.deferToThread(lambda: claim_out) return threads.deferToThread(lambda: claim_out)
MocLbryumWallet._abandon_claim = failed_abandon_claim MocLbryumWallet._abandon_claim = failed_abandon_claim
wallet = MocLbryumWallet() wallet = MocLbryumWallet()
d = wallet.abandon_claim("f43dc06256a69988bdbea09a58c80493ba15dcfa") d = wallet.abandon_claim("f43dc06256a69988bdbea09a58c80493ba15dcfa", None, None)
self.assertFailure(d, Exception) self.assertFailure(d, Exception)
return d return d
@ -131,12 +131,12 @@ class WalletTest(unittest.TestCase):
self.assertEqual(expected_abandon_out['fee'], claim_out['fee']) self.assertEqual(expected_abandon_out['fee'], claim_out['fee'])
self.assertEqual(expected_abandon_out['txid'], claim_out['txid']) self.assertEqual(expected_abandon_out['txid'], claim_out['txid'])
def success_abandon_claim(self, claim_outpoint): def success_abandon_claim(self, claim_outpoint, txid, nout):
return threads.deferToThread(lambda: expected_abandon_out) return threads.deferToThread(lambda: expected_abandon_out)
MocLbryumWallet._abandon_claim = success_abandon_claim MocLbryumWallet._abandon_claim = success_abandon_claim
wallet = MocLbryumWallet() wallet = MocLbryumWallet()
d = wallet.abandon_claim("f43dc06256a69988bdbea09a58c80493ba15dcfa") d = wallet.abandon_claim("f43dc06256a69988bdbea09a58c80493ba15dcfa", None, None)
d.addCallback(lambda claim_out: check_out(claim_out)) d.addCallback(lambda claim_out: check_out(claim_out))
return d return d