You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once a Sway user imports it into their contract, Vec<T> and RawVec<T> will be exposed in the JSON ABI as regular structs. This will be abigen!'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 length len, the pointer ptr, and the capacity cap. But where is the ptr pointing to? It will point to where the data lives inside the script_data, where we'll have to encode the actual content of the Vec<T>. This should suffice and, in Sway-land, a user should be able to access the contents of the Vec<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 the Vec's ptr.
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 the Receipts.
The text was updated successfully, but these errors were encountered:
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: