Skip to content

Commit 793e861

Browse files
committed
fix txbuilder remaining multi asset amount
1 parent 4e3f4c0 commit 793e861

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

pycardano/txbuilder.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,9 @@ def build(
13501350

13511351
unfulfilled_amount = requested_amount - trimmed_selected_amount
13521352

1353-
can_use_again_multi_asset = unfulfilled_amount.multi_asset.filter(
1354-
lambda p, n, v: v < 0
1355-
)
1356-
can_use_again = Value(
1357-
min(0, unfulfilled_amount.coin) * -1, can_use_again_multi_asset
1358-
)
1353+
remaining = trimmed_selected_amount - requested_amount
1354+
remaining.multi_asset = remaining.multi_asset.filter(lambda p, n, v: v > 0)
1355+
remaining.coin = max(0, remaining.coin)
13591356

13601357
if change_address is not None and not can_merge_change:
13611358
# If change address is provided and remainder is smaller than minimum ADA required in change,
@@ -1415,7 +1412,7 @@ def build(
14151412
self.context,
14161413
include_max_fee=False,
14171414
respect_min_utxo=not can_merge_change,
1418-
existing_amount=can_use_again,
1415+
existing_amount=remaining,
14191416
)
14201417

14211418
for s in selected:

test/pycardano/test_txbuilder.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def test_tx_builder_burn_multi_asset(chain_context):
443443
tx_builder = TransactionBuilder(chain_context)
444444
sender = "addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x"
445445
sender_address: Address = Address.from_primitive(sender)
446-
print("1")
446+
447447
# Add sender address as input
448448
to_burn = MultiAsset.from_primitive({policy_id.payload: {b"Token1": -1}})
449449
tx_input = TransactionInput.from_primitive([b"1" * 32, 123])
@@ -455,13 +455,12 @@ def test_tx_builder_burn_multi_asset(chain_context):
455455
),
456456
)
457457
)
458-
print("2")
458+
459459
tx_builder.add_input_address(sender).add_output(
460460
TransactionOutput.from_primitive([sender, 3000000])
461461
).add_output(TransactionOutput.from_primitive([sender, 2000000]))
462462

463463
tx_builder.mint = to_burn
464-
print("3")
465464
tx_body = tx_builder.build(change_address=sender_address)
466465

467466
assert tx_input in tx_body.inputs
@@ -2401,7 +2400,6 @@ def test_token_transfer_with_change(chain_context):
24012400
),
24022401
)
24032402
tx_builder.add_output(TransactionOutput(receiver_address, output_value))
2404-
# print(tx_builder)
24052403

24062404
# Build transaction with change going back to vault
24072405
tx = tx_builder.build(change_address=vault_address, merge_change=True)

0 commit comments

Comments
 (0)