Merge pull request #829 from lbryio/fix_abandon

Expose abandon by txid/nout in Daemon
This commit is contained in:
Umpei Kay Kurokawa 2017-08-14 22:51:39 -04:00 committed by GitHub
commit 34ed2467f2
4 changed files with 23 additions and 23 deletions

View file

@ -16,6 +16,7 @@ at anytime.
* Added `claim_send_tip`, a command to tip the owner of a claim via a support transaction
* Added `reflector` keyword parameter to `file_reflect` command
* Added configuration options for auto re-reflect
* Added option to abandon by txid/nout
### Fixed
* Fixed reflector server blocking the `received_blob` reply on the server announcing the blob to the dht

View file

@ -952,11 +952,12 @@ class Wallet(object):
defer.returnValue(claim)
@defer.inlineCallbacks
def abandon_claim(self, claim_id):
claim_out = yield self._abandon_claim(claim_id)
def abandon_claim(self, claim_id, txid, nout):
claim_out = yield self._abandon_claim(claim_id, txid, nout)
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)
claim_out = self._process_claim_out(claim_out)
@ -1089,7 +1090,7 @@ class Wallet(object):
change_address=None):
return defer.fail(NotImplementedError())
def _abandon_claim(self, claim_id):
def _abandon_claim(self, claim_id, txid, nout):
return defer.fail(NotImplementedError())
def _support_claim(self, name, claim_id, amount):
@ -1372,9 +1373,9 @@ class LBRYumWallet(Wallet):
defer.returnValue(claim_out)
@defer.inlineCallbacks
def _abandon_claim(self, claim_id):
def _abandon_claim(self, claim_id, txid, nout):
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.inlineCallbacks

View file

@ -1867,12 +1867,13 @@ class Daemon(AuthJSONRPCServer):
@AuthJSONRPCServer.auth_required
@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
Usage:
claim_abandon (<claim_id> | --claim_id=<claim_id>)
claim_abandon [<claim_id> | --claim_id=<claim_id>]
[<txid> | --txid=<txid>] [<nout> | --nout=<nout>]
Return:
(dict) Dictionary containing result of the claim
@ -1881,19 +1882,16 @@ class Daemon(AuthJSONRPCServer):
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:
abandon_claim_tx = yield self.session.wallet.abandon_claim(claim_id)
self.analytics_manager.send_claim_action('abandon')
response = yield self._render_response(abandon_claim_tx)
except BaseException as err:
log.warning(err)
# pylint: disable=unsubscriptable-object
if len(err.args) and err.args[0] == "txid was not found in wallet":
raise Exception("This transaction was not found in your wallet")
else:
response = yield self._render_response(err)
defer.returnValue(response)
result = yield self.session.wallet.abandon_claim(claim_id, txid, nout)
self.analytics_manager.send_claim_action('abandon')
defer.returnValue(result)
@AuthJSONRPCServer.auth_required
@defer.inlineCallbacks

View file

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