MCPcopy Create free account
hub / github.com/ccxt/ccxt / #getEvent

Method #getEvent

ts/src/static_dependencies/ethers/interface.ts:584–641  ·  view source on GitHub ↗
(key: string, values: null | Array<null | any | Typed>, forceUnique: boolean)

Source from the content-addressed store, hash-verified

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 }

Callers 3

getEventNameMethod · 0.95
hasEventMethod · 0.95
getEventMethod · 0.95

Calls 10

isHexStringFunction · 0.90
assertArgumentFunction · 0.90
splitMethod · 0.80
pushMethod · 0.80
valuesMethod · 0.45
isTypedMethod · 0.45
mapMethod · 0.45
formatMethod · 0.45
getMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected