@@ -608,10 +608,12 @@ def build(self, change_address: Optional[Address] = None) -> TransactionBody:
608
608
# When there are positive coin or native asset quantity in unfulfilled Value
609
609
if Value () < unfulfilled_amount :
610
610
additional_utxo_pool = []
611
+ additional_amount = Value ()
611
612
for address in self .input_addresses :
612
613
for utxo in self .context .utxos (str (address )):
613
614
if utxo not in selected_utxos and utxo not in self .excluded_inputs :
614
615
additional_utxo_pool .append (utxo )
616
+ additional_amount += utxo .output .amount
615
617
616
618
for i , selector in enumerate (self .utxo_selectors ):
617
619
try :
@@ -631,7 +633,28 @@ def build(self, change_address: Optional[Address] = None) -> TransactionBody:
631
633
logger .info (e )
632
634
logger .info (f"{ selector } failed. Trying next selector." )
633
635
else :
634
- raise UTxOSelectionException ("All UTxO selectors failed." )
636
+ trimmed_additional_amount = Value (
637
+ additional_amount .coin ,
638
+ additional_amount .multi_asset .filter (
639
+ lambda p , n , v : p in requested_amount .multi_asset
640
+ and n in requested_amount .multi_asset [p ]
641
+ ),
642
+ )
643
+ diff = (
644
+ requested_amount
645
+ - trimmed_selected_amount
646
+ - trimmed_additional_amount
647
+ )
648
+ diff .multi_asset = diff .multi_asset .filter (
649
+ lambda p , n , v : v > 0
650
+ )
651
+ raise UTxOSelectionException (
652
+ f"All UTxO selectors failed.\n "
653
+ f"Requested output:\n { requested_amount } \n "
654
+ f"Pre-selected inputs:\n { selected_amount } \n "
655
+ f"Additional UTxO pool:\n { additional_utxo_pool } \n "
656
+ f"Unfulfilled amount:\n { diff } "
657
+ )
635
658
636
659
selected_utxos .sort (
637
660
key = lambda utxo : (str (utxo .input .transaction_id ), utxo .input .index )
0 commit comments