Skip to content

Commit

Permalink
Refactor Redeemer handling in TransactionWitnessSet
Browse files Browse the repository at this point in the history
  • Loading branch information
bhatt-deep committed Sep 11, 2024
1 parent 05b150d commit ea03c63
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pycardano/witness.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
RawPlutusData,
Redeemer,
Redeemers,
RedeemerMap,
RedeemerKey,
RedeemerValue,
ExecutionUnits,
RedeemerTag,
)
from pycardano.serialization import (
ArrayCBORSerializable,
Expand Down Expand Up @@ -116,11 +121,19 @@ def _get_plutus_v2_scripts(data: Any):
return [PlutusV2Script(script) for script in data] if data else None

def _get_redeemers(data: Any):
return (
[Redeemer.from_primitive(redeemer) for redeemer in data]
if data
else None
)
if not data:
return None
if isinstance(data, dict):
redeemer_map = RedeemerMap()
for (tag, index), value in data.items():
key = RedeemerKey(RedeemerTag(tag), index)
redeemer_value = RedeemerValue(value[0], ExecutionUnits(*value[1]))
redeemer_map[key] = redeemer_value
return redeemer_map
elif isinstance(data, list):
return [Redeemer.from_primitive(redeemer) for redeemer in data]
else:
raise ValueError(f"Unexpected redeemer data format: {type(data)}")

def _get_cls(data: Any):
return cls(
Expand Down

0 comments on commit ea03c63

Please sign in to comment.