Skip to content

Commit c4e06d6

Browse files
committed
Avoid using _CONSTR_ID from parent class by adding class name to _CONSTR_ID
1 parent 9bcea9b commit c4e06d6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pycardano/plutus.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,17 @@ def CONSTR_ID(cls):
476476
The default implementation is an almost unique, deterministic constructor ID in the range 1 - 2^32 based
477477
on class attributes, types and class name.
478478
"""
479-
if not hasattr(cls, "_CONSTR_ID"):
479+
k = f"_CONSTR_ID_{cls.__name__}"
480+
if not hasattr(cls, k):
480481
det_string = (
481482
cls.__name__
482483
+ "*"
483484
+ "*".join([f"{f.name}~{f.type}" for f in fields(cls)])
484485
)
485486
det_hash = sha256(det_string.encode("utf8")).hexdigest()
486-
setattr(cls, "_CONSTR_ID", int(det_hash, 16) % 2**32)
487+
setattr(cls, k, int(det_hash, 16) % 2**32)
487488

488-
return cls._CONSTR_ID
489+
return getattr(cls, k)
489490

490491
def __post_init__(self):
491492
valid_types = (PlutusData, dict, IndefiniteList, int, bytes)

0 commit comments

Comments
 (0)