Support trial and error of multiple event signatures
This commit is contained in:
parent
48747ab9c9
commit
23737ce4d0
|
@ -22,19 +22,21 @@ const LogEntry: React.FC<LogEntryProps> = ({ txData, log, logDesc }) => {
|
|||
const topic0 = useTopic0(rawTopic0);
|
||||
|
||||
const topic0LogDesc = useMemo(() => {
|
||||
if (!topic0?.signature) {
|
||||
if (!topic0?.signatures) {
|
||||
return undefined;
|
||||
}
|
||||
const sig = topic0.signature;
|
||||
const logFragment = Fragment.fromString(`event ${sig}`);
|
||||
const intf = new Interface([logFragment]);
|
||||
try {
|
||||
return intf.parseLog(log);
|
||||
} catch (err) {
|
||||
// TODO: try other indexed/non-indexed combinations?
|
||||
console.error(err);
|
||||
return undefined;
|
||||
|
||||
const sigs = topic0.signatures;
|
||||
for (const sig of sigs) {
|
||||
const logFragment = Fragment.fromString(`event ${sig}`);
|
||||
const intf = new Interface([logFragment]);
|
||||
try {
|
||||
return intf.parseLog(log);
|
||||
} catch (err) {
|
||||
// Ignore on purpose; try to match other sigs
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}, [topic0, log]);
|
||||
|
||||
const resolvedLogDesc = logDesc ?? topic0LogDesc;
|
||||
|
|
|
@ -3,7 +3,7 @@ import { RuntimeContext } from "./useRuntime";
|
|||
import { topic0URL } from "./url";
|
||||
|
||||
export type Topic0Entry = {
|
||||
signature: string | undefined;
|
||||
signatures: string[] | undefined;
|
||||
};
|
||||
|
||||
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
|
||||
const sig = await res.text();
|
||||
const sigs = sig.split(";");
|
||||
const entry: Topic0Entry = {
|
||||
signature: sig,
|
||||
signatures: sigs,
|
||||
};
|
||||
setEntry(entry);
|
||||
fullCache.set(topic0, entry);
|
||||
|
|
2
topic0
2
topic0
|
@ -1 +1 @@
|
|||
Subproject commit 052043e6d51dd18cffb1a5a450262f47e5638684
|
||||
Subproject commit b30f9d442081a231641c5cef196be79650306e55
|
Loading…
Reference in New Issue