5555 Value ,
5656 Withdrawals ,
5757)
58- from pycardano .utils import (
59- fee ,
60- max_tx_fee ,
61- min_lovelace_post_alonzo ,
62- min_lovelace_pre_alonzo ,
63- script_data_hash ,
64- )
58+ from pycardano .utils import fee , max_tx_fee , min_lovelace_post_alonzo , script_data_hash
6559from pycardano .witness import TransactionWitnessSet , VerificationKeyWitness
6660
6761__all__ = ["TransactionBuilder" ]
@@ -436,10 +430,12 @@ def _calc_change(
436430
437431 # when there is only ADA left, simply use remaining coin value as change
438432 if not change .multi_asset :
439- if change .coin < min_lovelace_pre_alonzo (change , self .context ):
433+ if change .coin < min_lovelace_post_alonzo (
434+ TransactionOutput (address , change ), self .context
435+ ):
440436 raise InsufficientUTxOBalanceException (
441437 f"Not enough ADA left for change: { change .coin } but needs "
442- f"{ min_lovelace_pre_alonzo ( change , self .context )} "
438+ f"{ min_lovelace_post_alonzo ( TransactionOutput ( address , change ) , self .context )} "
443439 )
444440 lovelace_change = change .coin
445441 change_output_arr .append (TransactionOutput (address , lovelace_change ))
@@ -456,8 +452,8 @@ def _calc_change(
456452 # Combine remainder of provided ADA with last MultiAsset for output
457453 # There may be rare cases where adding ADA causes size exceeds limit
458454 # We will revisit if it becomes an issue
459- if change .coin < min_lovelace_pre_alonzo (
460- Value (0 , multi_asset ), self .context
455+ if change .coin < min_lovelace_post_alonzo (
456+ TransactionOutput ( address , Value (0 , multi_asset ) ), self .context
461457 ):
462458 raise InsufficientUTxOBalanceException (
463459 "Not enough ADA left to cover non-ADA assets in a change address"
@@ -468,8 +464,8 @@ def _calc_change(
468464 change_value = Value (change .coin , multi_asset )
469465 else :
470466 change_value = Value (0 , multi_asset )
471- change_value .coin = min_lovelace_pre_alonzo (
472- change_value , self .context
467+ change_value .coin = min_lovelace_post_alonzo (
468+ TransactionOutput ( address , change_value ) , self .context
473469 )
474470
475471 change_output_arr .append (TransactionOutput (address , change_value ))
@@ -560,7 +556,9 @@ def _adding_asset_make_output_overflow(
560556 attempt_amount = new_amount + current_amount
561557
562558 # Calculate minimum ada requirements for more precise value size
563- required_lovelace = min_lovelace_pre_alonzo (attempt_amount , self .context )
559+ required_lovelace = min_lovelace_post_alonzo (
560+ TransactionOutput (output .address , attempt_amount ), self .context
561+ )
564562 attempt_amount .coin = required_lovelace
565563
566564 return len (attempt_amount .to_cbor ("bytes" )) > max_val_size
@@ -617,7 +615,9 @@ def _pack_tokens_for_change(
617615
618616 # Calculate min lovelace required for more precise size
619617 updated_amount = deepcopy (output .amount )
620- required_lovelace = min_lovelace_pre_alonzo (updated_amount , self .context )
618+ required_lovelace = min_lovelace_post_alonzo (
619+ TransactionOutput (change_address , updated_amount ), self .context
620+ )
621621 updated_amount .coin = required_lovelace
622622
623623 if len (updated_amount .to_cbor ("bytes" )) > max_val_size :
@@ -903,8 +903,11 @@ def build(
903903 unfulfilled_amount .coin = max (
904904 0 ,
905905 unfulfilled_amount .coin
906- + min_lovelace_pre_alonzo (
907- selected_amount - trimmed_selected_amount , self .context
906+ + min_lovelace_post_alonzo (
907+ TransactionOutput (
908+ change_address , selected_amount - trimmed_selected_amount
909+ ),
910+ self .context ,
908911 ),
909912 )
910913 else :
0 commit comments