MCPcopy Create free account
hub / github.com/d1ll0n/stack-packer / getCallFunction

Function getCallFunction

src/code-gen/functions.ts:290–317  ·  view source on GitHub ↗
(fn: AbiFunction, context: FileContext)

Source from the content-addressed store, hash-verified

288}
289
290export 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

Callers

nothing calls this directly

Calls 6

toTypeNameFunction · 0.90
toHexFunction · 0.90
buildFunctionBlockFunction · 0.90
buildAssemblyBlockFunction · 0.90
addConstantMethod · 0.80
toPascalCaseMethod · 0.80

Tested by

no test coverage detected