diff --git a/starknet_py/abi/v2/parser.py b/starknet_py/abi/v2/parser.py index ea5d599d6..d7cf42a12 100644 --- a/starknet_py/abi/v2/parser.py +++ b/starknet_py/abi/v2/parser.py @@ -234,6 +234,7 @@ def _parse_event(self, event: EventDict) -> EventType: types=self._parse_members( cast(List[TypedParameterDict], members_), event["name"] ), + keys=self._parse_keys(cast(List[EventStructMemberDict], members_)), ) TypedParam = TypeVar( @@ -250,6 +251,9 @@ def _parse_members( for name, param in members.items() ) + def _parse_keys(self, params: List[EventStructMemberDict]) -> List[str]: + return [param["name"] for param in params if param["kind"] == "key"] + def _parse_interface(self, interface: InterfaceDict) -> Abi.Interface: return Abi.Interface( name=interface["name"], diff --git a/starknet_py/abi/v2/schemas.py b/starknet_py/abi/v2/schemas.py index 091fda132..8af47d2de 100644 --- a/starknet_py/abi/v2/schemas.py +++ b/starknet_py/abi/v2/schemas.py @@ -1,4 +1,4 @@ -from marshmallow import Schema, fields +from marshmallow import Schema, fields, validate from marshmallow_oneofschema.one_of_schema import OneOfSchema from starknet_py.abi.v2.shape import ( @@ -9,6 +9,7 @@ FUNCTION_ENTRY, IMPL_ENTRY, INTERFACE_ENTRY, + KEY_KIND, L1_HANDLER_ENTRY, NESTED_KIND, STRUCT_ENTRY, @@ -51,7 +52,9 @@ class L1HandlerAbiEntrySchema(FunctionBaseSchema): class EventStructMemberSchema(TypedParameterSchema): - kind = fields.Constant(DATA_KIND, data_key="kind", required=True) + kind = fields.String( + validate=validate.OneOf([KEY_KIND, DATA_KIND]), data_key="kind", required=True + ) class EventStructAbiEntrySchema(Schema): diff --git a/starknet_py/abi/v2/shape.py b/starknet_py/abi/v2/shape.py index f26ebe26e..bb7450ec4 100644 --- a/starknet_py/abi/v2/shape.py +++ b/starknet_py/abi/v2/shape.py @@ -11,6 +11,7 @@ IMPL_ENTRY = "impl" INTERFACE_ENTRY = "interface" +KEY_KIND = "key" DATA_KIND = "data" NESTED_KIND = "nested" @@ -56,7 +57,7 @@ class EventBaseDict(TypedDict): class EventStructMemberDict(TypedParameterDict): - kind: Literal["data"] + kind: Literal["data", "key"] class EventStructDict(EventBaseDict): diff --git a/starknet_py/cairo/data_types.py b/starknet_py/cairo/data_types.py index 872a1368a..4c1fc3ba2 100644 --- a/starknet_py/cairo/data_types.py +++ b/starknet_py/cairo/data_types.py @@ -121,3 +121,4 @@ class EventType(CairoType): name: str types: OrderedDict[str, CairoType] + keys: List[str] diff --git a/starknet_py/tests/e2e/fixtures/abi_v2_structures.py b/starknet_py/tests/e2e/fixtures/abi_v2_structures.py index c2ef12a2a..9482a8d62 100644 --- a/starknet_py/tests/e2e/fixtures/abi_v2_structures.py +++ b/starknet_py/tests/e2e/fixtures/abi_v2_structures.py @@ -7,8 +7,7 @@ pool_id_struct = StructType("PoolId", OrderedDict(value=UintType(256))) pool_id_added_event: EventType = EventType( - "PoolIdAdded", - OrderedDict(pool_id=pool_id_struct), + "PoolIdAdded", OrderedDict(pool_id=pool_id_struct), [] ) abi_v2 = Abi( diff --git a/starknet_py/tests/unit/abi/v2/parser_test.py b/starknet_py/tests/unit/abi/v2/parser_test.py index e73865fcb..f2eb89d6c 100644 --- a/starknet_py/tests/unit/abi/v2/parser_test.py +++ b/starknet_py/tests/unit/abi/v2/parser_test.py @@ -22,6 +22,7 @@ "TestEnum", "TestOption", "TokenBridge", + "l1_l2", ], ) def test_abi_parse(contract_name):