Skip to content

Commit

Permalink
fix: handling variant and alias types
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Aug 26, 2023
1 parent 1b42c88 commit 09aa3f1
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/codegen/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ export function findInternalType(type: string, typeNamespace: string | null, abi

typeString = parseType(typeString)

const relevantAbitype = findAbiType(typeString, abi)
const aliasType = findAliasType(typeString, abi)

if (relevantAbitype) {
typeString = relevantAbitype
if (aliasType) {
console.log({aliasType})
typeString = aliasType
}

const variantType = findVariantType(typeString, typeNamespace, abi)
Expand All @@ -175,6 +176,12 @@ export function findInternalType(type: string, typeNamespace: string | null, abi
typeString = variantType
}

const relevantAbitype = findAbiType(typeString, abi)

if (relevantAbitype) {
typeString = relevantAbitype
}

return formatInternalType(typeString, typeNamespace, abi)
}

Expand All @@ -195,6 +202,12 @@ export function generateStructClassName(name) {
.join('')
}

function findAliasType(typeString: string, abi: ABI.Def): string | undefined {
const alias = abi.types.find((type) => type.new_type_name === typeString)

return alias?.type
}

function findVariantType(
typeString: string,
namespace: string | null,
Expand All @@ -204,10 +217,18 @@ function findVariantType(
(variant) => variant.name.toLowerCase() === typeString.toLowerCase()
)

if (typeString === 'variant_block_signing_authority_v0') {
console.log({ variants: abi.variants, typeString, abiVariant})
}

if (!abiVariant) {
return
}

console.log({ variants: abi.variants, typeString, abiVariant, returned: abiVariant.types
.map((variant) => formatInternalType(variant, namespace, abi))
.join(' | ') })

return abiVariant.types
.map((variant) => formatInternalType(variant, namespace, abi))
.join(' | ')
Expand Down

0 comments on commit 09aa3f1

Please sign in to comment.