-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ask! Tuple & Enum Support (Experimental) #260
base: main
Are you sure you want to change the base?
Conversation
@yjhmelody & ask! team, please have a look at this PR and let me know your thoughts. I've marked the PR as draft because I've not added a transform for enums because I want to make sure you guys are comfortable with the design first. |
Ok, I will take a look at this. It seems a good idea to decorator a class to be tuple or someelse other. |
The import of But I want to update deps firstly before all concrete works. I will open a issue to schedule some works. Thank you for your good idea. |
@ashutoshvarma Hi, I would like to implement tuple and enum in |
That would be great! For Enums, I've added manual implementations for
|
Yeah, since scale-codec is a binary format without caring about field name, it should work well. The specific designs may be considered in implementation. |
BTW, |
@yjhmelody friendly ping, how's the work on serde side going? |
It's being done slowly... |
Cool! Let me know if I can be of any help to accelerate this. |
Changes
ask-transform
's Metadata vistitor.debugMessage()
in env for debugging (e0e2260)Ask! Tuple & Enum Support (Experimental)
AssemblyScript does not supports tuples and tagged-union types (Rust-like enums) and so does ask!.
The
Option<T>
andResult<T, E>
are used extensively inside PSPs along with other enum types.Therefore having their support in ask! is really important before ask! can be used to onboard new
developers from non Rust background.
Notes :-
Mapping<K,V,H>
whereV
has no default constructor. #245 (comment)Tuples
Tuples in ask! are objects anointed with
@tuple()
decorator. All it does is instruct the metadata generatorto output a Tuple type instead of a Composite one.
Below type is equivalent to Rust's
(u64, bool)
.Generic implementations for tuples are provided in 'tuples.ts' and recommended over creating a new tuple type.
Compatibility
@serialize()
- works fine@deserialize()
- works fine@packedLayout()
- works fine@spreadLayout()
- works fineEnums
Rust like enums (or tagged union types) can be defined using the combination of
@enumeration()
and@variant()
decorators.Other Examples :-
Option<T>
(adapted fromas-containers
)Result<T>
(adapted fromas-containers
)Id
(from PSP34 Spec)PSP34Error
(from PSP34 Spec)Please go though this PSP34 implementation in ask! for understanding more about enum support - https://github.com/ashutoshvarma/psp34-contract/tree/feat/enum/packages/psp34/assembly/psp34
Compatibility
Does not support
SpreadLayout
because ask! does not have something similar to ink! v0.3'sFOOTPRINT
. I've experimented with adding that to ask!, you can find it here - ashutoshvarma@8671900.If using inside a spread layout type, use it with
Pack<T>
.@serialize()
- needs manual implementation@deserialize()
- needs manual implementation@packedLayout()
- needs manual implementation@spreadLayout()
- does not support spread layout at allTODO
serialize()
&packedLayout()
decorators for Enum