From c13d3a0e737c0dfe79ba6abef2df48652881ae77 Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Wed, 18 Dec 2024 18:58:18 +0000 Subject: [PATCH] Support complex types in abi --- src/dipdup/abi/cairo.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/dipdup/abi/cairo.py b/src/dipdup/abi/cairo.py index 6ff66d9d8..82f6366c9 100644 --- a/src/dipdup/abi/cairo.py +++ b/src/dipdup/abi/cairo.py @@ -32,23 +32,32 @@ class CairoAbi(TypedDict): events: list[CairoEventAbi] -def _convert_type(type_: CairoType) -> str: +def _convert_type(type_: CairoType) -> dict: # TODO: Support all types - return { + if type_.__class__.__name__ == 'StructType': + return { + 'type': 'object', + 'properties': { + key: _convert_type(value) + for key, value in type_.types.items() + }, + 'required': tuple(type_.types.keys()), + 'additionalProperties': False, + } + + property_type = { 'FeltType': 'integer', 'UintType': 'integer', 'BoolType': 'boolean', }[type_.__class__.__name__] + return {'type': property_type} def _jsonschema_from_event(event: EventType) -> dict[str, Any]: # TODO: Unpack nested types (starknet.py could do that) return { '$schema': 'http://json-schema.org/draft/2019-09/schema#', - 'type': 'object', - 'properties': {key: {'type': _convert_type(value)} for key, value in event.types.items()}, - 'required': tuple(event.types.keys()), - 'additionalProperties': False, + **_convert_type(event) }