Skip to content

Conversation

PhilippeR26
Copy link
Collaborator

@PhilippeR26 PhilippeR26 commented Sep 3, 2025

Motivation and Resolution

In the frame of the new parsing strategy, implementation of Cairo option & Cairo result type.

Usage related changes

No user change.

Development related changes

Current CairoOption, CairoResult & CairoCustomEnum classes remains unchanged, and is used by users.
New CairoTypeOption & CairoTypeResult class is created in conformity with the CairoType interface, and is used to encode/decode to Starknet API. Can be used by user, or is automatically created from a CairoOption.

       USER                             Starknet.js                   USER
    CairoOption    
 CairoTypeOption -->         CairoTypeOption --> encode/decode --> CairoOption
 
    CairoResult    
 CairoTypeResult -->         CairoTypeResult --> encode/decode --> CairoResult

 CairoCustomEnum
CairoTypeCustomEnum -->  CairoTypeCustomEnum --> encode/decode --> CairoCustomEnum

Added also CairoNonZero, CairoEth, CairoEthAddress, CairoBool classes, CairoStruct.
Also handling of ContractAddress & ClassHash (are in fact just felt252).

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@PhilippeR26
Copy link
Collaborator Author

Added a commit to solve problems of recursive decompose.

@PhilippeR26
Copy link
Collaborator Author

Added a commit to solve several problems of recursive encoding.
Remains to handle named tuples.

@PhilippeR26
Copy link
Collaborator Author

PhilippeR26 commented Sep 9, 2025

@tabaktoni
Now we have full recursive encoding and decoding for tuple, array, fixed array, option.
Cairo0 handling: felt, named tuple ( {a:10, b:20} ) and array (felt*).

  • felt has been added in strategy for Cairo 0 handling (is just using felt252 class).
  • tuple decoding is an object (named if is a Cairo 0 named tuple).
  • as named tuple do not exists in Cairo1, existing code of CairoTuple.extractTupleMemberTypes() has to be reconsidered.
  • Tests not yet updated.

@PhilippeR26 PhilippeR26 changed the title feat: add CairoTypeOption class feat: add CairoTypeOption CairoTypeResult classes Sep 15, 2025
@tabaktoni tabaktoni deleted the branch starknet-io:cairotypes/all September 24, 2025 10:16
@tabaktoni tabaktoni closed this Sep 24, 2025
@tabaktoni tabaktoni reopened this Sep 24, 2025
@PhilippeR26 PhilippeR26 changed the title feat: add CairoTypeOption CairoTypeResult classes feat: CairoTypeOption CairoTypeResult CairoTypeCustomEnum and others Oct 8, 2025
@PhilippeR26
Copy link
Collaborator Author

@tabaktoni
It's now working with all Cairo v2 I tested (and I tested a LOT of things).
I have no infra to test Cairo v0.6 & v1.
So, I think that job is done in CairoDataTypes folder.
I am now digging in calldata directory ; seems there are several possible optimizations using this new concept.

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