From f5789775a2f3dfdda3fd1483a6a2a6fc18dc2965 Mon Sep 17 00:00:00 2001 From: hackrush Date: Wed, 19 Sep 2018 21:57:53 +0530 Subject: [PATCH] Change sql to use less code --- lbrynet/wallet/database.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lbrynet/wallet/database.py b/lbrynet/wallet/database.py index 247e41235..61fc6b0b8 100644 --- a/lbrynet/wallet/database.py +++ b/lbrynet/wallet/database.py @@ -86,23 +86,19 @@ class WalletDatabase(BaseDatabase): @defer.inlineCallbacks 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,) - ) + filter_sql = "claim_id=?" + filter_value = (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) - ) + filter_sql = "txo.txid=? AND position=?" + filter_value = (txid, nout) + utxos = yield self.db.runQuery( + """ + SELECT amount, script, txo.txid, position + FROM txo JOIN tx ON tx.txid=txo.txid + WHERE {} AND (is_claim OR is_update) AND txoid NOT IN (SELECT txoid FROM txi) + ORDER BY tx.height DESC LIMIT 1; + """.format(filter_sql), filter_value + ) output_class = account.ledger.transaction_class.output_class defer.returnValue([ output_class(