mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
test: Refactor MiniWallet get_utxo helper
This commit is contained in:
parent
bf2c0fb2a2
commit
fab61437f6
1 changed files with 8 additions and 4 deletions
|
@ -8,7 +8,10 @@ from copy import deepcopy
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from random import choice
|
from random import choice
|
||||||
from typing import Optional
|
from typing import (
|
||||||
|
Any,
|
||||||
|
Optional,
|
||||||
|
)
|
||||||
from test_framework.address import (
|
from test_framework.address import (
|
||||||
base58_to_byte,
|
base58_to_byte,
|
||||||
create_deterministic_address_bcrt1_p2tr_op_true,
|
create_deterministic_address_bcrt1_p2tr_op_true,
|
||||||
|
@ -144,11 +147,12 @@ class MiniWallet:
|
||||||
Args:
|
Args:
|
||||||
txid: get the first utxo we find from a specific transaction
|
txid: get the first utxo we find from a specific transaction
|
||||||
"""
|
"""
|
||||||
index = -1 # by default the last utxo
|
|
||||||
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
|
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
|
||||||
if txid:
|
if txid:
|
||||||
utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos))
|
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
|
||||||
index = self._utxos.index(utxo)
|
else:
|
||||||
|
utxo_filter = reversed(self._utxos) # By default the largest utxo
|
||||||
|
index = self._utxos.index(next(utxo_filter))
|
||||||
if mark_as_spent:
|
if mark_as_spent:
|
||||||
return self._utxos.pop(index)
|
return self._utxos.pop(index)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue