(fn: CodeGenFunction, structStorageName: string, libraryName: string)
| 8 | }) |
| 9 | |
| 10 | function generateExternalFunction(fn: CodeGenFunction, structStorageName: string, libraryName: string) { |
| 11 | // const functionName = `test${fn.name.toPascalCase()}`; |
| 12 | const copyForExternalFunction: CodeGenFunction = { |
| 13 | ...copyFnDef(fn), |
| 14 | location: 'external', |
| 15 | body: [] |
| 16 | // name: functionName |
| 17 | }; |
| 18 | const copyForLibraryCall: CodeGenFunction = copyFnDef(fn); |
| 19 | // let structTypeName: string; |
| 20 | if (fn.internalType === 'setter') { |
| 21 | copyForExternalFunction.visibility = undefined |
| 22 | } else if (fn.internalType === 'getter') { |
| 23 | copyForExternalFunction.visibility = 'view' |
| 24 | } else { |
| 25 | return undefined; |
| 26 | } |
| 27 | |
| 28 | const hasStructInput = fn.inputs[0]?.type.meta === 'struct'; |
| 29 | if (hasStructInput) { |
| 30 | const { name, definition, type } = copyForLibraryCall.inputs[0] |
| 31 | // Change library call's struct name to name of storage variable |
| 32 | copyForLibraryCall.inputs[0].name = structStorageName; |
| 33 | copyForLibraryCall.inputs[0].definition = definition.replace(name, structStorageName); |
| 34 | // Remove struct from external function inputs |
| 35 | copyForExternalFunction.inputs.shift(); |
| 36 | } |
| 37 | const hasStructOutput = fn.outputs[0]?.type.meta === 'struct'; |
| 38 | if (hasStructOutput) { |
| 39 | const { name, definition, type } = copyForLibraryCall.inputs[0] |
| 40 | // structTypeName = (type as AbiStruct).name; |
| 41 | // Change library call's struct name to name of storage variable |
| 42 | copyForLibraryCall.outputs[0].name = structStorageName; |
| 43 | copyForLibraryCall.outputs[0].definition = definition.replace(name, structStorageName); |
| 44 | // Remove struct from external function outputs |
| 45 | copyForExternalFunction.outputs.shift(); |
| 46 | } |
| 47 | // const externalFunctionCode = generateFunctionCode() |
| 48 | copyForExternalFunction.body = generateInternalLibraryCall(copyForLibraryCall, libraryName); |
| 49 | return copyForExternalFunction; |
| 50 | } |
| 51 | |
| 52 | export function generateExternalCoder( |
| 53 | functions: CodeGenFunction[], |
no test coverage detected