(abi: RawAbiDefinition[], path: string, documentation?: DocumentationResult)
| 146 | } |
| 147 | |
| 148 | export function parse(abi: RawAbiDefinition[], path: string, documentation?: DocumentationResult): Contract { |
| 149 | const constructors: FunctionWithoutOutputDeclaration[] = [] |
| 150 | let fallback: FunctionWithoutInputDeclaration | undefined |
| 151 | const functions: FunctionDeclaration[] = [] |
| 152 | const events: EventDeclaration[] = [] |
| 153 | |
| 154 | const structs: StructType[] = [] |
| 155 | function registerStruct(newStruct: StructType) { |
| 156 | // ignore registration if structName not present |
| 157 | if (newStruct.structName === undefined) return |
| 158 | // if struct array (recursive) then keep going deep until we reach the struct tuple |
| 159 | while (newStruct.type === 'array') { |
| 160 | newStruct = newStruct.itemType as StructType |
| 161 | } |
| 162 | // only register if not already registered |
| 163 | const newStructName = newStruct.structName?.toString() |
| 164 | if (!structs.find((s) => s.structName?.toString() === newStructName)) { |
| 165 | structs.push(newStruct) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | abi.forEach((abiPiece) => { |
| 170 | if (abiPiece.type === 'fallback') { |
| 171 | if (fallback) { |
| 172 | throw new Error( |
| 173 | `Fallback function can't be defined more than once! ${JSON.stringify( |
| 174 | abiPiece, |
| 175 | )} Previously defined: ${JSON.stringify(fallback)}`, |
| 176 | ) |
| 177 | } |
| 178 | fallback = parseFallback(abiPiece, registerStruct) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | if (abiPiece.type === 'constructor') { |
| 183 | constructors.push(parseConstructor(abiPiece, registerStruct)) |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | if (abiPiece.type === 'function') { |
| 188 | functions.push(parseFunctionDeclaration(abiPiece, registerStruct, documentation)) |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | if (abiPiece.type === 'event') { |
| 193 | const eventAbi = abiPiece as any as RawEventAbiDefinition |
| 194 | |
| 195 | events.push(parseEvent(eventAbi, registerStruct)) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | debug(`Unrecognized abi element: ${abiPiece.type}`) |
| 200 | }) |
| 201 | |
| 202 | return { |
| 203 | ...parseContractPath(path), |
| 204 | fallback, |
| 205 | constructor: constructors, |
no test coverage detected
searching dependent graphs…