(key, values, forceUnique)
| 372 | } |
| 373 | // Find an event definition by any means necessary (unless it is ambiguous) |
| 374 | #getEvent(key, values, forceUnique) { |
| 375 | // EventTopic |
| 376 | if (isHexString(key)) { |
| 377 | const eventTopic = key.toLowerCase(); |
| 378 | for (const fragment of this.#events.values()) { |
| 379 | if (eventTopic === fragment.topicHash) { |
| 380 | return fragment; |
| 381 | } |
| 382 | } |
| 383 | return null; |
| 384 | } |
| 385 | // It is a bare name, look up the function (will return null if ambiguous) |
| 386 | if (key.indexOf("(") === -1) { |
| 387 | const matching = []; |
| 388 | for (const [name, fragment] of this.#events) { |
| 389 | if (name.split("(" /* fix:) */)[0] === key) { |
| 390 | matching.push(fragment); |
| 391 | } |
| 392 | } |
| 393 | if (values) { |
| 394 | // Remove all matches that don't have a compatible length. |
| 395 | for (let i = matching.length - 1; i >= 0; i--) { |
| 396 | if (matching[i].inputs.length < values.length) { |
| 397 | matching.splice(i, 1); |
| 398 | } |
| 399 | } |
| 400 | // Remove all matches that don't match the Typed signature |
| 401 | for (let i = matching.length - 1; i >= 0; i--) { |
| 402 | const inputs = matching[i].inputs; |
| 403 | for (let j = 0; j < values.length; j++) { |
| 404 | // Not a typed value |
| 405 | if (!Typed.isTyped(values[j])) { |
| 406 | continue; |
| 407 | } |
| 408 | // Make sure the value type matches the input type |
| 409 | if (values[j].type !== inputs[j].baseType) { |
| 410 | matching.splice(i, 1); |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | if (matching.length === 0) { |
| 417 | return null; |
| 418 | } |
| 419 | if (matching.length > 1 && forceUnique) { |
| 420 | const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); |
| 421 | assertArgument(false, `ambiguous event description (i.e. matches ${matchStr})`, "key", key); |
| 422 | } |
| 423 | return matching[0]; |
| 424 | } |
| 425 | // Normalize the signature and lookup the function |
| 426 | const result = this.#events.get(EventFragment.from(key).format()); |
| 427 | if (result) { |
| 428 | return result; |
| 429 | } |
| 430 | return null; |
| 431 | } |
no test coverage detected