From 16c340e3539715e4407c2febcaf4095c63dcd3a9 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 11 Dec 2024 11:45:03 +0000 Subject: [PATCH] chore: rollback to working state --- packages/abi/src/parser/index.ts | 2 +- .../specifications/v1/resolvable-type.ts | 42 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/packages/abi/src/parser/index.ts b/packages/abi/src/parser/index.ts index 1d0b7a7f86b..52984dcec05 100644 --- a/packages/abi/src/parser/index.ts +++ b/packages/abi/src/parser/index.ts @@ -1,3 +1,3 @@ -export { AbiParser } from './abi-parser'; +export { AbiParser, AbiSpecification } from './abi-parser'; export * from './abi'; export * from './specifications/v1/specification'; diff --git a/packages/abi/src/parser/specifications/v1/resolvable-type.ts b/packages/abi/src/parser/specifications/v1/resolvable-type.ts index 9a5c2739c40..dc6ee18ecba 100644 --- a/packages/abi/src/parser/specifications/v1/resolvable-type.ts +++ b/packages/abi/src/parser/specifications/v1/resolvable-type.ts @@ -29,11 +29,7 @@ export class ResolvableType { ) { this.metadataType = this.findMetadataType(metadataTypeId); this.swayType = this.metadataType.type; - this.typeParamsArgsMap ??= this.metadataType.typeParameters?.map((typeParameter) => [ - typeParameter, - new ResolvableType(this.abi, typeParameter, undefined), - ]); - + this.typeParamsArgsMap ??= this.mapTypeParametersAndArgs(this.metadataType, undefined); let components = this.metadataType.components; /** @@ -47,7 +43,10 @@ export class ResolvableType { if (swayTypeMatchers.vector(this.metadataType.type)) { components = components?.map((component) => { if (component.name === 'buf') { - return component.typeArguments?.[0]; + return { + ...component.typeArguments?.[0], + name: component.name, + }; } return component; }) as AbiComponentV1[]; @@ -112,8 +111,15 @@ export class ResolvableType { private mapTypeParametersAndArgs( metadataType: AbiMetadataTypeV1, - args: (ResolvableType | ResolvedType)[] + args: (ResolvableType | ResolvedType)[] | undefined ): Array<[number, ResolvedType | ResolvableType]> | undefined { + if (!args) { + return metadataType.typeParameters?.map((typeParameter) => [ + typeParameter, + new ResolvableType(this.abi, typeParameter, undefined), + ]); + } + return metadataType.typeParameters?.map((typeParameter, idx) => [typeParameter, args[idx]]); } @@ -223,17 +229,6 @@ export class ResolvableType { (typeArgument) => this.handleComponent(parent, typeArgument).type ); - /** - * If there are no type arguments because the metadata type isn't generic, - * we can resolve it immediately. - * This would be the case for e.g. non-generic structs and enums. - */ - if (!typeArgs?.length) { - return new ResolvableType(this.abi, metadataType.metadataTypeId, undefined).resolveInternal( - metadataType.metadataTypeId, - undefined - ); - } const resolvable = new ResolvableType( this.abi, metadataType.metadataTypeId, @@ -247,7 +242,7 @@ export class ResolvableType { * then this check will resolve to `false` because there are no concrete type arguments * to resolve the generics with. */ - if (typeArgs.every((ta) => ta instanceof ResolvedType)) { + if (typeArgs?.every((typeArgument) => typeArgument instanceof ResolvedType)) { return resolvable.resolveInternal(metadataType.metadataTypeId, undefined); } @@ -322,11 +317,10 @@ export class ResolvableType { return this.resolveConcreteType(concreteTypeArg); }); - const typeParamsArgsMap = concreteTypeArgs?.length - ? (this.mapTypeParametersAndArgs(this.metadataType, concreteTypeArgs) as Array< - [number, ResolvedType] - >) - : undefined; + const typeParamsArgsMap = this.mapTypeParametersAndArgs( + this.metadataType, + concreteTypeArgs + ) as Array<[number, ResolvedType]>; return this.resolveInternal(concreteType.concreteTypeId, typeParamsArgsMap); }