Support trial and error of multiple event signatures

This commit is contained in:
Willian Mitsuda 2021-10-13 15:34:30 -03:00
parent 48747ab9c9
commit 23737ce4d0
3 changed files with 16 additions and 13 deletions

View File

@ -22,19 +22,21 @@ const LogEntry: React.FC<LogEntryProps> = ({ txData, log, logDesc }) => {
const topic0 = useTopic0(rawTopic0); const topic0 = useTopic0(rawTopic0);
const topic0LogDesc = useMemo(() => { const topic0LogDesc = useMemo(() => {
if (!topic0?.signature) { if (!topic0?.signatures) {
return undefined; return undefined;
} }
const sig = topic0.signature;
const logFragment = Fragment.fromString(`event ${sig}`); const sigs = topic0.signatures;
const intf = new Interface([logFragment]); for (const sig of sigs) {
try { const logFragment = Fragment.fromString(`event ${sig}`);
return intf.parseLog(log); const intf = new Interface([logFragment]);
} catch (err) { try {
// TODO: try other indexed/non-indexed combinations? return intf.parseLog(log);
console.error(err); } catch (err) {
return undefined; // Ignore on purpose; try to match other sigs
}
} }
return undefined;
}, [topic0, log]); }, [topic0, log]);
const resolvedLogDesc = logDesc ?? topic0LogDesc; const resolvedLogDesc = logDesc ?? topic0LogDesc;

View File

@ -3,7 +3,7 @@ import { RuntimeContext } from "./useRuntime";
import { topic0URL } from "./url"; import { topic0URL } from "./url";
export type Topic0Entry = { export type Topic0Entry = {
signature: string | undefined; signatures: string[] | undefined;
}; };
const fullCache = new Map<string, Topic0Entry | null>(); const fullCache = new Map<string, Topic0Entry | null>();
@ -46,8 +46,9 @@ export const useTopic0 = (
// Get only the first occurrence, for now ignore alternative param names // Get only the first occurrence, for now ignore alternative param names
const sig = await res.text(); const sig = await res.text();
const sigs = sig.split(";");
const entry: Topic0Entry = { const entry: Topic0Entry = {
signature: sig, signatures: sigs,
}; };
setEntry(entry); setEntry(entry);
fullCache.set(topic0, entry); fullCache.set(topic0, entry);

2
topic0

@ -1 +1 @@
Subproject commit 052043e6d51dd18cffb1a5a450262f47e5638684 Subproject commit b30f9d442081a231641c5cef196be79650306e55