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!: improve () and Option<T> type handling #2777

Merged
merged 54 commits into from
Jul 30, 2024

Conversation

petertonysmith94
Copy link
Contributor

@petertonysmith94 petertonysmith94 commented Jul 16, 2024

Release notes

In this release, we:

  • Improved the type handling for () and Option<T> types

Summary

  • Our types for functions are now like for like against their Sway counterparts.
  • Made the Option<T> property optional.
  • Added the VoidCoder, enabling encoding and decoding void types.

Breaking Changes

  • () and Option<T> Sway types are now either required or optional, dependent on where the argument appears in the function arguments.

    Given these Sway functions:

    fn type_then_void_then_type(x: u8, y: (), z: u8) -> ()
    fn type_then_void_then_void(x: u8, y: (), z: ()) -> ()
    
    fn type_then_option_then_type(x: u8, y: Option<u8>, z: u8) -> ()
    fn type_then_option_then_option(x: u8, y: Option<u8>, z: Option<u8>) -> ()

    This is what changes:

    // before
    contract.functions.type_then_void_then_type(42, 43)
    contract.functions.type_then_void_then_void(42) // Unchanged
    
    contract.functions.type_then_option_then_type(42, undefined, 43)
    contract.functions.type_then_option_then_option(42, undefined, undefined)
    // after
    contract.functions.type_then_void_then_type(42, undefined, 43)
    contract.functions.type_then_void_then_void(42) // Unchanged 
    
    contract.functions.type_then_option_then_type(42, undefined, 43)
    contract.functions.type_then_option_then_option(42)

Checklist

  • I addedtests to prove my changes
  • I updated — all the necessary docs
  • I reviewed — the entire PR myself, using the GitHub UI
  • I described — all breaking changes and the Migration Guide

@petertonysmith94 petertonysmith94 added the feat Issue is a feature label Jul 16, 2024
@petertonysmith94 petertonysmith94 added this to the 0.x post-launch milestone Jul 16, 2024
@petertonysmith94 petertonysmith94 self-assigned this Jul 16, 2024
@petertonysmith94 petertonysmith94 changed the title Ps/feat/void coder feat: implement VoidCoder Jul 16, 2024
Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-ts ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2024 2:39pm

Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

// before
contract.functions.type_then_void_then_type(42, 43)
contract.functions.type_then_option(42, undefined)
// after
contract.functions.type_then_void_then_type(42, undefined, 43)
contract.functions.type_then_option(42)

Context question, how come we are treating these two things differently? I'd expect to pass () and Option::None in the same way?

@petertonysmith94
Copy link
Contributor Author

// before
contract.functions.type_then_void_then_type(42, 43)
contract.functions.type_then_option(42, undefined)
// after
contract.functions.type_then_void_then_type(42, undefined, 43)
contract.functions.type_then_option(42)

Context question, how come we are treating these two things differently? I'd expect to pass () and Option::None in the same way?

They are treated the same - maybe the example that I provided is confusing - I've updated the example, please let me know if that clears it up.

Torres-ssf
Torres-ssf previously approved these changes Jul 30, 2024
@danielbate
Copy link
Contributor

@petertonysmith94 thankyou for clearing it up. Makes sense, we are treating them the same, it is actually dependent on their position in the function arguments that had thrown me off.

@petertonysmith94
Copy link
Contributor Author

petertonysmith94 commented Jul 30, 2024

@petertonysmith94 thankyou for clearing it up. Makes sense, we are treating them the same, it is actually dependent on their position in the function arguments that had thrown me off.

Correct - do you think the breaking change description needs work?

maschad
maschad previously approved these changes Jul 30, 2024
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

Awesome!

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
79.49%(+0.14%) 71.79%(+0.29%) 77.46%(+0.14%) 79.63%(+0.15%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/abi-coder/src/FunctionFragment.ts 62.16%
(+10.24%)
37.5%
(+2.5%)
66.66%
(+9.52%)
61.53%
(+11.53%)
✨ packages/abi-coder/src/encoding/coders/VoidCoder.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 packages/abi-coder/src/encoding/strategies/getCoderV1.ts 91.66%
(+0.18%)
87.09%
(+0.43%)
100%
(+0%)
91.83%
(+0.17%)
🔴 packages/abi-coder/src/utils/constants.ts 97.5%
(+0.14%)
100%
(+0%)
0%
(+0%)
97.5%
(+0.14%)
✨ packages/abi-coder/src/utils/getFunctionInputs.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/utils/padValuesWithUndefined.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-typegen/src/utils/getFunctionInputs.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-typegen/src/utils/getTypeDeclaration.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)

@danielbate
Copy link
Contributor

() and Option Sway types are now either required or optional, depending on the circumstances.

() and Option<T> Sway types are now either required or optional, dependent on where the argument appears in the function arguments.

@petertonysmith94 change for breaking changes maybe?

Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

Clean 🧹

@petertonysmith94 petertonysmith94 merged commit 9c07b00 into master Jul 30, 2024
25 checks passed
@petertonysmith94 petertonysmith94 deleted the ps/feat/void-coder branch July 30, 2024 15:44
@petertonysmith94 petertonysmith94 mentioned this pull request Jul 30, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Option<x> optional with typegen Implement VoidCoder Improve empty type for ABI Coder and Typegen
6 participants