MCPcopy Create free account
hub / github.com/everx-labs/everdev / parseComponents

Method parseComponents

src/controllers/contract/param-parser.ts:113–151  ·  view source on GitHub ↗
(param: AbiParam)

Source from the content-addressed store, hash-verified

111 }
112
113 parseComponents(param: AbiParam): { [name: string]: any } {
114 const text = this.text.trim()
115 if (text.startsWith("@")) {
116 return loadJSON(path.resolve(process.cwd(), text.substring(1)))
117 }
118
119 if (text.startsWith("{") && text.endsWith("}")) {
120 try {
121 return JSON.parse(text)
122 } catch (err: any) {
123 throw new Error(`Malformed JSON object has been passed`)
124 }
125 }
126
127 const isLetter = (x: string) => x.toLowerCase() !== x.toUpperCase()
128 const isDigit = (x: string) => x >= "0" && x <= "9"
129 const isIdent = (x: string) => isLetter(x) || isDigit(x) || x === "_"
130 const components = param.components ?? []
131 const value: { [name: string]: any } = {}
132
133 while (this.hasMore()) {
134 const name = this.expectIf(isIdent, param, "name")
135 this.expect(":", param)
136 const component = components.find(
137 x => x.name.toLowerCase() === name.toLowerCase(),
138 )
139 if (!component) {
140 throw this.error(`Unknown field ${name}`)
141 }
142 if (param.name in value) {
143 throw new Error(`Field "${name}" already defined.`)
144 }
145 value[name] = this.parseParam(component)
146 if (this.hasMore()) {
147 this.expect(",", param)
148 }
149 }
150 return value
151 }
152
153 private error(message: string) {
154 const text = this.text

Callers 1

componentsMethod · 0.95

Calls 8

hasMoreMethod · 0.95
expectIfMethod · 0.95
expectMethod · 0.95
errorMethod · 0.95
parseParamMethod · 0.95
loadJSONFunction · 0.90
parseMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected