@@ -112,6 +112,8 @@ class TransactionBuilder:
112
112
113
113
_inputs : List [UTxO ] = field (init = False , default_factory = lambda : [])
114
114
115
+ _potential_inputs : List [UTxO ] = field (init = False , default_factory = lambda : [])
116
+
115
117
_excluded_inputs : List [UTxO ] = field (init = False , default_factory = lambda : [])
116
118
117
119
_input_addresses : List [Union [Address , str ]] = field (
@@ -331,6 +333,10 @@ def add_output(
331
333
def inputs (self ) -> List [UTxO ]:
332
334
return self ._inputs
333
335
336
+ @property
337
+ def potential_inputs (self ) -> List [UTxO ]:
338
+ return self ._potential_inputs
339
+
334
340
@property
335
341
def excluded_inputs (self ) -> List [UTxO ]:
336
342
return self ._excluded_inputs
@@ -984,21 +990,34 @@ def build(
984
990
lambda p , n , v : v > 0
985
991
)
986
992
993
+ # Create a set of all seen utxos in addition to other utxo lists.
994
+ # We need this set to avoid adding the same utxo twice.
995
+ # The reason of not turning all utxo lists into sets is that we want to keep the order of utxos and make
996
+ # utxo selection deterministic.
997
+ seen_utxos = set (selected_utxos )
998
+
987
999
# When there are positive coin or native asset quantity in unfulfilled Value
988
1000
if Value () < unfulfilled_amount :
989
1001
additional_utxo_pool = []
990
1002
additional_amount = Value ()
1003
+
1004
+ for utxo in self .potential_inputs :
1005
+ additional_amount += utxo .output .amount
1006
+ seen_utxos .add (utxo )
1007
+ additional_utxo_pool .append (utxo )
1008
+
991
1009
for address in self .input_addresses :
992
1010
for utxo in self .context .utxos (address ):
993
1011
if (
994
- utxo not in selected_utxos
1012
+ utxo not in seen_utxos
995
1013
and utxo not in self .excluded_inputs
996
1014
and not utxo .output .datum_hash # UTxO with datum should be added by using `add_script_input`
997
1015
and not utxo .output .datum
998
1016
and not utxo .output .script
999
1017
):
1000
1018
additional_utxo_pool .append (utxo )
1001
1019
additional_amount += utxo .output .amount
1020
+ seen_utxos .add (utxo )
1002
1021
1003
1022
for index , selector in enumerate (self .utxo_selectors ):
1004
1023
try :
0 commit comments