55
55
Value ,
56
56
Withdrawals ,
57
57
)
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
65
59
from pycardano .witness import TransactionWitnessSet , VerificationKeyWitness
66
60
67
61
__all__ = ["TransactionBuilder" ]
@@ -436,10 +430,12 @@ def _calc_change(
436
430
437
431
# when there is only ADA left, simply use remaining coin value as change
438
432
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
+ ):
440
436
raise InsufficientUTxOBalanceException (
441
437
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 )} "
443
439
)
444
440
lovelace_change = change .coin
445
441
change_output_arr .append (TransactionOutput (address , lovelace_change ))
@@ -456,8 +452,8 @@ def _calc_change(
456
452
# Combine remainder of provided ADA with last MultiAsset for output
457
453
# There may be rare cases where adding ADA causes size exceeds limit
458
454
# 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
461
457
):
462
458
raise InsufficientUTxOBalanceException (
463
459
"Not enough ADA left to cover non-ADA assets in a change address"
@@ -468,8 +464,8 @@ def _calc_change(
468
464
change_value = Value (change .coin , multi_asset )
469
465
else :
470
466
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
473
469
)
474
470
475
471
change_output_arr .append (TransactionOutput (address , change_value ))
@@ -560,7 +556,9 @@ def _adding_asset_make_output_overflow(
560
556
attempt_amount = new_amount + current_amount
561
557
562
558
# 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
+ )
564
562
attempt_amount .coin = required_lovelace
565
563
566
564
return len (attempt_amount .to_cbor ("bytes" )) > max_val_size
@@ -617,7 +615,9 @@ def _pack_tokens_for_change(
617
615
618
616
# Calculate min lovelace required for more precise size
619
617
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
+ )
621
621
updated_amount .coin = required_lovelace
622
622
623
623
if len (updated_amount .to_cbor ("bytes" )) > max_val_size :
@@ -903,8 +903,11 @@ def build(
903
903
unfulfilled_amount .coin = max (
904
904
0 ,
905
905
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 ,
908
911
),
909
912
)
910
913
else :
0 commit comments