From 4e8d8dfc23d3845f99dfa4dfe6266f15c9abf7d5 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Tue, 8 Aug 2017 12:37:28 -0400 Subject: [PATCH 1/3] Expose abandon by txid/nout in Daemon --- lbrynet/core/Wallet.py | 13 +++++++------ lbrynet/daemon/Daemon.py | 13 ++++++++++--- tests/unit/core/test_Wallet.py | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index c7de21d29..a49b6751b 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -951,11 +951,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) @@ -1088,7 +1089,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): @@ -1371,9 +1372,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 diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index fc96f5ebf..890e1c791 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1858,12 +1858,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_abandon [ | --claim_id=] + [ | --txid=] [ | --nout=] Return: (dict) Dictionary containing result of the claim @@ -1872,9 +1873,15 @@ 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) + abandon_claim_tx = yield self.session.wallet.abandon_claim(claim_id, txid, nout) self.analytics_manager.send_claim_action('abandon') response = yield self._render_response(abandon_claim_tx) except BaseException as err: diff --git a/tests/unit/core/test_Wallet.py b/tests/unit/core/test_Wallet.py index 0cfbd89d4..4b9bb6527 100644 --- a/tests/unit/core/test_Wallet.py +++ b/tests/unit/core/test_Wallet.py @@ -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 From 7a2f6079983844ab811c8c67b20877df66ed2597 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Tue, 8 Aug 2017 13:54:25 -0400 Subject: [PATCH 2/3] no need to catch exception when abandoning in Daemon --- lbrynet/daemon/Daemon.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 890e1c791..5bd82d914 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -1880,18 +1880,9 @@ class Daemon(AuthJSONRPCServer): 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, txid, nout) - 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 From b10d7c0923f282529547454514a5a64e1539e53d Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Tue, 8 Aug 2017 13:55:57 -0400 Subject: [PATCH 3/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25705ade7..173323c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 *