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

eth/abi: allow parsing numerics from string inputs #112

Merged
merged 2 commits into from
Jun 10, 2022
Merged

Conversation

q9f
Copy link
Owner

@q9f q9f commented Jun 10, 2022

fix #110

@q9f q9f added the bug Something isn't working label Jun 10, 2022
@q9f q9f merged commit bb640c7 into main Jun 10, 2022
@q9f q9f deleted the q9f/abi/string branch June 10, 2022 08:19
@pynixwang
Copy link

hex number not work

"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i
=> 21

1 similar comment
@pynixwang
Copy link

hex number not work

"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i
=> 21

@q9f
Copy link
Owner Author

q9f commented Jun 13, 2022

Makes sense 😮‍💨

@q9f
Copy link
Owner Author

q9f commented Jun 13, 2022

hex number not work

"00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i
=> 21

You need to preprocess the JSON in this case. There is no way to know if a string is binary, octal, decimal, or hexadecimal.

@pynixwang
Copy link

decimal is enough.

I found you have hex string in test, so I have a try. do you run you test?

@unixneo
Copy link

unixneo commented Jun 20, 2022

I found you have hex string in test, so I have a try. do you run you test?

test = "00000000000000000000000000000000000000000000021e19e0c9bab2400000".hex
=> 10000000000000000000000
test.to_s(16)
=> "21e19e0c9bab2400000"

@kurotaky
Copy link
Collaborator

For hexadecimal numbers, the argument to_i() must be 16.

irb(main):005:0> "00000000000000000000000000000000000000000000021e19e0c9bab2400000".to_i(16)
=> 10000000000000000000000

However, it is difficult to distinguish octal, decimal, or hexadecimal in the following pattern... 😢

irb(main):016:0> '000255'.to_i(8)
=> 173
irb(main):017:0> '000255'.to_i(10)
=> 255
irb(main):018:0> '000255'.to_i(16)
=> 597

@pynixwang
Copy link

decimal string is enough for most cases.

q9f added a commit that referenced this pull request Jun 27, 2022
* Revert "eth/abi: allow parsing numerics from string inputs (#112)"

This reverts commit bb640c7.

* eth/abi: raise error if numeric comes as string
mculp pushed a commit to mculp/eth.rb that referenced this pull request Aug 1, 2022
* eth/abi: allow parsing numerics from string inputs

* sepc: run rufo
mculp pushed a commit to mculp/eth.rb that referenced this pull request Aug 1, 2022
* Revert "eth/abi: allow parsing numerics from string inputs (q9f#112)"

This reverts commit bb640c7.

* eth/abi: raise error if numeric comes as string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

comparison of String with Integer failed
4 participants