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

Function getEmitFunction

src/code-gen/functions.ts:263–288  ·  view source on GitHub ↗
(event: AbiEvent, context: FileContext)

Source from the content-addressed store, hash-verified

261}
262
263export function getEmitFunction(event: AbiEvent, context: FileContext): ArrayJoinInput<string> {
264 const topic0 = `0x${keccak256(`${event.name}(${event.fields.map(f => toTypeName(f.type)).join(',')})`).toString('hex')}`;
265 const lines: string[] = [];
266 const topics: string[] = []
267 const topic0Reference = context.addConstant(`${event.name}_topic0`, topic0);
268 topics.push(topic0Reference)
269 let offset = 0;
270 for (let field of event.fields) {
271 if (field.isIndexed) {
272 topics.push(field.name)
273 } else {
274 const offsetRef = context.addConstant(`${event.name}_${field.name}_ptr`, toHex(offset));
275 lines.push(`mstore(${offsetRef}, ${field.name})`);
276 offset += 32;
277 }
278 }
279 const lengthReference = context.addConstant(`${event.name}_length`, toHex(offset))
280 lines.push(`log${topics.length}(0, ${lengthReference}, ${topics.join(', ')})`)
281 const fnBlock = buildFunctionBlock(
282 `emit${event.name}`,
283 event.fields.map((field) => `${toTypeName(field.type)} ${field.name}`),
284 [],
285 buildAssemblyBlock(lines)
286 );
287 return fnBlock
288}
289
290export function getCallFunction(fn: AbiFunction, context: FileContext): ArrayJoinInput<string> {
291 const {input, output} = fn

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected