prefer confirmed but allow spending unconfirmed with sqlite coin chooser

This commit is contained in:
Jack Robison 2020-05-27 12:27:04 -04:00
parent c7e0e9f085
commit 5d5cd3499a
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -491,12 +491,27 @@ def get_spendable_utxos(transaction: sqlite3.Connection, accounts: List, reserve
reserved = []
while accumulated < reserve_amount:
found_txs = False
# prefer confirmed, but save unconfirmed utxos from this selection in case they are needed
unconfirmed = []
for row in transaction.execute(txo_query, (floor, floor * multiplier, *accounts)):
(txid, txoid, raw, height, nout, verified, amount) = row.values()
found_txs = True
if txid not in decoded_transactions:
decoded_transactions[txid] = Transaction(raw)
decoded_tx = decoded_transactions[txid]
if not verified:
unconfirmed.append((txid, txoid, raw, height, nout, verified, amount))
continue
accumulated += amount
accumulated -= Input.spend(decoded_tx.outputs[nout]).size * fee_per_byte
txs[(raw, height, verified)].append(nout)
reserved.append(txoid)
if accumulated >= reserve_amount:
break
unconfirmed.reverse()
while unconfirmed:
(txid, txoid, raw, height, nout, verified, amount) = unconfirmed.pop()
decoded_tx = decoded_transactions[txid]
accumulated += amount
accumulated -= Input.spend(decoded_tx.outputs[nout]).size * fee_per_byte
txs[(raw, height, verified)].append(nout)