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

Vec and heap type support #353

Closed
7 tasks done
adlerjohn opened this issue Jun 1, 2022 · 2 comments · Fixed by #597
Closed
7 tasks done

Vec and heap type support #353

adlerjohn opened this issue Jun 1, 2022 · 2 comments · Fixed by #597
Assignees
Labels
enhancement New feature or request P1 High priority

Comments

@adlerjohn
Copy link
Contributor

adlerjohn commented Jun 1, 2022

Description

Currently, the SDK only supports static-sized arrays in the format [T; n] where T is the type and n is the length.

Soon, Sway will release Vec, a growable/mutable/dynamic vector. We need to support this on the SDK side.

Blockers

Design

Vec is implemented in Sway with a struct like this:

struct RawVec<T> {
    ptr: u64,
    cap: u64,
}

pub struct Vec<T> {
    buf: RawVec<T>,
    len: u64,
}

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.

@digorithm
Copy link
Member

Reopening to use this as a tracker for the vec output support (#602).

@iqdecay
Copy link
Contributor

iqdecay commented Mar 22, 2023

Support for Vec was added in #848, support for bytes was added in #868.
Support for those types as script returns will be tracked in #866.

@iqdecay iqdecay closed this as completed Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants