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

Allow converting between nil big.Int and nil uint256.Int #137

Merged
merged 5 commits into from
Mar 31, 2023

Conversation

karalabe
Copy link
Contributor

This is perhaps a debatable change, but may be more logical than originally anticipated.

In some places, having a nil as a big.Int or uint256.Int might make sense (e.g. an optional and non-initialized field). In those cases, converting between the two across older/newer code might be necessary. In it's current incarnation, the uint256 library will crash, so all optional nils need to be special cased.

IMHO this should not be necessary. If a uint256 should not be nil, but a nil big int is passed, then I assume the code later will crash anyway on some uint256 accessor method whether we crash at the conversion or not, so it's not like we're silently swallowing up errors. On the other hand, allowing the nils to be converted back and forth reduces the error potential of forgetting to special case an optional nil somewhere and blowing up runtime.

Copy link
Owner

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

conversion_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #137 (9053f6a) into master (71f8c05) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 9053f6a differs from pull request most recent head 6ca7b7d. Consider uploading reports for the commit 6ca7b7d to get more accurate results

@@            Coverage Diff            @@
##            master      #137   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines         1615      1621    +6     
=========================================
+ Hits          1615      1621    +6     

conversion.go Show resolved Hide resolved
conversion.go Show resolved Hide resolved
conversion.go Show resolved Hide resolved
@holiman holiman merged commit c46f3b8 into holiman:master Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants