Added support to abandon claim using txid and nout

This commit is contained in:
hackrush 2018-09-19 02:48:02 +05:30 committed by Lex Berezhny
parent 5430a0f289
commit 5cc0d365c2
4 changed files with 28 additions and 14 deletions

View file

@ -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])

View file

@ -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)

View file

@ -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(

View file

@ -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