Change sql to use less code

This commit is contained in:
hackrush 2018-09-19 21:57:53 +05:30 committed by Lex Berezhny
parent 5cc0d365c2
commit f5789775a2

View file

@ -86,23 +86,19 @@ class WalletDatabase(BaseDatabase):
@defer.inlineCallbacks @defer.inlineCallbacks
def get_claim(self, account, claim_id=None, txid=None, nout=None): def get_claim(self, account, claim_id=None, txid=None, nout=None):
if claim_id is not None: if claim_id is not None:
utxos = yield self.db.runQuery( filter_sql = "claim_id=?"
""" filter_value = (claim_id,)
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: else:
utxos = yield self.db.runQuery( filter_sql = "txo.txid=? AND position=?"
""" filter_value = (txid, nout)
SELECT amount, script, txo.txid, position utxos = yield self.db.runQuery(
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) SELECT amount, script, txo.txid, position
ORDER BY tx.height DESC LIMIT 1; FROM txo JOIN tx ON tx.txid=txo.txid
""", (txid, nout) 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 output_class = account.ledger.transaction_class.output_class
defer.returnValue([ defer.returnValue([
output_class( output_class(