(originalFields: ProcessedField[], context: FileContext)
| 206 | ] |
| 207 | |
| 208 | export 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 | |
| 239 | export function getThrowFunction(error: AbiError, context: FileContext): ArrayJoinInput<string> { |
| 240 | const signature = `${error.name}(${error.fields.map(f => toTypeName(f.type)).join(',')})`; |
no test coverage detected