MCPcopy Index your code
hub / github.com/dethcrypto/TypeChain / parse

Function parse

packages/typechain/src/parser/abiParser.ts:148–211  ·  view source on GitHub ↗
(abi: RawAbiDefinition[], path: string, documentation?: DocumentationResult)

Source from the content-addressed store, hash-verified

146}
147
148export 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,

Callers 9

generation.test.tsFile · 0.90
generation.test.tsFile · 0.90
transformFileMethod · 0.90
transformFileMethod · 0.90
abiParser.test.tsFile · 0.90
getFilenameFunction · 0.85
getFileExtensionFunction · 0.85

Calls 7

parseFallbackFunction · 0.85
parseConstructorFunction · 0.85
parseFunctionDeclarationFunction · 0.85
parseEventFunction · 0.85
parseContractPathFunction · 0.85
pushMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…