Skip to content

Commit 3161ef9

Browse files
committed
automatically set redeemer index to last added certificate
1 parent b3ad8e7 commit 3161ef9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pycardano/txbuilder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def add_certificate_script(
396396
redeemer: Optional[Redeemer] = None,
397397
) -> TransactionBuilder:
398398
"""Add a certificate script along with its redeemer to this transaction.
399+
WARNING: The order of operations matters. The index of the redeemer will be set to the index of the last certificate added.
399400
400401
Args:
401402
script (Union[UTxO, PlutusV1Script, PlutusV2Script, PlutusV3Script]): A plutus script.
@@ -410,6 +411,10 @@ def add_certificate_script(
410411
f"Expect the redeemer tag's type to be {RedeemerTag.CERTIFICATE}, "
411412
f"but got {redeemer.tag} instead."
412413
)
414+
assert (
415+
self.certificates is not None and len(self.certificates) >= 1
416+
), "self.certificates is None. redeemer.index needs to be set to the index of the corresponding certificate (defaulting to the last certificate) however no certificates could be found"
417+
redeemer.index = len(self.certificates) - 1
413418
redeemer.tag = RedeemerTag.CERTIFICATE
414419
self._consolidate_redeemer(redeemer)
415420

@@ -924,7 +929,7 @@ def _set_redeemer_index(self):
924929
# Set redeemers' index according to section 4.1 in
925930
# https://hydra.iohk.io/build/13099856/download/1/alonzo-changes.pdf
926931
#
927-
# There is no way to determine
932+
# There is no way to determine certificate index here
928933

929934
if self.mint:
930935
sorted_mint_policies = sorted(self.mint.keys(), key=lambda x: x.to_cbor())

0 commit comments

Comments
 (0)