* Create a new Interface for the %%fragments%%.
(fragments)
| 228 | * Create a new Interface for the %%fragments%%. |
| 229 | */ |
| 230 | constructor(fragments) { |
| 231 | let abi = []; |
| 232 | if (typeof (fragments) === "string") { |
| 233 | abi = JSON.parse(fragments); |
| 234 | } |
| 235 | else { |
| 236 | abi = fragments; |
| 237 | } |
| 238 | this.#functions = new Map(); |
| 239 | this.#errors = new Map(); |
| 240 | this.#events = new Map(); |
| 241 | // this.#structs = new Map(); |
| 242 | const frags = []; |
| 243 | for (const a of abi) { |
| 244 | try { |
| 245 | frags.push(Fragment.from(a)); |
| 246 | } |
| 247 | catch (error) { |
| 248 | console.log(`[Warning] Invalid Fragment ${JSON.stringify(a)}:`, error.message); |
| 249 | } |
| 250 | } |
| 251 | defineProperties(this, { |
| 252 | fragments: Object.freeze(frags) |
| 253 | }); |
| 254 | let fallback = null; |
| 255 | let receive = false; |
| 256 | this.#abiCoder = this.getAbiCoder(); |
| 257 | // Add all fragments by their signature |
| 258 | this.fragments.forEach((fragment, index) => { |
| 259 | let bucket; |
| 260 | switch (fragment.type) { |
| 261 | case "constructor": |
| 262 | if (this.deploy) { |
| 263 | console.log("duplicate definition - constructor"); |
| 264 | return; |
| 265 | } |
| 266 | //checkNames(fragment, "input", fragment.inputs); |
| 267 | defineProperties(this, { deploy: fragment }); |
| 268 | return; |
| 269 | case "fallback": |
| 270 | if (fragment.inputs.length === 0) { |
| 271 | receive = true; |
| 272 | } |
| 273 | else { |
| 274 | assertArgument(!fallback || fragment.payable !== fallback.payable, "conflicting fallback fragments", `fragments[${index}]`, fragment); |
| 275 | fallback = fragment; |
| 276 | receive = fallback.payable; |
| 277 | } |
| 278 | return; |
| 279 | case "function": |
| 280 | //checkNames(fragment, "input", fragment.inputs); |
| 281 | //checkNames(fragment, "output", (<FunctionFragment>fragment).outputs); |
| 282 | bucket = this.#functions; |
| 283 | break; |
| 284 | case "event": |
| 285 | //checkNames(fragment, "input", fragment.inputs); |
| 286 | bucket = this.#events; |
| 287 | break; |
nothing calls this directly
no test coverage detected