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

feat: add U256 support #1014

Merged
merged 7 commits into from
Jul 5, 2023
Merged

feat: add U256 support #1014

merged 7 commits into from
Jul 5, 2023

Conversation

hal3e
Copy link
Contributor

@hal3e hal3e commented Jun 26, 2023

closes: #1013

Adds support for sway's U256 type.

Checklist

  • I have linked to any relevant issues.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary labels.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@hal3e hal3e added the enhancement New feature or request label Jun 26, 2023
@hal3e hal3e self-assigned this Jun 26, 2023
Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

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

The JSON serialization of U256 seems a bit unexpected.

Take the following example:

        let num: U256 = U256::from(123);
        let serialized: String = serde_json::to_string(&num).unwrap();
        eprintln!("{num} serialized is: '{serialized}'");

        let num: u128 = 123;
        let serialized: String = serde_json::to_string(&num).unwrap();
        eprintln!("{num} serialized is: '{serialized}'");

Which prints out:

123 serialized is: '"0x7b"'
123 serialized is: '123'

The U256 is serialized as hex while u128 is a stringified decimal number. Might take somebody by surprise.

Although it is probably faster to do the hex dump, I'd sacrifice the speed and go with the least surprising approach.

packages/fuels-core/src/types/core/native.rs Outdated Show resolved Hide resolved
Copy link
Member

@Salka1988 Salka1988 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@iqdecay iqdecay left a comment

Choose a reason for hiding this comment

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

Perfect on the first try!

@hal3e hal3e merged commit f0c5789 into master Jul 5, 2023
32 checks passed
@hal3e hal3e deleted the feat/u256-support branch July 5, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add u256 support
4 participants