Skip to content

Commit a19eb7b

Browse files
committed
update
1 parent 31459b4 commit a19eb7b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/core.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,10 @@ function getFunctionArguments(fnDef: FunctionDefinition, context: ContractDefini
452452
const storageVar = 'v_' + storageType.replace(/[^0-9a-zA-Z$_]+/g, '_');
453453
// The argument is an index to an array in storage.
454454
return { name, type: 'uint256', storageVar, storageType };
455-
} else if (p.typeName?.nodeType == 'UserDefinedTypeName') {
456-
const type = getVarType(p, context, deref, 'calldata');
457-
const udvtType = 'bytes32'; // TODO: Do an actual resolution
458-
return { name, type, udvtType };
459455
} else {
460456
const type = getVarType(p, context, deref, 'calldata');
461-
return { name, type };
457+
const udvtType = getVarUdvtType(p, context, deref, 'calldata');
458+
return { name, type, udvtType };
462459
}
463460
});
464461
}
@@ -513,6 +510,27 @@ function getType(typeName: TypeName, context: ContractDefinition, deref: ASTDere
513510
return type;
514511
}
515512

513+
function getVarUdvtType(varDecl: VariableDeclaration, context: ContractDefinition, deref: ASTDereferencer, location: StorageLocation | null = varDecl.storageLocation): string | undefined {
514+
if (!varDecl.typeName) {
515+
throw new Error('Missing type information');
516+
}
517+
return getUdvtType(varDecl.typeName, context, deref, location);
518+
}
519+
520+
function getUdvtType(typeName: TypeName, context: ContractDefinition, deref: ASTDereferencer, location: StorageLocation | null): string | undefined {
521+
const { typeString, typeIdentifier } = typeName.typeDescriptions;
522+
if (typeof typeString !== 'string' || typeof typeIdentifier !== 'string') {
523+
throw new Error('Missing type information');
524+
}
525+
526+
// TODO: recover UDVT underlying properly
527+
if (typeIdentifier.startsWith('t_userDefinedValueType')) {
528+
return 'bytes32';
529+
} else {
530+
return undefined;
531+
}
532+
}
533+
516534
function getVariables(contract: ContractDefinition, deref: ASTDereferencer, subset?: Visibility[]): VariableDeclaration[] {
517535
const parents = contract.linearizedBaseContracts.map(deref('ContractDefinition'));
518536

0 commit comments

Comments
 (0)