-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Vec
and heap type support
#353
Labels
Comments
This was referenced Jun 16, 2022
This was referenced Jul 21, 2022
This was referenced Aug 2, 2022
2 tasks
2 tasks
Reopening to use this as a tracker for the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Currently, the SDK only supports static-sized arrays in the format
[T; n]
whereT
is the type andn
is the length.Soon, Sway will release
Vec
, a growable/mutable/dynamic vector. We need to support this on the SDK side.Blockers
Vec
sway#1118: FullVec
support in Sway.retd()
method (or similar) that returns the content of a vector to be returned from a contract method sway#1994: An output-related work that needs to be done in the compiler, i.e., converting the heap data into stack data and returning it in aretd
T
inVec<T>
needs to be resolved and present in the ABI)Vec
when returning from a script sway#2900raw_ptr
inabigen!
#600Design
Vec
is implemented in Sway with a struct like this:Once a Sway user imports it into their contract,
Vec<T>
andRawVec<T>
will be exposed in the JSON ABI as regular structs. This will beabigen!
'd on the SDK side, turning these two Sway structs into equivalent Rust structs.Passing data in and out using
Vec
will be the most challenging part.Passing in a
Vec<T>
to a contract call in Rust-land means we have to encode the lengthlen
, the pointerptr
, and the capacitycap
. But where is theptr
pointing to? It will point to where the data lives inside thescript_data
, where we'll have to encode the actual content of theVec<T>
. This should suffice and, in Sway-land, a user should be able to access the contents of theVec<T>
param in their contract method.Taking the returned data, in Rust-land, from a contract call that returns a
Vec<T>
means this, which should be simpler than the encoding part.Once the SDK is unblocked by the compiler, the SDK needs to encode the vector data into
script_data
and point to it using theVec
'sptr
.Update August 16th, 2022
We've decided to support only
Vec
as inputs for now. Once that's done,Vec
as output will be effectively a log of its data in theReceipt
s.The text was updated successfully, but these errors were encountered: