-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Allow strings and bigints instead of numbers in decoder input fields #6131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small docs thing
packages/decoder/lib/types.ts
Outdated
/** | ||
* Index of the log within the block. | ||
*/ | ||
logIndex?: number; | ||
/** | ||
* Index within the block of the emitting transaction; null if | ||
* block is pending. | ||
*/ | ||
transactionIndex?: number | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these optional fields need explanation on why they might be undefined
. Probably warrants a note in the DecodedLog
docstring, to say that @truffle/decoder re-emits everything given, and unspecified optional input fields will thus not appear in output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that's not how this works! Which raises a good point: These fields shouldn't be optional. I guess I should just not make this an extension of Log
, huh? Because it doesn't save me any work if everything is mandatory. :-/
To explain: If you use decodeLog
, passing in your own logs, you just get back the decodings, you don't get DecodedLog
. You only get DecodedLog
if you call events()
, to which one does not pass in their own logs. So actually these fields will always be present in this type.
...so do you agree that's what I should do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this emit the same info in both situations? It's weird that passing in a Log
will remove fields, while events()
will return everything log-related
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? Passing in a Log
doesn't remove fields. What I'm saying is that decodeLog
doesn't use the DecodedLog
type at all. It returns the decodings, they're not inside a DecodedLog
container. Only events
uses that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, sorry to misunderstand. Yeah, let's not extend Log
PR description
Addresses #6080. This makes it so that fields in
Log
orTransaction
that previously werenumber
are nownumber | string | bigint
, and fields that werenumber | null
are nownumber | string | bigint | null
.Most of these fields are ignored, so the type is changed and that's all.
The one changed field that's actually used is
blockNumber
, so I just changed things so that if we get that and it's not null, we convert it to a number.I do have to also discuss what happened to the
DecodedLog
type. For simplicity,DecodedLog
extendsLog
. However,Log
has just had its type broadened. But while that's fine forLog
, because it's an input type,DecodedLog
is an output type. So to broaden its type would be a breaking change. So I re-narrowed the types of the appropriate fields to prevent that.Anyway that's it (aside from tests); this is pretty simple.
Testing instructions
I altered some decoder tests so that they pass in strings for the block number (the only part that matters), I think that should be sufficient.