(fn: AbiFunction, context: FileContext)
| 288 | } |
| 289 | |
| 290 | export function getCallFunction(fn: AbiFunction, context: FileContext): ArrayJoinInput<string> { |
| 291 | const {input, output} = fn |
| 292 | const signature = `${fn.name}(${input.fields.map(f => toTypeName(f.type)).join(',')})`; |
| 293 | const selector = `0x${keccak256(signature).slice(0, 4).toString('hex')}`.padEnd(66, '0'); |
| 294 | let offset = 4; |
| 295 | const selectorReference = context.addConstant(`${fn.name}_selector`, selector); |
| 296 | const lines: string[] = [ |
| 297 | `mstore(0, ${selectorReference})` |
| 298 | ]; |
| 299 | for (let field of input.fields) { |
| 300 | const offsetRef = context.addConstant(`${fn.name}_${field.name}_ptr`, toHex(offset)); |
| 301 | lines.push(`mstore(${offsetRef}, ${field.name})`); |
| 302 | offset += 32; |
| 303 | } |
| 304 | const lengthReference = context.addConstant(`${fn.name}_calldata_${input.dynamic ? 'baseLength' : 'length'}`, toHex(offset)) |
| 305 | // lines.push(`revert(0, ${lengthReference})`) |
| 306 | lines.push(`call(target, gasleft(), 0, ${lengthReference}, 0, 0)`) |
| 307 | const fnBlock = buildFunctionBlock( |
| 308 | `call${fn.name.toPascalCase()}`, |
| 309 | [ |
| 310 | `address target`, |
| 311 | ...input.fields.map((field) => `${toTypeName(field.type)} ${field.name}`) |
| 312 | ], |
| 313 | [], |
| 314 | buildAssemblyBlock(lines) |
| 315 | ); |
| 316 | return fnBlock |
| 317 | } |
| 318 | |
| 319 | // function get |
nothing calls this directly
no test coverage detected