diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-03-17 20:07:47 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-03-17 20:48:43 +0100 |
commit | fab61437f68d2fa9c791f09ab6d53e3c7be535e0 (patch) | |
tree | 9d9a9c6404339919d0db5ea433a3aa32bfb84c36 /test | |
parent | bf2c0fb2a26432762bf98e19a98e252b7bdd7d30 (diff) | |
download | bitcoin-fab61437f68d2fa9c791f09ab6d53e3c7be535e0.tar.xz |
test: Refactor MiniWallet get_utxo helper
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/test_framework/wallet.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index dd41a740ae..7e8c43c396 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -8,7 +8,10 @@ from copy import deepcopy from decimal import Decimal from enum import Enum from random import choice -from typing import Optional +from typing import ( + Any, + Optional, +) from test_framework.address import ( base58_to_byte, create_deterministic_address_bcrt1_p2tr_op_true, @@ -144,11 +147,12 @@ class MiniWallet: Args: 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 if txid: - utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos)) - index = self._utxos.index(utxo) + utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos) + else: + utxo_filter = reversed(self._utxos) # By default the largest utxo + index = self._utxos.index(next(utxo_filter)) if mark_as_spent: return self._utxos.pop(index) else: |