From 7702d9c4b51a44098ae5adc3bea87b9022b8f7aa Mon Sep 17 00:00:00 2001 From: PhilippeR26 Date: Thu, 6 Jun 2024 11:17:07 +0200 Subject: [PATCH] refactor: add spec6 types --- src/types/lib/contract/abi.ts | 15 +++++++-------- src/utils/events/index.ts | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/types/lib/contract/abi.ts b/src/types/lib/contract/abi.ts index 9c11821e7..e3dd015ed 100644 --- a/src/types/lib/contract/abi.ts +++ b/src/types/lib/contract/abi.ts @@ -1,3 +1,5 @@ +import type { ENUM_EVENT, EVENT_FIELD, STRUCT_EVENT } from '../../api/rpcspec_0_6/contract'; + /** ABI */ export type Abi = ReadonlyArray; @@ -58,18 +60,15 @@ export type AbiEvents = { [hash: string]: AbiEvent }; // if Cairo 0 then definition of an event export type AbiEvent = CairoEvent | LegacyEvent; -// CairoEvent is CairoEventDefinition type if we have a leaf (end of the arborescence for an event), otherwise a new branch is created. Only for Cairo 1 +// CairoEvent is CairoEventDefinition type if we have a leaf (end of the arborescence for an event), otherwise a new node level is created. Only for Cairo 1 export type CairoEvent = CairoEventDefinition | AbiEvents; -export type CairoEventDefinition = { +export type CairoEventDefinition = STRUCT_EVENT & { name: string; - members: EventEntry[]; - kind: 'struct'; type: 'event'; }; -export type CairoEventVariant = { - kind: 'nested' | 'flat'; +export type CairoEventVariant = ENUM_EVENT & { name: string; type: string; }; @@ -77,6 +76,6 @@ export type CairoEventVariant = { export type LegacyEvent = { name: string; type: 'event'; - data: EventEntry[]; - keys: EventEntry[]; + data: EVENT_FIELD[]; + keys: EVENT_FIELD[]; }; diff --git a/src/utils/events/index.ts b/src/utils/events/index.ts index aba7f0a25..e7fbb919d 100644 --- a/src/utils/events/index.ts +++ b/src/utils/events/index.ts @@ -101,7 +101,7 @@ function getCairo1AbiEvents(abi: Abi) { while (true) { const eventEnum = abiEventsEnums.find((eventE) => eventE.variants.some(findName)); if (typeof eventEnum === 'undefined') break; - const variant: CairoEventVariant = eventEnum.variants.find(findName); + const variant = eventEnum.variants.find(findName); nameList.unshift(variant.name); if (variant.kind === 'flat') flat = true; name = eventEnum.name;