(key: string, values: null | Array<null | any | Typed>, forceUnique: boolean)
| 582 | |
| 583 | // Find an event definition by any means necessary (unless it is ambiguous) |
| 584 | #getEvent(key: string, values: null | Array<null | any | Typed>, forceUnique: boolean): null | EventFragment { |
| 585 | |
| 586 | // EventTopic |
| 587 | if (isHexString(key)) { |
| 588 | const eventTopic = key.toLowerCase(); |
| 589 | for (const fragment of this.#events.values()) { |
| 590 | if (eventTopic === fragment.topicHash) { return fragment; } |
| 591 | } |
| 592 | return null; |
| 593 | } |
| 594 | |
| 595 | // It is a bare name, look up the function (will return null if ambiguous) |
| 596 | if (key.indexOf("(") === -1) { |
| 597 | const matching: Array<EventFragment> = [ ]; |
| 598 | for (const [ name, fragment ] of this.#events) { |
| 599 | if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } |
| 600 | } |
| 601 | |
| 602 | if (values) { |
| 603 | // Remove all matches that don't have a compatible length. |
| 604 | for (let i = matching.length - 1; i >= 0; i--) { |
| 605 | if (matching[i].inputs.length < values.length) { |
| 606 | matching.splice(i, 1); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | // Remove all matches that don't match the Typed signature |
| 611 | for (let i = matching.length - 1; i >= 0; i--) { |
| 612 | const inputs = matching[i].inputs; |
| 613 | for (let j = 0; j < values.length; j++) { |
| 614 | // Not a typed value |
| 615 | if (!Typed.isTyped(values[j])) { continue; } |
| 616 | |
| 617 | // Make sure the value type matches the input type |
| 618 | if (values[j].type !== inputs[j].baseType) { |
| 619 | matching.splice(i, 1); |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | if (matching.length === 0) { return null; } |
| 627 | |
| 628 | if (matching.length > 1 && forceUnique) { |
| 629 | const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); |
| 630 | assertArgument(false, `ambiguous event description (i.e. matches ${ matchStr })`, "key", key); |
| 631 | } |
| 632 | |
| 633 | return matching[0]; |
| 634 | } |
| 635 | |
| 636 | // Normalize the signature and lookup the function |
| 637 | const result = this.#events.get(EventFragment.from(key).format()); |
| 638 | if (result) { return result; } |
| 639 | |
| 640 | return null; |
| 641 | } |
no test coverage detected