request: log topics
type could be narrowed
#163
-
Is there an existing issue for this?
Package Version0.1.6 Current BehaviorEvent logs returned by viem have a topics property typed like this: type TopicFilter = (null | string | string[])[]
type Log = {
/** List of order-dependent topics */
topics: TopicFilter
} Expected BehaviorWhile the type Topics = string[]
type Log = {
/** List of order-dependent topics */
topics: Topics
} It may be possible to narrow the type further like this: type Hex = `0x${string}`
type Topics = [Hex, Hex | undefined, Hex | undefined, Hex | undefined] but I'm not certain that the first topic must be defined (can an anonymous event have 0 indexed arguments?). Steps To ReproduceNo response Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)No response Anything else?No response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yellow Paper section 4.3.1: A log entry, $$O \equiv (O_{\mathrm{a}}, ({O_{\mathbf{t}}}0, {O{\mathbf{t}}}1, ...), O{\mathbf{d}})$$ Topics can be empty. For example: this transaction contains logs with empty topics. |
Beta Was this translation helpful? Give feedback.
-
Thanks! So, the best type is probably: type Topics = Hex[]; Although it is guaranteed that the length of the array will be <= 4, and that could be represented as a union of tuples: type Topics = [] | [Hex] | [Hex, Hex] | [Hex, Hex, Hex] | [Hex, Hex, Hex, Hex]; In any case, the current type of |
Beta Was this translation helpful? Give feedback.
Yellow Paper section 4.3.1:
A log entry,$O$ , is a tuple of the logger's address, $O_a$ , a possibly empty series of 32-byte log topics, $O_{\mathbf{t}}$ and some number of bytes of data, $O_{\mathbf{d}}$ :
$$O \equiv (O_{\mathrm{a}}, ({O_{\mathbf{t}}}0, {O{\mathbf{t}}}1, ...), O{\mathbf{d}})$$
Topics can be empty. For example: this transaction contains logs with empty topics.