Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Decoder stores numbers oddly. #261

Closed
MicahZoltu opened this issue Aug 21, 2018 · 5 comments
Closed

Event Decoder stores numbers oddly. #261

MicahZoltu opened this issue Aug 21, 2018 · 5 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@MicahZoltu
Copy link

When decoding an event like Foo(uint256 a), I end up with an object like:

{ /*...*/, values: { a: { _hex: '0x5' } } }

I would have expected a BigNumber here, or barring that a hex encoded string. _ prefixed property names are usually internal, so I am hesitant to write code that relies or reading that. Also, non-number values are stored without the inner-most object, so just { b: '0xabcd1234' }, which makes number values odd.

After a significant amount of digging I found the issue is in the way it "freezes" the values key. It does JSON.stringify then JSON.parse on it, which results in stripping the prototype from all of the methods and leaving only the _hex internal variable of the original BigNumber object.

@ricmoo
Copy link
Member

ricmoo commented Aug 21, 2018

That is certainly a bug. Can you provide a quick snippet? Are you on the v4 branch? I recall adding a fix for that, but I must have missed some place.

@ricmoo ricmoo self-assigned this Aug 21, 2018
@ricmoo ricmoo added the bug Verified to be an issue. label Aug 21, 2018
@ricmoo
Copy link
Member

ricmoo commented Aug 21, 2018

Oh! Looking at the code and your example, I understand the bug. I’ll get a fix out soon. Thanks!

@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. v4.0 labels Aug 21, 2018
@MicahZoltu
Copy link
Author

I'm experiencing this on the 4.0.0-beta.12, and the linked code is in typescript branch.

@ricmoo
Copy link
Member

ricmoo commented Aug 21, 2018

Yeah. I'm going to make a proper copyDeep that supports an immutability flag and replace defineFrozen with defineReadOnly(copyDeep(o)). I'll also see about getting rid of jsonCopy and using the new copyDeep.

The problem is with nested structures, like a tuple or array which contains BigNumbers. I felt the cold chill the second I read the _hex in your issue, and realized the error of my ways once I looked at the code... :)

Thanks!

@ricmoo
Copy link
Member

ricmoo commented Aug 27, 2018

This should be fixed in 4.0.0-beta.13.

Closing for now, but if you continue experiencing any issues, please feel free to re-open. :)

@ricmoo ricmoo closed this as completed Aug 27, 2018
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Aug 27, 2018
@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants