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

Function getThrowFunction

src/code-gen/functions.ts:239–261  ·  view source on GitHub ↗
(error: AbiError, context: FileContext)

Source from the content-addressed store, hash-verified

237}
238
239export function getThrowFunction(error: AbiError, context: FileContext): ArrayJoinInput<string> {
240 const signature = `${error.name}(${error.fields.map(f => toTypeName(f.type)).join(',')})`;
241 const selector = `0x${keccak256(signature).slice(0, 4).toString('hex')}`.padEnd(66, '0');
242 let offset = 4;
243 const selectorReference = context.addConstant(`${error.name}_selector`, selector);
244 const lines: string[] = [
245 `mstore(0, ${selectorReference})`
246 ];
247 for (let field of error.fields) {
248 const offsetRef = context.addConstant(`${error.name}_${field.name}_ptr`, toHex(offset));
249 lines.push(`mstore(${offsetRef}, ${field.name})`);
250 offset += 32;
251 }
252 const lengthReference = context.addConstant(`${error.name}_length`, toHex(offset))
253 lines.push(`revert(0, ${lengthReference})`)
254 const fnBlock = buildFunctionBlock(
255 `throw${error.name}`,
256 error.fields.map((field) => `${toTypeName(field.type)} ${field.name}`),
257 [],
258 buildAssemblyBlock(lines)
259 );
260 return fnBlock
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')}`;

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