mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
prefer confirmed but allow spending unconfirmed with sqlite coin chooser
This commit is contained in:
parent
c7e0e9f085
commit
5d5cd3499a
1 changed files with 15 additions and 0 deletions
|
@ -491,12 +491,27 @@ def get_spendable_utxos(transaction: sqlite3.Connection, accounts: List, reserve
|
||||||
reserved = []
|
reserved = []
|
||||||
while accumulated < reserve_amount:
|
while accumulated < reserve_amount:
|
||||||
found_txs = False
|
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)):
|
for row in transaction.execute(txo_query, (floor, floor * multiplier, *accounts)):
|
||||||
(txid, txoid, raw, height, nout, verified, amount) = row.values()
|
(txid, txoid, raw, height, nout, verified, amount) = row.values()
|
||||||
found_txs = True
|
found_txs = True
|
||||||
if txid not in decoded_transactions:
|
if txid not in decoded_transactions:
|
||||||
decoded_transactions[txid] = Transaction(raw)
|
decoded_transactions[txid] = Transaction(raw)
|
||||||
decoded_tx = decoded_transactions[txid]
|
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 += amount
|
||||||
accumulated -= Input.spend(decoded_tx.outputs[nout]).size * fee_per_byte
|
accumulated -= Input.spend(decoded_tx.outputs[nout]).size * fee_per_byte
|
||||||
txs[(raw, height, verified)].append(nout)
|
txs[(raw, height, verified)].append(nout)
|
||||||
|
|
Loading…
Add table
Reference in a new issue