From 5cc0d365c2b92c79a30b97d28a18137aebdd60fb Mon Sep 17 00:00:00 2001 From: hackrush Date: Wed, 19 Sep 2018 02:48:02 +0530 Subject: [PATCH] Added support to abandon claim using txid and nout --- lbrynet/daemon/Daemon.py | 3 +-- lbrynet/wallet/account.py | 4 ++-- lbrynet/wallet/database.py | 28 +++++++++++++++++++--------- lbrynet/wallet/manager.py | 7 ++++++- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 04479d410..429369a44 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2342,8 +2342,8 @@ class Daemon(AuthJSONRPCServer): Returns: (dict) Dictionary containing result of the claim { + success: (bool) True if txn is successful txid : (str) txid of resulting transaction - fee : (float) fee paid for the transaction } """ if claim_id is None and txid is None and nout is None: @@ -2358,7 +2358,6 @@ class Daemon(AuthJSONRPCServer): defer.returnValue({ "success": True, "tx": tx, - "claim_id": claim_id }) @requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED]) diff --git a/lbrynet/wallet/account.py b/lbrynet/wallet/account.py index 89a8e90e2..8a234ac1d 100644 --- a/lbrynet/wallet/account.py +++ b/lbrynet/wallet/account.py @@ -166,5 +166,5 @@ class Account(BaseAccount): details['certificates'] = len(self.certificates) return details - def get_claim(self, claim_id): - return self.ledger.db.get_claim(self, claim_id) + def get_claim(self, claim_id=None, txid=None, nout=None): + return self.ledger.db.get_claim(self, claim_id, txid, nout) diff --git a/lbrynet/wallet/database.py b/lbrynet/wallet/database.py index d57b7c41d..247e41235 100644 --- a/lbrynet/wallet/database.py +++ b/lbrynet/wallet/database.py @@ -84,15 +84,25 @@ class WalletDatabase(BaseDatabase): return certificates @defer.inlineCallbacks - def get_claim(self, account, claim_id): - utxos = yield self.db.runQuery( - """ - SELECT amount, script, txo.txid, position - FROM txo JOIN tx ON tx.txid=txo.txid - WHERE claim_id=? AND (is_claim OR is_update) AND txoid NOT IN (SELECT txoid FROM txi) - ORDER BY tx.height DESC LIMIT 1; - """, (claim_id,) - ) + def get_claim(self, account, claim_id=None, txid=None, nout=None): + if claim_id is not None: + utxos = yield self.db.runQuery( + """ + SELECT amount, script, txo.txid, position + FROM txo JOIN tx ON tx.txid=txo.txid + WHERE claim_id=? AND (is_claim OR is_update) AND txoid NOT IN (SELECT txoid FROM txi) + ORDER BY tx.height DESC LIMIT 1; + """, (claim_id,) + ) + else: + utxos = yield self.db.runQuery( + """ + SELECT amount, script, txo.txid, position + FROM txo JOIN tx ON tx.txid=txo.txid + WHERE txo.txid=? AND position=? AND (is_claim OR is_update) AND txoid NOT IN (SELECT txoid FROM txi) + ORDER BY tx.height DESC LIMIT 1; + """, (txid, nout) + ) output_class = account.ledger.transaction_class.output_class defer.returnValue([ output_class( diff --git a/lbrynet/wallet/manager.py b/lbrynet/wallet/manager.py index 3095e0d96..e31fa0785 100644 --- a/lbrynet/wallet/manager.py +++ b/lbrynet/wallet/manager.py @@ -264,7 +264,12 @@ class LbryWalletManager(BaseWalletManager): @defer.inlineCallbacks def abandon_claim(self, claim_id, txid, nout): account = self.default_account - claim = yield account.get_claim(claim_id) + if claim_id is not None: + claim = yield account.get_claim(claim_id=claim_id) + elif txid is not None and nout is not None: + claim = yield account.get_claim(txid=txid, nout=nout) + else: + raise Exception('Must specify claim_id, or txid and nout') tx = yield Transaction.abandon(claim, [account], account) yield account.ledger.broadcast(tx) # TODO: release reserved tx outputs in case anything fails by this point