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

Function getOverflowCheck

src/code-gen/functions.ts:208–237  ·  view source on GitHub ↗
(originalFields: ProcessedField[], context: FileContext)

Source from the content-addressed store, hash-verified

206]
207
208export function getOverflowCheck(originalFields: ProcessedField[], context: FileContext): ArrayJoinInput<string> {
209 const fields = originalFields.filter((field) => shouldCheckForOverflow(field));
210 if (fields.length === 0) return [];
211 const overflowConstantReferences = overflowConstants.map(([_name, _constant]) => context.addConstant(_name, _constant))
212 const overflowChecks: { positioned: string; }[] = [];
213 for ( const field of fields) {
214 // const maxSizeName = `MaxUint${field.type.size}`;
215 // const maxSizeHex = getMaxUint(field.type.size)
216 // const maxSizeReference = context.addConstant(maxSizeName, maxSizeHex);
217 overflowChecks.push({ positioned: field.getOverflowCheck(field.name) })
218 }
219 let overflowCondition = toArray(buildNestedAssemblyOr(overflowChecks));
220 prefixFirstString(overflowCondition, 'if ');
221 suffixLastString(overflowCondition, ' {');
222 overflowCondition.push(overflowRevert(overflowConstantReferences));
223 overflowCondition.push("}");
224 if (!context.opts.noComments) {
225 const namesComment = fields.length === 1
226 ? `\`${fields[0].name}\` overflows`
227 : [
228 ...fields
229 .slice(0, -1)
230 .map(({ name }) => `\`${name}\``)
231 .join(", "),
232 ` or \`${fields[fields.length - 1].name}\` overflow`,
233 ].join("");
234 overflowCondition.unshift(`// Revert if ${namesComment}`);
235 }
236 return overflowCondition
237}
238
239export function getThrowFunction(error: AbiError, context: FileContext): ArrayJoinInput<string> {
240 const signature = `${error.name}(${error.fields.map(f => toTypeName(f.type)).join(',')})`;

Callers 1

getEncoderFunction · 0.85

Calls 7

shouldCheckForOverflowFunction · 0.90
toArrayFunction · 0.90
buildNestedAssemblyOrFunction · 0.90
prefixFirstStringFunction · 0.90
suffixLastStringFunction · 0.90
overflowRevertFunction · 0.85
addConstantMethod · 0.80

Tested by

no test coverage detected